• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Power Management Subsystem Changelog
2
3## cl.powermgr Change in ohos.permission.POWER_MANAGER Permission Verification and Error Codes for wakeup, suspend, setScreenOffTime and hibernate APIs
4
5**Access Level**
6
7System API
8
9**Reason for the Change**
10
11Some TS APIs violate the minimum permission principle. Therefore, permission verification need to be added to the corresponding APIs.
12
13**Change Impact**
14
15This change requires application adaptation.
16
17Before change:
18System applications can directly access the **wakeup**, **suspend**, **setScreenOffTime**, and **hibernate** APIs without requesting for permissions.
19
20After change:
21System applications can call these APIs only after obtaining the **ohos.permission.POWER_MANAGER** permission. If the API permission verification fails, error code 201 is reported.
22
23**Start API Level**
24
25- wakeup available since API version 9
26- suspend available since API version 9
27- setScreenOffTime available since API version 12
28- hibernate available since API version 12
29
30**Change Since**
31
32OpenHarmony SDK 5.1.0.56
33
34**Key API/Component Changes**
35
36The following APIs in [@ohos.account.distributedAccount.d.ts](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-basic-services-kit/js-apis-distributed-account.md):
37
38- wakeup(detail: string): void
39- suspend(isImmediate?: boolean): void
40- setScreenOffTime(timeout: number): void
41- hibernate(clearMemory: boolean): void
42
43**Adaptation Guide**
44
45An application needs to request for the **ohos.permission.POWER_MANAGER** permission for calling the related APIs.
46
47The error code 201 is added to the **wakeup** API. The following is an example:
48```ts
49import { power } from '@kit.BasicServicesKit';
50
51try {
52    power.wakeup('wakeup_test');
53} catch (err) {
54    if (err.code === 201) {
55      console.error('wakeup failed, permission verification failed');
56    } else {
57      console.error('wakeup failed, err: ' + err);
58    }
59}
60```
61
62The error code 201 is added to the **suspend** API. The following is an example:
63```ts
64import { power } from '@kit.BasicServicesKit';
65
66try {
67    power.suspend();
68} catch (err) {
69    if (err.code === 201) {
70      console.error('suspend failed, permission verification failed');
71    } else {
72      console.error('suspend failed, err: ' + err);
73    }
74}
75```
76
77The error code 201 is added to the **setScreenOffTime** API. The following is an example:
78```ts
79import { power } from '@kit.BasicServicesKit';
80
81try {
82    power.setScreenOffTime(30000);
83} catch (err) {
84    if (err.code === 201) {
85      console.error('set screen off time failed, permission verification failed');
86    } else {
87      console.error('set screen off time failed, err: ' + err);
88    }
89}
90```
91
92The error code 201 is added to the **hibernate** API. The following is an example:
93```ts
94import { power } from '@kit.BasicServicesKit';
95
96try {
97    power.hibernate(true);
98} catch (err) {
99    if (err.code === 201) {
100      console.error('hibernate failed, permission verification failed');
101    } else {
102      console.error('hibernate failed, err: ' + err);
103    }
104}
105```
106