subsys-application-framework-overview.md 10.8 KB
Newer Older
W
wusongqing 已提交
1
# Application Framework Overview<a name="EN-US_TOPIC_0000001062225512"></a>
N
NEEN 已提交
2

M
mamingshuai 已提交
3
The application framework is provided by OpenHarmony for you to develop OpenHarmony applications. It consists of two modules: ability management framework \(also called the ability framework\) and bundle management framework.
N
NEEN 已提交
4

M
mamingshuai 已提交
5
## Basic Concepts<a name="section72601941194812"></a>
N
NEEN 已提交
6

M
mamingshuai 已提交
7
This section describes some basic concepts for you to better understand the OpenHarmony application framework before you start development.
N
NEEN 已提交
8

M
mamingshuai 已提交
9
## Ability Management Framework<a name="section14633111813374"></a>
N
NEEN 已提交
10

M
mamingshuai 已提交
11
The ability management framework manages running status of OpenHarmony applications.
N
NEEN 已提交
12

M
mamingshuai 已提交
13
**Figure  1**  Architecture of the ability management framework<a name="fig9759195514371"></a>  
14
![](figures/architecture-of-the-ability-management-framework.png "architecture-of-the-ability-management-framework")
N
NEEN 已提交
15

M
mamingshuai 已提交
16 17
-   **Ability**  is the minimum unit for the system to schedule applications. It is a component that can implement an independent functionality. An application can contain one or more  **Ability**  instances. There are two types of templates that you can use to create an  **Ability**  instance: Page and Service.
    -   An  **Ability using the Page template**  \(Page ability for short\) provides a UI for interacting with users.
N
NEEN 已提交
18

M
mamingshuai 已提交
19
    -   An  **Ability using the Service template**  does not have a UI and is used for running background tasks.
N
NEEN 已提交
20 21 22



M
mamingshuai 已提交
23
-   An  **AbilitySlice**  represents a single screen and its control logic. It is specific to Page abilities. A Page ability may contain one ability slice or multiple ability slices that provide highly relevant capabilities.
N
NEEN 已提交
24

M
mamingshuai 已提交
25
    **Figure  2**  Relationship between a Page ability and its ability slices<a name="fig1065819910347"></a>  
26
    ![](figures/relationship-between-a-page-ability-and-its-ability-slices.png "relationship-between-a-page-ability-and-its-ability-slices")
N
NEEN 已提交
27

M
mamingshuai 已提交
28
-   **Lifecycle**  is a general term for all states of an ability, including  **INITIAL**,  **INACTIVE**,  **ACTIVE**, and  **BACKGROUND**.
N
NEEN 已提交
29

M
mamingshuai 已提交
30 31
    **Figure  3**  Lifecycle state transition of a Page ability<a name="fig56111543375"></a>  
    
N
NEEN 已提交
32

33
    ![](figures/fig1.png)
N
NEEN 已提交
34

M
mamingshuai 已提交
35
    -   **OnStart\(\)**
N
NEEN 已提交
36

M
mamingshuai 已提交
37
        This callback is invoked when the system first creates the Page ability. After this callback is executed, the Page ability enters the  **INACTIVE**  state. This callback is triggered only once in the entire lifecycle of each Page ability. You must override this callback and set the default ability slice to be displayed.
N
NEEN 已提交
38

M
mamingshuai 已提交
39
    -   **OnActive\(\)**
N
NEEN 已提交
40

M
mamingshuai 已提交
41
        This callback is invoked when the Page ability in the  **INACTIVE**  state enters the foreground. After this callback is executed, the Page ability enters the  **ACTIVE**  state, in which it becomes interactive. The Page ability will stay in this state unless it loses focus upon a certain event, for example, when the user touches the Back button or navigates to another Page ability.
N
NEEN 已提交
42

