• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.arkui.uiExtension (uiExtension) (System API)
2
3The **uiExtension** module provides APIs for the EmbeddedUIExtensionAbility (or UIExtensionAbility) to obtain the host application window information or the information about the corresponding **EmbeddedComponent** (or **UIExtensionComponent**).
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version.
8>
9> This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.arkui.uiExtension (uiExtension)](js-apis-arkui-uiExtension.md).
10
11## Modules to Import
12
13```
14import { uiExtension } from '@kit.ArkUI'
15```
16
17## WindowProxy
18
19### hideNonSecureWindows
20
21hideNonSecureWindows(shouldHide: boolean): Promise\<void>
22
23Sets whether to hide insecure windows.
24
25> **NOTE**
26>
27> Insecure windows refer to the windows that may block the **EmbeddedComponent** (or **UIExtensionComponent**), such as global floating windows, host subwindows, and dialog box windows created by the host application, excluding the aforementioned types of windows created by system applications. When the **EmbeddedComponent** (or **UIExtensionComponent**) is used to present important information, you can hide insecure windows to prevent such information from being blocked. When the **EmbeddedComponent** (or **UIExtensionComponent**) is not displayed or is destroyed, you must unhide the insecure windows. By default, the **UIExtensionComponent** created using the **CreateModalUIExtension** API hides insecure windows. To cancel this behavior and show insecure windows, apply for the **ohos.permission.ALLOW_SHOW_NON_SECURE_WINDOWS** permission and call this API to set **shouldHide** to **false**.
28>
29> This API has no effect on 2-in-1 devices.
30
31**System capability**: SystemCapability.ArkUI.ArkUI.Full
32
33**System API**: This is a system API and cannot be called by third-party applications.
34
35**Parameters**
36
37| Name     | Type                     | Mandatory| Description      |
38| ----------- | ------------------------- | ---- | ---------- |
39| shouldHide  | boolean                   | Yes  | Whether to hide insecure windows. The value **true** means to hide insecure windows, and **false** means the opposite.|
40
41**Return value**
42
43| Type               | Description                     |
44| ------------------- | ------------------------- |
45| Promise&lt;void&gt; | Promise that returns no value.|
46
47**Error codes**
48
49| ID| Error Message                         |
50| -------- | --------------------------------- |
51| 202      | Permission verification failed. A non-system application calls a system API. |
52| 401      | Parameter error. Possible causes: <br> 1. Mandatory parameters are left unspecified. <br> 2. Incorrect parameters types. <br> 3. Parameter verification failed. |
53| 1300002  | Abnormal state. Possible causes: <br> 1. Permission denied. Interface caller does not have permission "ohos.permission.ALLOW_SHOW_NON_SECURE_WINDOWS". <br> 2. The UIExtension window proxy is abnormal. |
54| 1300003  | This window manager service works abnormally. |
55
56**Example**
57
58```ts
59// ExtensionProvider.ts
60
61import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
62import { BusinessError } from '@kit.BasicServicesKit';
63
64export default class EntryAbility extends UIExtensionAbility {
65  onSessionCreate(want: Want, session: UIExtensionContentSession) {
66    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
67    // Hide insecure windows.
68    extensionHostWindow.hideNonSecureWindows(true).then(()=> {
69      console.log(`Succeeded in hiding the non-secure windows.`);
70    }).catch((err: BusinessError)=> {
71      console.log(`Failed to hide the non-secure windows. Cause:${JSON.stringify(err)}`);
72    })
73  }
74  onSessionDestroy(session: UIExtensionContentSession) {
75    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
76    // Unhide insecure windows.
77    extensionHostWindow.hideNonSecureWindows(false).then(()=> {
78      console.log(`Succeeded in showing the non-secure windows.`);
79    }).catch((err: BusinessError)=> {
80      console.log(`Failed to show the non-secure windows. Cause:${JSON.stringify(err)}`);
81    })
82  }
83}
84```
85
86### setWaterMarkFlag
87
88setWaterMarkFlag(enable: boolean): Promise&lt;void&gt;
89
90Adds or deletes the watermark flag for this window. This API uses a promise to return the result.
91> **NOTE**
92>
93> With the watermark flag added, the watermark is applied on the full screen when the window is in the foreground, regardless of whether the window is displayed in full screen, floating, and split screen mode.
94
95**System capability**: SystemCapability.ArkUI.ArkUI.Full
96
97**System API**: This is a system API and cannot be called by third-party applications.
98
99**Parameters**
100
101| Name| Type    | Mandatory| Description                                           |
102| ------ | ------- | --- | ------------------------------------------------ |
103| enable | boolean | Yes  | Whether to add or delete the flag. The value **true** means to add the watermark flag, and **false** means to delete the watermark flag.|
104
105**Return value**
106
107| Type               | Description                     |
108| ------------------- | ------------------------- |
109| Promise&lt;void&gt; | Promise that returns no value.|
110
111**Error codes**
112
113| ID| Error Message|
114| ------- | ---------------------------------------------- |
115| 1300002 | This window state is abnormal.                 |
116| 1300003 | This window manager service works abnormally.  |
117| 1300008 | The operation is on invalid display. |
118
119**Example**
120
121```ts
122// ExtensionProvider.ts
123import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
124import { BusinessError } from '@kit.BasicServicesKit';
125
126export default class EntryAbility extends UIExtensionAbility {
127  onSessionCreate(want: Want, session: UIExtensionContentSession) {
128    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
129    // Add the watermark flag.
130    extensionHostWindow.setWaterMarkFlag(true).then(() => {
131      console.log(`Succeeded in setting water mark flag of window.`);
132    }).catch((err: BusinessError) => {
133      console.log(`Failed to setting water mark flag of window. Cause:${JSON.stringify(err)}`);
134    })
135  }
136  onSessionDestroy(session: UIExtensionContentSession) {
137    const extensionHostWindow = session.getUIExtensionHostWindowProxy();
138    // Delete the watermark flag.
139    extensionHostWindow.setWaterMarkFlag(false).then(() => {
140      console.log(`Succeeded in deleting water mark flag of window.`);
141    }).catch((err: BusinessError) => {
142      console.log(`Failed to deleting water mark flag of window. Cause:${JSON.stringify(err)}`);
143    })
144  }
145}
146```
147