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**System capability**: SystemCapability.ArkUI.ArkUI.Full 30 31**System API**: This is a system API and cannot be called by third-party applications. 32 33**Parameters** 34 35| Name | Type | Mandatory| Description | 36| ----------- | ------------------------- | ---- | ---------- | 37| shouldHide | boolean | Yes | Whether to hide insecure windows. The value **true** means to hide insecure windows, and **false** means the opposite.| 38 39**Return value** 40 41| Type | Description | 42| ------------------- | ------------------------- | 43| Promise<void> | Promise that returns no value.| 44 45**Error codes** 46 47| ID| Error Message | 48| -------- | --------------------------------- | 49| 202 | Permission verification failed. A non-system application calls a system API. | 50| 401 | Parameter error. Possible causes: <br> 1. Mandatory parameters are left unspecified. <br> 2. Incorrect parameters types. <br> 3. Parameter verification failed. | 51| 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. | 52| 1300003 | This window manager service works abnormally. | 53 54**Example** 55 56```ts 57// ExtensionProvider.ts 58 59import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit'; 60import { BusinessError } from '@kit.BasicServicesKit'; 61 62export default class EntryAbility extends UIExtensionAbility { 63 onSessionCreate(want: Want, session: UIExtensionContentSession) { 64 const extensionHostWindow = session.getUIExtensionHostWindowProxy(); 65 // Hide insecure windows. 66 extensionHostWindow.hideNonSecureWindows(true).then(()=> { 67 console.log(`Succeeded in hiding the non-secure windows.`); 68 }).catch((err: BusinessError)=> { 69 console.log(`Failed to hide the non-secure windows. Cause:${JSON.stringify(err)}`); 70 }) 71 } 72 onSessionDestroy(session: UIExtensionContentSession) { 73 const extensionHostWindow = session.getUIExtensionHostWindowProxy(); 74 // Unhide insecure windows. 75 extensionHostWindow.hideNonSecureWindows(false).then(()=> { 76 console.log(`Succeeded in showing the non-secure windows.`); 77 }).catch((err: BusinessError)=> { 78 console.log(`Failed to show the non-secure windows. Cause:${JSON.stringify(err)}`); 79 }) 80 } 81} 82``` 83 84### setWaterMarkFlag 85 86setWaterMarkFlag(enable: boolean): Promise<void> 87 88Adds or deletes the watermark flag for this window. This API uses a promise to return the result. 89> **NOTE** 90> 91> 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. 92 93**System capability**: SystemCapability.ArkUI.ArkUI.Full 94 95**System API**: This is a system API and cannot be called by third-party applications. 96 97**Parameters** 98 99| Name| Type | Mandatory| Description | 100| ------ | ------- | --- | ------------------------------------------------ | 101| 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.| 102 103**Return value** 104 105| Type | Description | 106| ------------------- | ------------------------- | 107| Promise<void> | Promise that returns no value.| 108 109**Error codes** 110 111| ID| Error Message| 112| ------- | ---------------------------------------------- | 113| 1300002 | This window state is abnormal. | 114| 1300003 | This window manager service works abnormally. | 115| 1300008 | The operation is on invalid display. | 116 117**Example** 118 119```ts 120// ExtensionProvider.ts 121import { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit'; 122import { BusinessError } from '@kit.BasicServicesKit'; 123 124export default class EntryAbility extends UIExtensionAbility { 125 onSessionCreate(want: Want, session: UIExtensionContentSession) { 126 const extensionHostWindow = session.getUIExtensionHostWindowProxy(); 127 // Add the watermark flag. 128 extensionHostWindow.setWaterMarkFlag(true).then(() => { 129 console.log(`Succeeded in setting water mark flag of window.`); 130 }).catch((err: BusinessError) => { 131 console.log(`Failed to setting water mark flag of window. Cause:${JSON.stringify(err)}`); 132 }) 133 } 134 onSessionDestroy(session: UIExtensionContentSession) { 135 const extensionHostWindow = session.getUIExtensionHostWindowProxy(); 136 // Delete the watermark flag. 137 extensionHostWindow.setWaterMarkFlag(false).then(() => { 138 console.log(`Succeeded in deleting water mark flag of window.`); 139 }).catch((err: BusinessError) => { 140 console.log(`Failed to deleting water mark flag of window. Cause:${JSON.stringify(err)}`); 141 }) 142 } 143} 144``` 145