M
mamingshuai 已提交
43
        When such an event occurs, the Page ability returns to the  **INACTIVE**  state, and the system invokes the  **OnInactive\(\)**  callback. The Page ability may move to the  **ACTIVE**  state again, and the system will then invoke the  **OnActive\(\)**  callback again. You should implement both  **OnActive\(\)**  and  **OnInactive\(\)**  for a Page ability and use  **OnActive\(\)**  to obtain the resources released in  **OnInactive\(\)**.
N
NEEN 已提交
44

M
mamingshuai 已提交
45
    -   **OnInactive\(\)**
N
NEEN 已提交
46

M
mamingshuai 已提交
47
        This callback is invoked when the Page ability loses focus, and the Page ability then becomes  **INACTIVE**. You can implement the behavior to perform after the Page ability loses focus.
N
NEEN 已提交
48

M
mamingshuai 已提交
49
    -   **OnBackground\(\)**
N
NEEN 已提交
50

M
mamingshuai 已提交
51
        This callback is invoked based on the system resource status when the Page ability becomes invisible to the user. After this callback is executed, the Page ability enters the  **BACKGROUND**  state. You should release the resources that are no longer needed after the Page ability becomes invisible or perform time-consuming save operations in this callback.
N
NEEN 已提交
52

M
mamingshuai 已提交
53
    -   **OnForeground\(\)**
N
NEEN 已提交
54

M
mamingshuai 已提交
55
        A Page ability in the  **BACKGROUND**  state still resides in memory. When the Page ability returns to the foreground \(for example, when the user navigates to this Page ability again\), the system first calls  **OnForeground\(\)**  to switch the Page ability to the  **INACTIVE**  state, and then calls  **OnActive\(\)**  to make it  **ACTIVE**. You should use the  **OnForeground\(\)**  callback to reclaim the resources released in  **OnBackground\(\)**. Currently, the  **OnForeground\(\)**  callback is unavailable to lite devices.
N
NEEN 已提交
56

M
mamingshuai 已提交
57
    -   **OnStop\(\)**
N
NEEN 已提交
58

M
mamingshuai 已提交
59
        This callback is invoked when the system is destroying a Page ability due to one of the following possible causes:
N
NEEN 已提交
60

M
mamingshuai 已提交
61 62 63 64
        -   The user explicitly closes the Page ability using a system management feature, for example, the task manager.
        -   The user behavior, for example, exiting an application, triggers the  **TerminateAbility\(\)**  function on the Page ability.
        -   The system needs to temporarily destroy the Page ability and re-create it due to configuration changes.
        -   The system automatically destroys a Page ability in the  **BACKGROUND**  state due to resource management purposes.
N
NEEN 已提交
65 66


M
mamingshuai 已提交
67 68
-   **AbilityKit**  is a development kit provided by the ability management framework. You can use this kit to develop applications based on the  **Ability**  component. There are two types of applications developed based on the  **Ability**  component: JS Ability developed using the JavaScript language and Native Ability developed using the C/C++ language. The JS application development framework encapsulates JavaScript UI components on the basis of the AbilityKit and is used to help you quickly develop JS Ability-based applications.
-   **AbilityLoader**  is used to register and load  **Ability**  classes. After creating an  **Ability**  class, you should first call the registration API defined in  **AbilityLoader**  to register the  **Ability**  class name with the ability management framework so that this  **Ability**  can be instantiated when being started.
N
NEEN 已提交
69

M
mamingshuai 已提交
70
-   **AbilityManager**  enables inter-process communication \(IPC\) between the AbilityKit and the Ability Manager Service.
N
NEEN 已提交
71

M
mamingshuai 已提交
72
-   **EventHandler**  is provided by the AbilityKit to enable inter-thread communication between abilities.
N
NEEN 已提交
73

M
mamingshuai 已提交
74
-   The  **Ability Manager Service**  is a system service used to coordinate the running relationships and lifecycle states of  **Ability**  instances. It consists of the following modules:
N
NEEN 已提交
75

