未验证 提交 05fb2b21 编写于 作者: O openharmony_ci 提交者: Gitee

!12330 Translation finished: 11280 提交《OpenHarmony API设计规范》

Merge pull request !12330 from wusongqing/TR11280
......@@ -2,7 +2,7 @@
## Background
* API type: [Public API | Test API | HDI]
* API type: [Public API | System API | Test API | HDI]
* API requirement source:
* API usage scenario:
* Belonging subsystem:
......
......@@ -2,9 +2,9 @@
## Introduction
To help the OpenHarmony ecosystem develop and evolve in a healthy and orderly way, this Charter defines the governance process and lifecycle (creation, change, deprecation, and deletion) of OpenHarmony APIs. It also specifies basic design requirements of OpenHarmony APIs.
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.
This Charter is formulated by the [API SIG](https://www.openharmony.cn/SIG/api/) and approved by the [PMC](https://www.openharmony.cn/community/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
......@@ -12,23 +12,23 @@ This Charter is formulated by the API SIG and approved by the PMC for release. A
The OpenHarmony software stack contains multiple roles. Naturally, OpenHarmony APIs have multiple types.
<img src="figures/API-Category.png" width="800" />
![](figures/API-Category.png)
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 | Five API versions | X test suite (XTS) |
| Test API | Test framework | All application developers | Three API versions | To be built |
| System API | System and framework |System application developers |Not guaranteed | To be built |
| HDI | HDF | System services | Four API versions | XTS |
| Driver API | HDF | Driver developers | Not guaranteed | None |
| Inner API | System parts | System parts | Not guaranteed | None |
| 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| X test suite (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.
* Test API: APIs used for testing. They can be used only in the test phase.
* 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.
......@@ -41,6 +41,7 @@ OpenHarmony aims to build a next-generation Operating System (OS) for the Intern
* C/C++
* JavaScript
* TypeScript
* ArkTS
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.
......@@ -48,25 +49,25 @@ The content described in this Charter is irrelevant to the programming language
### 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. <br/>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. |
|**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.<br>Provide pre-review comments 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:
<img src="figures/API-Workflow.png" width="800" />
![](figures/API-Workflow.png)
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 (API SIG). The code of changed APIs can be merged only after being reviewed and approved by the API SIG.
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
......@@ -87,75 +88,11 @@ For changed APIs, except the preceding operations, you must:
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:
## API Lifecycle and Compatibility Requirements
OpenHarmony APIs will evolve in the form of API versions. Each version goes through the release period shown in the following figure,
which also demonstrates the compatibility requirements for the APIs in different periods.
![](figures/API-Lifecycle.png)
......@@ -163,7 +100,7 @@ Design APIs from the perspective of their users rather than providers.
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. Canary 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.
......@@ -173,33 +110,6 @@ Design APIs from the perspective of their users rather than providers.
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. Make sure that the impact of API call timing and frequency on the RAM usage is under control.
3. Make sure that the impact of API call timing and frequency on the power consumption is under control.
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 optimize the design if there is any impact.
2. Make sure that the power consumption does not deteriorate during version evolution.
### Reliability
1. APIs shall not 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 **sequenceNo** 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
### API Design Specifications
Regardless of the programming language in use, APIs must comply with the OpenHarmony programming language specifications.
For details, see [OpenHarmony API Design Specifications](OpenHarmony-API-quality.md).
此差异已折叠。
......@@ -4,20 +4,35 @@
- ### Ability
An abstraction of a functionality that an application can provide. An ability is the minimum unit for the system to schedule applications. An application can contain one or more **Ability** instances.
The abstraction of a functionality provided by an application. **Ability** is the minimum unit for the system to schedule an application. It is a component that can implement an independent functionality. An application can contain one or more **Ability** instances. Different types of abilities are defined in the Feature Ability (FA) model and stage model.
- ### AMS
Ability Manager Service, a service that manages abilities.
- ### App pack
An application package released to the application market. The package contains one or more HAP files with the file name extension .app.
- ### App component
Same as ability. Each ability is an app component.
- ### ArkCompiler
A component-based and configurable multi-language compilation and running platform built in OpenHarmony. Bolstered by key components such as the compiler, toolchain, and runtime, ArkCompiler is able to compile and run code written in various advanced programming languages on multiple chip platforms. It also enables the OpenHarmony standard system and its applications and services to run on a variety of device types, from phones and PCs, tablets, TVs, automobiles, to smart wearables.
A component-based, configurable multi-language compilation and running platform built in OpenHarmony. Bolstered by key components such as the compiler, toolchain, and runtime, ArkCompiler is able to compile and run code written in various advanced programming languages on multiple chip platforms. It also enables the OpenHarmony standard system and its applications and services to run on a variety of device types, from phones and PCs, tablets, TVs, automobiles, to smart wearables.
- ### ArkTS
Application development language used in OpenHarmony. Based on TypeScript, ArkTS extends capabilities such as declarative UI and status management, helping you develop applications in a simpler and more natural way.
- ### ArkUI
A simplified and high-performance UI development framework for cross-device application design and development, increasing your productivity when creating application UIs for use across devices. For details, see [ArkUI Overview](application-dev/ui/arkui-overview.md).
Native UI framework of OpenHarmony. ArkUI is a simplified, high-performance UI development framework for cross-device application design and development, increasing your productivity when creating application UIs for use across devices. For details, see [ArkUI Overview](application-dev/ui/arkui-overview.md).
- ### Atomic service
A brand-new application form provided by OpenHarmony. Each atomic service has an independent entry for users to easily access, such as by tapping it, using OneHop, or scanning a particular QR code. They support silent installation (installed automatically by the system in the background).
## B
......@@ -26,17 +41,29 @@
Bundle Manager Service, a service that manages application bundles.
## C
- ### C API
Native development interface provided by the OpenHarmony SDK.
- ### Continuation
Distributed operations provided by OpenHarmony, including cross-device migration and multi-device collaboration.
## D
- ### Derivative framework
A third-party framework bridged to the native framework.
- ### DevEco Device Tool
A one-stop development environment and all-in-one resource platform for smart device developers. It provides comprehensive capabilities spanning the entire process of device development, from chip template project creation and custom development resource selection to code writing, build, debugging, and burning.
- ### DMS
Distributed Management Service, a service used for distributed data management.
Distributed Management Service, a service used for distributed management.
## F
......@@ -46,8 +73,7 @@
- ### FA model
Feature Ability model, one of the development models supported by the ability development framework. It is the only application development model supported by API version 8 and earlier. The FA model provides [FAs](#fa) and [Particle abilities (PAs)](#pa). The FA supports the Page ability template, and the PA supports the Service, Data, and Form ability templates. For details, see [FA Model Overview](application-dev/ability/fa-brief.md).
A development model provided by the ability framework. It is the only application development model supported by API version 8 and earlier. The FA model provides [FAs](#fa) and [Particle abilities (PAs)](#pa). The FA supports the Page ability template, and the PA supports the Service, Data, and Form ability templates. For details, see [FA Model Overview](application-dev/ability/fa-brief.md).
## H
......@@ -55,9 +81,13 @@
OpenHarmony Ability Package, released with the file name extension .hap. One HAP provides all content of an application, including code, resources, third-party libraries, and an application configuration file.
- ### HAR
OpenHarmony Archive file, which contains the middle format of code, resources, and configuration files.
- ### HCS
HDF Configuration Source (HCS), providing the [Hardware Driver Foundation (HDF)](#hdf) configuration in key-value pairs. HCS removes the dependency between configuration code and driver code, simplifies configuration management.
HDF Configuration Source, providing the Hardware Driver Foundation (HDF) configuration in key-value pairs. HCS removes the dependency between configuration code and driver code, simplifying configuration management.
- ### HC-GEN
......@@ -67,7 +97,7 @@
- ### HDF
Hardware Driver Foundation that provides a unified access interface for peripherals and the framework for driver development and management in OpenHarmony.
Hardware Driver Foundation, which provides a unified access interface for peripherals and the framework for driver development and management in OpenHarmony.
- ### Hypium
......@@ -80,6 +110,12 @@
Intelligent Distributed Networking, a distributed networking unit of OpenHarmony. You can use IDN to obtain the device list and device states and subscribe to the connection state changes of devices on a distributed network.
## N
- ### Native framework
A development framework provided by the system. A non-native framework is a third-party framework.
## P
......@@ -87,18 +123,41 @@
Particle Ability, an ability that does not have a UI in the ability framework of the FA model. It provides services and support for FAs. For example, a PA can function as a background service to provide computing power or as a data store to provide data access capabilities. The PA supports Service, Data, and Form ability templates.
## S
- ### SA
System Ability, which is a system-level component written by system developers.
- ### Secondary framework
A third-party framework that does not depend on the native framework.
- ### Stage model
A development model provided by the ability framework since API version 9. The stage model provides **UIAbility** and **ExtensionAbility** classes. The **ExtensionAbility** classes include **ServiceExtensionAbility**, **FormExtensionAbility**, **DataShareExtensionAbility**, and more.
- ### Super Virtual Device
Also called Super Device. It integrates the capabilities of multiple devices through the distributed technology into a virtual hardware resource pool and then centrally manages and schedules these capabilities based on application requirements.
- ### Stage model
- ### SysCap
A development model supported by the Ability development framework since API version 9. The stage model provides **Ability** and **ExtensionAbility** classes. The **ExtensionAbility** classes include **ServiceExtensionAbility**, **FormExtensionAbility**, **DataShareExtensionAbility**, and more.
System Capability, each relatively independent feature in OpenHarmony, such as Bluetooth, Wi-Fi, NFC, and camera. Each system capability corresponds to multiple APIs, and each API definition contains the corresponding SysCap tag.
- ### System type
- Mini system: an operating system for the devices that come with MCU processors, such as Arm Cortex-M and 32-bit RISC-V, and memory greater than or equal to 128 KiB. This system provides rich short-distance connection capabilities and peripheral access bus. The mini system applies to smart home products such as LinkIoT module devices and sensors.
- Small system: an operating system for the devices that come with application processors, such as Arm Cortex-A, and memory greater than or equal to 1 MiB. This system provides higher security capabilities, a standard graphics framework, and video encoding and decoding capabilities. The small system applies to smart home products such as IP cameras, peephole cameras, and routers as well as smart travel products such as event data recorders (EDRs).
- Standard system: an operating system for the devices that come with application processors, such as Arm Cortex-A, and memory greater than or equal to 128 MiB. This system provides a complete application framework supporting enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. The standard system applies to high-end refrigerator displays.
- Mini system: an operating system for the devices that come with MCU processors, such as Arm Cortex-M and 32-bit RISC-V, and memory greater than or equal to 128 KiB. This system provides rich short-range connection capabilities and peripheral access bus. The mini system applies to smart home products such as LinkIoT module devices and sensors.
- Small system: an operating system for the devices that come with application processors such as Arm Cortex-A and memory greater than or equal to 1 MiB. This system provides higher security capabilities, a standard graphics framework, and video encoding and decoding capabilities. The small system applies to smart home products such as IP cameras, peephole cameras, and routers as well as easy travel products such as event data recorders (EDRs).
- Standard system: an operating system for the devices that come with application processors such as Arm Cortex-A and memory greater than or equal to 128 MiB. This system provides a complete application framework supporting enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. The standard system applies to high-end refrigerator displays.
## U
- ### UI component
Part of the UI that supports user interaction.
## X
- ### XComponent
Component interfaces provided by ArkUI to meet self-rendering requirements of developers.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册