• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.contextConstant (Context-related Constants)
2<!--Kit: Ability Kit-->
3<!--Subsystem: Ability-->
4<!--Owner: @wangkailong; @yangxuguang-huawei; @Luobniz21-->
5<!--Designer: @ccllee1; @li-weifeng2-->
6<!--Tester: @lixueqing513-->
7<!--Adviser: @huipeizi-->
8
9The ContextConstant module defines context-related enums. Currently, it defines only the enum of encryption levels.
10
11> **NOTE**
12>
13> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
14>
15> The APIs of this module can be used only in the stage model.
16
17## Modules to Import
18
19```ts
20import { contextConstant } from '@kit.AbilityKit';
21```
22
23## AreaMode
24
25Enumerates the data encryption levels.
26
27**System capability**: SystemCapability.Ability.AbilityRuntime.Core
28
29| Name | Value| Description                                                                                                                  |
30|-----| -------- |----------------------------------------------------------------------------------------------------------------------|
31| EL1 | 0 | Device-level encryption. Directories with this encryption level are accessible after the device is powered on.<br>**Atomic service API**: This API can be used in atomic services since API version 11.   |
32| EL2 | 1 | User-level encryption. Directories with this encryption level are accessible only after the device is powered on and the password is entered (for the first time).<br>**Atomic service API**: This API can be used in atomic services since API version 11.      |
33| EL3<sup>11+<sup> | 2 | User-level encryption. The file permissions vary according to their scenarios.<br>- An open file is always readable and writable regardless of whether the screen is locked.<br>- When the screen is locked, a closed file cannot be opened, read, or written. When the screen is unlocked, such a file can be opened, read, and written.<br>- When the screen is locked, a file can be created and then opened and written but not read. When the screen is unlocked, a file can be created and then opened, read, and written.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
34| EL4<sup>11+<sup> | 3 | User-level encryption. The file permissions vary according to their scenarios.<br>- When the screen is locked, an open file is not readable or writable. When the screen is unlocked, such a file is readable and writable.<br>- When the screen is locked, a closed file cannot be opened, read, or written. When the screen is unlocked, such a file can be opened, read, and written.<br>- When the screen is locked, a file cannot be created. When the screen is unlocked, a file can be created and then opened, read, and written.<br>**Atomic service API**: This API can be used in atomic services since API version 11. |
35| EL5<sup>12+<sup> | 4 | Application-level encryption. The file permissions vary according to their scenarios.<br>- An open file is always readable and writable regardless of whether the screen is locked.<br>When the screen is locked, a closed file can be opened, read, and written only if the reserved key is obtained by calling [Access](js-apis-screenLockFileManager.md#screenlockfilemanageracquireaccess). When the screen is unlocked, such a file can be opened, read, and written.<br>A file can be created and then opened, read, and written regardless of whether the screen is locked.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
36
37
38## ProcessMode<sup>12+</sup>
39
40Enumerates the process modes of the UIAbility after it is started. It takes effect only on 2-in-1 devices and tablets.
41
42As a property of [StartOptions](js-apis-app-ability-startOptions.md), **ProcessMode** takes effect only in [UIAbilityContext.startAbility](js-apis-inner-application-uiAbilityContext.md#startability-1) and is used to specify the process mode of the target UIAbility.
43
44**System capability**: SystemCapability.Ability.AbilityRuntime.Core
45
46| Name | Value| Description                                                                                                                  |
47|-----| -------- |----------------------------------------------------------------------------------------------------------------------|
48| NEW_PROCESS_ATTACH_TO_PARENT | 1 | A new process is created, the UIAbility is started on the process, and the process exits along with the parent process.<br>**Constraints**:<br>In this mode, the target UIAbility and caller must be in the same application.                    |
49| NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM | 2 | A new process is created, the UIAbility is started on the process, and the process is bound to the status bar icon.<br>**Constraints**:<br>In this mode, the target UIAbility and caller must be in the same application, and the application must have an icon in the status bar.                 |
50| ATTACH_TO_STATUS_BAR_ITEM | 3 | The UIAbility is started, and the process of the UIAbility is bound to the status bar icon.<br>**Constraints**:<br>In this mode, the target UIAbility and caller must be in the same application, and the application must have an icon in the status bar.                 |
51
52**Example**
53
54  ```ts
55  import { UIAbility, Want, StartOptions, contextConstant } from '@kit.AbilityKit';
56  import { BusinessError } from '@kit.BasicServicesKit';
57
58  export default class EntryAbility extends UIAbility {
59    onForeground() {
60      let want: Want = {
61        deviceId: '',
62        bundleName: 'com.example.myapplication',
63        abilityName: 'MainAbility2'
64      };
65      let options: StartOptions = {
66        processMode: contextConstant.ProcessMode.NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM,
67        startupVisibility: contextConstant.StartupVisibility.STARTUP_HIDE
68      };
69
70      try {
71        this.context.startAbility(want, options, (err: BusinessError) => {
72          if (err.code) {
73            // Process service logic errors.
74            console.error(`startAbility failed, code is ${err.code}, message is ${err.message}`);
75            return;
76          }
77          // Carry out normal service processing.
78          console.info('startAbility succeed');
79        });
80      } catch (err) {
81        // Process input parameter errors.
82        let code = (err as BusinessError).code;
83        let message = (err as BusinessError).message;
84        console.error(`startAbility failed, code is ${code}, message is ${message}`);
85      }
86    }
87  }
88  ```
89
90## StartupVisibility<sup>12+</sup>
91
92Enumerates the visibility statuses of the UIAbility after it is started. It takes effect only on 2-in-1 devices and tablets.
93
94As a property of [StartOptions](js-apis-app-ability-startOptions.md), **StartupVisibility** takes effect only in [UIAbilityContext.startAbility](js-apis-inner-application-uiAbilityContext.md#startability-1) and specifies the visibility of the target UIAbility after it is started.
95
96**System capability**: SystemCapability.Ability.AbilityRuntime.Core
97
98| Name | Value| Description                                                                                                                  |
99|-----| -------- |----------------------------------------------------------------------------------------------------------------------|
100| STARTUP_HIDE | 0 | The target UIAbility is hidden after it is started in the new process. The **onForeground** lifecycle of the UIAbility is not invoked.       |
101| STARTUP_SHOW | 1 | The target UIAbility is displayed normally after it is started in the new process.    |
102
103**Example**
104
105  See [ContextConstant.ProcessMode](#processmode12).
106
107## Scenarios<sup>20+</sup>
108
109Enumerates the scenarios where the [onNewWant](./js-apis-app-ability-uiAbility.md#onnewwant) lifecycle callback is not triggered. It is used in the [setOnNewWantSkipScenarios](./js-apis-inner-application-uiAbilityContext.md#setonnewwantskipscenarios20) API.
110
111**Atomic service API**: This API can be used in atomic services since API version 20.
112
113**System capability**: SystemCapability.Ability.AbilityRuntime.Core
114
115| Name | Value| Description                                                                                                                  |
116|-----| -------- |----------------------------------------------------------------------------------------------------------------------|
117| SCENARIO_MOVE_MISSION_TO_FRONT | 0x00000001 | <!--RP1-->A scenario where the system API [missionManager.moveMissionToFront](./js-apis-app-ability-missionManager-sys.md#missionmanagermovemissiontofront-2) is called to move the UIAbility to the foreground.<!--RP1End-->        |
118| SCENARIO_SHOW_ABILITY | 0x00000002 | A scenario where the [showAbility](./js-apis-inner-application-uiAbilityContext.md#showability12) API is called to move the UIAbility to the foreground.    |
119| SCENARIO_BACK_TO_CALLER_ABILITY_WITH_RESULT | 0x00000004 | A scenario where the [backToCallerAbilityWithResult](./js-apis-inner-application-uiAbilityContext.md#backtocallerabilitywithresult12) API is called to move the UIAbility to the foreground.    |
120
121**Example**
122
123```ts
124import { AbilityConstant, contextConstant, UIAbility, Want } from '@kit.AbilityKit';
125import { BusinessError } from '@kit.BasicServicesKit';
126
127export default class EntryAbility extends UIAbility {
128  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
129    let scenarios: number = contextConstant.Scenarios.SCENARIO_MOVE_MISSION_TO_FRONT |
130      contextConstant.Scenarios.SCENARIO_SHOW_ABILITY |
131      contextConstant.Scenarios.SCENARIO_BACK_TO_CALLER_ABILITY_WITH_RESULT;
132
133    try {
134      this.context.setOnNewWantSkipScenarios(scenarios).then(() => {
135        // Carry out normal service processing.
136        console.info('setOnNewWantSkipScenarios succeed');
137      }).catch((err: BusinessError) => {
138        // Process service logic errors.
139        console.error(`setOnNewWantSkipScenarios failed, code is ${err.code}, message is ${err.message}`);
140      });
141    } catch (err) {
142      // Process input parameter errors.
143      let code = (err as BusinessError).code;
144      let message = (err as BusinessError).message;
145      console.error(`setOnNewWantSkipScenarios failed, code is ${code}, message is ${message}`);
146    }
147  }
148}
149```
150