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