1e41f4b71Sopenharmony_ci# @ohos.display (Display) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **Display** module provides APIs for managing displays, such as obtaining information about the default display, obtaining information about all displays, and listening for the addition and removal of displays. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> - This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohso.display (Display)](js-apis-display.md). 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```ts 14e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## display.hasPrivateWindow<sup>9+</sup> 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_cihasPrivateWindow(displayId: number): boolean 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciChecks whether there is a visible privacy window on a display. The privacy window can be set by calling [setWindowPrivacyMode()](js-apis-window.md#setwindowprivacymode9). The content in the privacy window cannot be captured or recorded. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**System API**: This is a system API. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.WindowManager.WindowManager.Core 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**Parameters** 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 30e41f4b71Sopenharmony_ci| ------ | ------------------------- | ---- |----------| 31e41f4b71Sopenharmony_ci| id | number | Yes | ID of the display. The value must be an integer greater than or equal to 0.| 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**Return value** 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci| Type | Description | 36e41f4b71Sopenharmony_ci| -------------------------------- |-----------------------------------------------------------------------| 37e41f4b71Sopenharmony_ci|boolean | Whether there is a visible privacy window on the display.<br>The value **true** means that there is a visible privacy window on the display, and **false** means the opposite.<br>| 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**Error codes** 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md). 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci| ID| Error Message| 44e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- | 45e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API.| 46e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.| 47e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci**Example** 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci```ts 52e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 55e41f4b71Sopenharmony_citry { 56e41f4b71Sopenharmony_ci displayClass = display.getDefaultDisplaySync(); 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci let ret: boolean = true; 59e41f4b71Sopenharmony_ci try { 60e41f4b71Sopenharmony_ci ret = display.hasPrivateWindow(displayClass.id); 61e41f4b71Sopenharmony_ci } catch (exception) { 62e41f4b71Sopenharmony_ci console.error('Failed to check has privateWindow or not. Code: ' + JSON.stringify(exception)); 63e41f4b71Sopenharmony_ci } 64e41f4b71Sopenharmony_ci if (ret == undefined) { 65e41f4b71Sopenharmony_ci console.log("Failed to check has privateWindow or not."); 66e41f4b71Sopenharmony_ci } 67e41f4b71Sopenharmony_ci if (ret) { 68e41f4b71Sopenharmony_ci console.log("There has privateWindow."); 69e41f4b71Sopenharmony_ci } else if (!ret) { 70e41f4b71Sopenharmony_ci console.log("There has no privateWindow."); 71e41f4b71Sopenharmony_ci } 72e41f4b71Sopenharmony_ci} catch (exception) { 73e41f4b71Sopenharmony_ci console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); 74e41f4b71Sopenharmony_ci} 75e41f4b71Sopenharmony_ci``` 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci## display.on('privateModeChange')<sup>10+</sup> 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_cion(type: 'privateModeChange', callback: Callback<boolean>): void 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ciSubscribes to privacy mode changes of this display. When there is a privacy window in the foreground of the display, the display is in privacy mode, and the content in the privacy window cannot be captured or recorded. 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**System API**: This is a system API. 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**System capability**: SystemCapability.WindowManager.WindowManager.Core 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci**Parameters** 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 90e41f4b71Sopenharmony_ci| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 91e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at 'privateModeChange', indicating the event of display privacy mode changes.| 92e41f4b71Sopenharmony_ci| callback | Callback<boolean> | Yes | Callback used to return whether the privacy mode of the display is changed. The value **true** means that the display changes to the privacy mode, and **false** means the opposite.| 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci**Error codes** 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci| ID| Error Message| 99e41f4b71Sopenharmony_ci| ------- | ----------------------- | 100e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API.| 101e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci**Example** 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci```ts 106e41f4b71Sopenharmony_ciimport { Callback } from '@kit.BasicServicesKit'; 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_cilet callback: Callback<boolean> = (data: boolean) => { 109e41f4b71Sopenharmony_ci console.info('Listening enabled. Data: ' + JSON.stringify(data)); 110e41f4b71Sopenharmony_ci}; 111e41f4b71Sopenharmony_citry { 112e41f4b71Sopenharmony_ci display.on("privateModeChange", callback); 113e41f4b71Sopenharmony_ci} catch (exception) { 114e41f4b71Sopenharmony_ci console.error('Failed to register callback. Code: ' + JSON.stringify(exception)); 115e41f4b71Sopenharmony_ci} 116e41f4b71Sopenharmony_ci``` 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci## display.off('privateModeChange')<sup>10+</sup> 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_cioff(type: 'privateModeChange', callback?: Callback<boolean>): void 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ciUnsubscribes from privacy mode changes of this display. When there is a privacy window in the foreground of the display, the display is in privacy mode, and the content in the privacy window cannot be captured or recorded. 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci**System API**: This is a system API. 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**System capability**: SystemCapability.WindowManager.WindowManager.Core 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**Parameters** 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 131e41f4b71Sopenharmony_ci| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 132e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is fixed at 'privateModeChange', indicating the event of display privacy mode changes.| 133e41f4b71Sopenharmony_ci| callback | Callback<boolean> | No | Callback used to return whether the privacy mode of the display is changed. The value **true** means that the display changes to the privacy mode, and **false** means the opposite.| 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci**Error codes** 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci| ID| Error Message| 140e41f4b71Sopenharmony_ci| ------- | ----------------------- | 141e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API.| 142e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci**Example** 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci```ts 147e41f4b71Sopenharmony_citry { 148e41f4b71Sopenharmony_ci display.off("privateModeChange"); 149e41f4b71Sopenharmony_ci} catch (exception) { 150e41f4b71Sopenharmony_ci console.error('Failed to unregister callback. Code: ' + JSON.stringify(exception)); 151e41f4b71Sopenharmony_ci} 152e41f4b71Sopenharmony_ci``` 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci## display.setFoldDisplayMode<sup>10+</sup> 155e41f4b71Sopenharmony_cisetFoldDisplayMode(mode: FoldDisplayMode): void 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ciSets the display mode of the foldable device. 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci**System API**: This is a system API. 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Window.SessionManager 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci**Parameters** 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 166e41f4b71Sopenharmony_ci| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 167e41f4b71Sopenharmony_ci| mode | [FoldDisplayMode](js-apis-display.md#folddisplaymode10) | Yes | Display mode.| 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci**Error codes** 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md). 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci| ID| Error Message| 174e41f4b71Sopenharmony_ci| ------- | ----------------------- | 175e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API.| 176e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 177e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci**Example** 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci```ts 182e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_citry { 185e41f4b71Sopenharmony_ci let mode: display.FoldDisplayMode = display.FoldDisplayMode.FOLD_DISPLAY_MODE_FULL; 186e41f4b71Sopenharmony_ci display.setFoldDisplayMode(mode); 187e41f4b71Sopenharmony_ci} catch (exception) { 188e41f4b71Sopenharmony_ci console.error('Failed to change the fold display mode. Code: ' + JSON.stringify(exception)); 189e41f4b71Sopenharmony_ci} 190e41f4b71Sopenharmony_ci``` 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci## display.setFoldStatusLocked<sup>11+</sup> 193e41f4b71Sopenharmony_cisetFoldStatusLocked(locked: boolean): void 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ciSets whether to lock the current fold status of the foldable device. 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci**System API**: This is a system API. 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Window.SessionManager 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci**Parameters** 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 204e41f4b71Sopenharmony_ci| -------- |------------------------------------------| ---- | ------------------------------------------------------- | 205e41f4b71Sopenharmony_ci| locked | boolean | Yes | Whether to lock the current fold status of the foldable device. The value **true** means to lock the current fold status, and **false** means the opposite.| 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**Error codes** 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md). 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci| ID| Error Message| 212e41f4b71Sopenharmony_ci| ------- | ----------------------- | 213e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API.| 214e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.| 215e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci**Example** 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci```ts 220e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_citry { 223e41f4b71Sopenharmony_ci let locked: boolean = false; 224e41f4b71Sopenharmony_ci display.setFoldStatusLocked(locked); 225e41f4b71Sopenharmony_ci} catch (exception) { 226e41f4b71Sopenharmony_ci console.error('Failed to change the fold status locked mode. Code: ' + JSON.stringify(exception)); 227e41f4b71Sopenharmony_ci} 228e41f4b71Sopenharmony_ci``` 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci## Display 231e41f4b71Sopenharmony_ciImplements a **Display** instance, with properties and APIs defined. 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ciBefore calling any API in **Display**, you must use [getAllDisplays()](js-apis-display.md#displaygetalldisplays9) or [getDefaultDisplaySync()](js-apis-display.md#displaygetdefaultdisplaysync9) to obtain a **Display** instance. 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci### hasImmersiveWindow<sup>11+</sup> 236e41f4b71Sopenharmony_cihasImmersiveWindow(callback: AsyncCallback<boolean>): void 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ciChecks whether this screen contains an immersive window. This API uses an asynchronous callback to return the result. 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci**System API**: This is a system API. 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Window.SessionManager 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci**Parameters** 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 247e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ------------------------------------------------------------ | 248e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means that the screen contains immersive windows, and **false** means the opposite.| 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci**Error codes** 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md). 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci| ID| Error Message| 255e41f4b71Sopenharmony_ci| ------- | ----------------------- | 256e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API.| 257e41f4b71Sopenharmony_ci| 801 | Capability not supported on this device. | 258e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. | 259e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci**Example** 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci```ts 264e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 265e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 268e41f4b71Sopenharmony_cidisplayClass = display.getDefaultDisplaySync(); 269e41f4b71Sopenharmony_cidisplayClass.hasImmersiveWindow((err: BusinessError, data) => { 270e41f4b71Sopenharmony_ci const errCode: number = err.code; 271e41f4b71Sopenharmony_ci if (errCode) { 272e41f4b71Sopenharmony_ci console.error('Failed to check whether there is immersive window. Code: ' + JSON.stringify(err)); 273e41f4b71Sopenharmony_ci return; 274e41f4b71Sopenharmony_ci } 275e41f4b71Sopenharmony_ci console.info('Succeeded in checking whether there is immersive window. data: ' + JSON.stringify(data)); 276e41f4b71Sopenharmony_ci}); 277e41f4b71Sopenharmony_ci``` 278e41f4b71Sopenharmony_ci### hasImmersiveWindow<sup>11+</sup> 279e41f4b71Sopenharmony_cihasImmersiveWindow(): Promise<boolean> 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ciChecks whether this screen contains an immersive window. This API uses a promise to return the result. 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci**System API**: This is a system API. 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Window.SessionManager 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci**Return value** 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci| Type | Description | 290e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 291e41f4b71Sopenharmony_ci| Promise<boolean> | Promise used to return the result. The value **true** means that the screen contains immersive windows, and **false** means the opposite.| 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci**Error codes** 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Display Error Codes](errorcode-display.md). 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci| ID| Error Message| 298e41f4b71Sopenharmony_ci| ------- | ----------------------- | 299e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API.| 300e41f4b71Sopenharmony_ci| 801 | Capability not supported on this device. | 301e41f4b71Sopenharmony_ci| 1400001 | Invalid display or screen. | 302e41f4b71Sopenharmony_ci| 1400003 | This display manager service works abnormally. | 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci**Example** 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci```ts 307e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 308e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_cilet displayClass: display.Display | null = null; 311e41f4b71Sopenharmony_cidisplayClass = display.getDefaultDisplaySync(); 312e41f4b71Sopenharmony_cilet promise = displayClass.hasImmersiveWindow(); 313e41f4b71Sopenharmony_cipromise.then((data) => { 314e41f4b71Sopenharmony_ci console.info('Succeeded in checking whether there is immersive window. data: ' + JSON.stringify(data)); 315e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 316e41f4b71Sopenharmony_ci console.error('Failed to check whether there is immersive window. Code: ' + JSON.stringify(err)); 317e41f4b71Sopenharmony_ci}) 318e41f4b71Sopenharmony_ci``` 319