README.md
1# Lite Power Manager<a name="EN-US_TOPIC_0000001126247025"></a>
2
3- [Introduction](#section11660541593)
4- [Directory Structure](#section19472752217)
5- [Usage](#section146636391856)
6 - [Available APIs](#section481251394)
7 - [Usage Guidelines](#section12620311012)
8
9- [Repositories Involved](#section63151229062)
10
11## Introduction<a name="section11660541593"></a>
12
13The lite power manager provides the following capabilities:
14
151. Managing sleep and wakeup locks.
162. Keeping the device screen always on using a lock
17
18**Figure 1** Lite power manager architecture<a name="fig106301571239"></a>
19
20
21![](figures/en-us_image_0000001079710638.png)
22
23## Directory Structure<a name="section19472752217"></a>
24
25```
26base/powermgr/powermgr_lite
27├── figures # Architecture figures
28├── frameworks # Frameworks
29│ ├── include # Header files
30│ └── src # Source files
31├── interfaces # APIs
32│ ├── innerkits # Internal APIs
33│ └── kits # External APIs
34├── services # Services
35│ ├── include # Header files
36│ └── src # Source files
37└── utils # Utilities
38 ├── include # Header files
39 └── src # Source files
40```
41
42## Usage<a name="section146636391856"></a>
43
44### Available APIs<a name="section481251394"></a>
45
46The following table lists the JavaScript APIs provided by the lite power manager.
47
48<a name="table45171237103112"></a>
49<table><thead align="left"><tr id="row12572123793117"><th class="cellrowborder" valign="top" width="38.71%" id="mcps1.1.3.1.1"><p id="p19572937163116"><a name="p19572937163116"></a><a name="p19572937163116"></a><strong id="b98969616388"><a name="b98969616388"></a><a name="b98969616388"></a>API</strong></p>
50</th>
51<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.3.1.2"><p id="p157213711313"><a name="p157213711313"></a><a name="p157213711313"></a><strong id="b17930187133810"><a name="b17930187133810"></a><a name="b17930187133810"></a>Description</strong></p>
52</th>
53</tr>
54</thead>
55<tbody><tr id="row14574143723119"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p67351028124111"><a name="p67351028124111"></a><a name="p67351028124111"></a>RunningLock *CreateRunningLock(const char *name, RunningLockType type, RunningLockFlag flag)</p>
56</td>
57<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p105741337153115"><a name="p105741337153115"></a><a name="p105741337153115"></a>Creates a <strong id="b175677317248"><a name="b175677317248"></a><a name="b175677317248"></a>Runninglock</strong> object.</p>
58</td>
59</tr>
60<tr id="row19195203919318"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p219643914313"><a name="p219643914313"></a><a name="p219643914313"></a>void DestroyRunningLock(const RunningLock *lock)</p>
61</td>
62<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p1619618397312"><a name="p1619618397312"></a><a name="p1619618397312"></a>Destroys an <strong id="b1383113383249"><a name="b1383113383249"></a><a name="b1383113383249"></a>Runninglock</strong> object.</p>
63</td>
64</tr>
65<tr id="row9397121153216"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p1339731103216"><a name="p1339731103216"></a><a name="p1339731103216"></a>BOOL AcquireRunningLock(const RunningLock *lock)</p>
66</td>
67<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p113972183214"><a name="p113972183214"></a><a name="p113972183214"></a>Obtains a <strong id="b7678195622413"><a name="b7678195622413"></a><a name="b7678195622413"></a>Runninglock</strong> object.</p>
68</td>
69</tr>
70<tr id="row1721311920324"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p321412915320"><a name="p321412915320"></a><a name="p321412915320"></a>BOOL ReleaseRunningLock(const RunningLock *lock)</p>
71</td>
72<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p32141298323"><a name="p32141298323"></a><a name="p32141298323"></a>Releases a <strong id="b33588942512"><a name="b33588942512"></a><a name="b33588942512"></a>Runninglock</strong> object.</p>
73</td>
74</tr>
75</tbody>
76</table>
77
78### Usage Guidelines<a name="section12620311012"></a>
79
80**Runninglock Management**
81
82The lite power manager provides APIs to create, obtain, and release **Runninglock** objects.
83
84The sample code is as follows:
85
86```
87const RunningLock *lock = CreateRunningLock("runinglock_example", RUNNINGLOCK_BACKGROUND, RUNNINGLOCK_FLAG_NONE);
88if (lock == NULL) {
89 return;
90}
91BOOL ret = AcquireRunningLock(lock);
92if (ret == FLASE) {
93 DestroyRunningLock(lock);
94 return;
95}
96ReleaseRunningLock(lock);
97DestroyRunningLock(lock); // Must release runninglock before destroyed
98```
99
100## Repositories Involved<a name="section63151229062"></a>
101
102[Power management subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/power-management.md)
103
104[powermgr_power_manager](https://gitee.com/openharmony/powermgr_power_manager)
105
106[powermgr_display_manager](https://gitee.com/openharmony/powermgr_display_manager)
107
108[powermgr_battery_manager](https://gitee.com/openharmony/powermgr_battery_manager)
109
110[powermgr_thermal_manager](https://gitee.com/openharmony/powermgr_thermal_manager)
111
112[powermgr_battery_statistics](https://gitee.com/openharmony/powermgr_battery_statistics)
113
114[powermgr_battery_lite](https://gitee.com/openharmony/powermgr_battery_lite)
115
116[powermgr_powermgr_lite](https://gitee.com/openharmony/powermgr_powermgr_lite)
117
118
README_zh.md
1# 轻量级电源管理组件<a name="ZH-CN_TOPIC_0000001126247025"></a>
2
3- [简介](#section11660541593)
4- [目录](#section19472752217)
5- [说明](#section146636391856)
6 - [接口说明](#section481251394)
7 - [使用说明](#section12620311012)
8
9- [相关仓](#section63151229062)
10
11## 简介<a name="section11660541593"></a>
12
13轻量级电源组件提供如下功能:
14
151. 休眠唤醒锁管理。
162. 亮灭屏控制锁。
17
18**图 1** 轻量级电源管理组件架构图<a name="fig106301571239"></a>
19
20
21![](figures/en-us_image_0000001079710638.png)
22
23## 目录<a name="section19472752217"></a>
24
25```
26base/powermgr/powermgr_lite
27├── figures # 架构图
28├── frameworks # Framework层
29│ ├── include # Framework层头文件
30│ └── src # Framework层源文件
31├── interfaces # 接口层
32│ ├── innerkits # 内部接口层
33│ └── kits # 外部接口层
34├── services # 服务层
35│ ├── include # 服务层头文件
36│ └── src # 服务层源文件
37└── utils # 工具和通用层
38 ├── include # 工具和通用层头文件
39 └── src # 工具和通用层源文件
40```
41
42## 说明<a name="section146636391856"></a>
43
44### 接口说明<a name="section481251394"></a>
45
46轻量电源管理服务对外提供的接口,如下表:
47
48<a name="table45171237103112"></a>
49<table><thead align="left"><tr id="row12572123793117"><th class="cellrowborder" valign="top" width="38.71%" id="mcps1.1.3.1.1"><p id="p19572937163116"><a name="p19572937163116"></a><a name="p19572937163116"></a><strong id="b18552135014316"><a name="b18552135014316"></a><a name="b18552135014316"></a>接口名</strong></p>
50</th>
51<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.3.1.2"><p id="p157213711313"><a name="p157213711313"></a><a name="p157213711313"></a><strong id="b193891558123118"><a name="b193891558123118"></a><a name="b193891558123118"></a>描述</strong></p>
52</th>
53</tr>
54</thead>
55<tbody><tr id="row14574143723119"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p67351028124111"><a name="p67351028124111"></a><a name="p67351028124111"></a>RunningLock *CreateRunningLock(const char *name, RunningLockType type, RunningLockFlag flag)</p>
56</td>
57<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p105741337153115"><a name="p105741337153115"></a><a name="p105741337153115"></a>创建Runninglock对象。</p>
58</td>
59</tr>
60<tr id="row19195203919318"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p219643914313"><a name="p219643914313"></a><a name="p219643914313"></a>void DestroyRunningLock(const RunningLock *lock)</p>
61</td>
62<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p1619618397312"><a name="p1619618397312"></a><a name="p1619618397312"></a>销毁Runninglock对象。</p>
63</td>
64</tr>
65<tr id="row9397121153216"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p1339731103216"><a name="p1339731103216"></a><a name="p1339731103216"></a>BOOL AcquireRunningLock(const RunningLock *lock)</p>
66</td>
67<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p113972183214"><a name="p113972183214"></a><a name="p113972183214"></a>获取Runninglock锁。</p>
68</td>
69</tr>
70<tr id="row1721311920324"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p321412915320"><a name="p321412915320"></a><a name="p321412915320"></a>BOOL ReleaseRunningLock(const RunningLock *lock)</p>
71</td>
72<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p32141298323"><a name="p32141298323"></a><a name="p32141298323"></a>释放Runninglock锁。</p>
73</td>
74</tr>
75<tr id="row879512416482"><td class="cellrowborder" valign="top" width="38.71%" headers="mcps1.1.3.1.1 "><p id="p20796124184815"><a name="p20796124184815"></a><a name="p20796124184815"></a>BOOL IsRunningLockAcquired(const RunningLock *lock);</p>
76</td>
77<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.3.1.2 "><p id="p18796104115482"><a name="p18796104115482"></a><a name="p18796104115482"></a>判断当前锁是否已经释放</p>
78</td>
79</tr>
80</tbody>
81</table>
82
83### 使用说明<a name="section12620311012"></a>
84
85**Runninglock管理**
86
87电源管理组件提供了创建Runninglock对象、获取锁、释放锁等接口。
88
89代码示例如下:
90
91```
92const RunningLock *lock = CreateRunningLock("runinglock_example", RUNNINGLOCK_BACKGROUND, RUNNINGLOCK_FLAG_NONE);
93if (lock == NULL) {
94 return;
95}
96BOOL ret = AcquireRunningLock(lock);
97if (ret == FLASE) {
98 DestroyRunningLock(lock);
99 return;
100}
101ReleaseRunningLock(lock);
102DestroyRunningLock(lock); // Must release runninglock before destroyed
103```
104
105## 相关仓<a name="section63151229062"></a>
106
107[电源管理子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E7%94%B5%E6%BA%90%E7%AE%A1%E7%90%86%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
108
109[powermgr_power_manager](https://gitee.com/openharmony/powermgr_power_manager)
110
111[powermgr_display_manager](https://gitee.com/openharmony/powermgr_display_manager)
112
113[powermgr_battery_manager](https://gitee.com/openharmony/powermgr_battery_manager)
114
115[powermgr_thermal_manager](https://gitee.com/openharmony/powermgr_thermal_manager)
116
117[powermgr_battery_statistics](https://gitee.com/openharmony/powermgr_battery_statistics)
118
119[powermgr_battery_lite](https://gitee.com/openharmony/powermgr_battery_lite)
120
121**powermgr_powermgr_lite**
122
123