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