M
mamingshuai 已提交
76 77 78 79 80 81
    -   The service startup module starts and registers the Ability Manager Service.
    -   The service interface management module manages external capabilities provided by the Ability Manager Service.
    -   The process management module starts and destroys processes where  **Ability**  instances are running, and maintains the process information.
    -   The ability stack management module maintains the presentation sequence of abilities in the stack.
    -   The lifecycle scheduling module changes an ability to a particular state based on the current operation of the system.
    -   The connection management module manages connections to Service abilities.
N
NEEN 已提交
82

M
mamingshuai 已提交
83
-   **AppSpawn**  is a system service used to create the process for running an ability. This service has high permissions. It sets permissions for  **Ability**  instances and pre-loads some common modules to accelerate application startup.
N
NEEN 已提交
84 85


M
mamingshuai 已提交
86 87 88 89 90
## Bundle Management Framework<a name="section1341146154412"></a>

The bundle management framework is provided by OpenHarmony for you to manage application bundles.

**Figure  4**  Architecture of the bundle management framework<a name="fig85883251434"></a>  
91
![](figures/architecture-of-the-bundle-management-framework.png "architecture-of-the-bundle-management-framework")
M
mamingshuai 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

-   **BundleKit**  includes external APIs provided by the Bundle Manager Service, including the APIs for application installation and uninstallation, bundle information query, and bundle state change listeners.
-   The  **bundle scanning sub-module**  parses pre-installed or installed bundles on the local device and extracts information from them for the bundle management module to manage and make the information persistent for storage.
-   The  **bundle installation sub-module**  installs, uninstalls, and updates a bundle. The  **bundle installation service**  is an independent process that communicates with the Bundle Manager Service through IPC. It is used to create or delete installation directories and has high permissions.

-   The  **bundle management sub-module**  manages information related to application bundles and stores persistent bundle information.

-   The  **bundle security management sub-module**  verifies signatures, and grants and manages permissions.


## Working Principles<a name="section94302021112717"></a>

The Ability Manager Service and Bundle Manager Service are the core modules of the ability management framework and bundle management framework, respectively. The two system-level services are registered and discovered by using the system service framework SAMgr, and they are used by manage abilities and bundles for other processes. The Ability Manager Service and Bundle Manager Service are provided as open APIs in the AbilityKit and BundleKit.

**Figure  5**  Startup of the Ability Manager Service and Bundle Manager Service<a name="fig13121104711910"></a>  
107
![](figures/startup-of-the-ability-manager-service-and-bundle-manager-service.png "startup-of-the-ability-manager-service-and-bundle-manager-service")
M
mamingshuai 已提交
108 109 110 111

OpenHarmony applications can be installed and started after the two services are started.

**Figure  6**  Application startup process<a name="fig756104112311"></a>  
112
![](figures/application-startup-process.png "application-startup-process")
M
mamingshuai 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

The home screen is the first OpenHarmony application started by the Ability Manager Service. After the home screen is started, the user can touch any installed OpenHarmony application on the home screen to start the particular application. The figure above shows the interaction process of starting an installed application from the home screen.

As shown in the figure, the Ability Manager Service is responsible for displaying or hiding an ability, and the Bundle Manager Service is responsible for storing and querying ability information.

## Limitations and Constraints<a name="section89534912527"></a>

-   Language version

    -   C++ 11 or later


-   The specifications of the application framework vary depending on the System-on-a-Chip \(SoC\) and underlying OS capabilities.

    -   Cortex-M RAM and ROM

        -   RAM: greater than 20 KB \(recommended\)

        -   ROM: greater than 300 KB \(for the JS application development framework and related subsystems, such as UIKit and engine\)

    -   Cortex-A RAM and ROM

        -   RAM: greater than 2 MB \(recommended\)

        -   ROM: greater than 2 MB \(for the JS application development framework and related subsystems, such as UIKit and engine\)

N
NEEN 已提交
139 140 141