• Home
Name Date Size #Lines LOC

..--

figures/12-May-2024-

frameworks/12-May-2024-2,8692,205

interfaces/inner_api/12-May-2024-197136

sa_profile/12-May-2024-3130

services/12-May-2024-1,8931,463

test/12-May-2024-1,6831,059

utils/12-May-2024-360259

BUILD.gnD12-May-2024866 2522

CODEOWNERSD12-May-2024763 1614

LICENSED12-May-20249.9 KiB177150

OAT.xmlD12-May-20244 KiB6714

README.mdD12-May-20243.2 KiB7756

README_ZH.mdD12-May-20249.5 KiB212167

bundle.jsonD12-May-20242.3 KiB9191

screenlock.gniD12-May-2024810 2116

README.md

1# theme_screenlock_mgr
2
3#### Introduction
4Provide three-party APP with the ability to request unlockScreen, query the screenlock status, and query whether to set the screenlock password.
5Provide screenOn callback, screenOff callback, screenSaver in and out callback, user switching callback, and screenlock manager service running status callback to the operation management
6
7**subsystem architecture diagram**
8![](figures/subsystem_architecture_zh.png "subsystem architecture diagram")
9
10#### Warehouse path
11/base/theme/screenlock_mgr
12
13#### Introduction to framework code
14/base/theme/screenlock_mgr
15├── figures                  # architecture diagram
16├── frameworks
17│   ├── js/napi              # the js interface resolves to the napi interface
18│   └── native               # interface provided for app
19├── sa_profile               # module contains the config files of system services and processes
20├── services                 # implementation of screenlock manager service
21├── test                     # unit test of interface
22└── utils                    # module contains log printing and constants for ordered commonEvent
23
24#### JS APIs and instructions
251.   JS APIs
26function isScreenLocked(callback: AsyncCallback<boolean>): void; query the screenlock status,callback mode
27function isScreenLocked(): Promise<boolean>; void; query the screenlock status,Promise mode
28
29function isSecureMode(callback: AsyncCallback<boolean>): void; query whether to set screenlock password (gesture, digital password, pin, SIM),callback mode
30function isSecureMode(): Promise<boolean>; query whether to set screenlock password (gesture, digital password, pin, SIM),Promise mode
31
32function unlockScreen(callback: AsyncCallback<void>): void; request unlockScreen,callback mode
33function unlockScreen(): Promise<void>; request unlockScreen,Promise mode
34
352.  JS APIs instructions
36// Import module
37import screenLock from '@ohos.screenLock';
38
39// query the screenlock status asynchronously with a Promise
40screenLock.isScreenLocked()
41      .then((value) => {
42          console.log(`success to screenLock.isScreenLocked: ${value}`);
43       }).catch((err) => {
44          console.error(`failed to screenLock.isScreenLocked because ${err.message}`)
45    });
46
47
48// query the screenlock status asynchronously with a callback
49screenLock.isScreenLocked((err, value) => {
50     if (err) {
51          console.error(`failed to screenLock.isScreenLocked because ${err.message}`);
52           return;
53         }
54       console.log(`success to screenLock.isScreenLocked: ${value}`);
55    });
56
57#### Debugging method
58
591.   Compile command
60
61./build.sh --product-name (Fill in the specific product name, such as:Hi3516DV300) --build-target screenlock_native
62
632.  push so file
64
65in $root\out\ohos-arm-release\miscservices\screenlock_native,push libscreenlock_server.z.so libscreenlock_client.z.so
66libscreenlock_utils.z.so to system/lib,and push libscreenlockability.z.so to system/lib/module/app下.make sure the four so files is readable at least.
67
683.  reboot
69
70#### Participation contribution
71
721. Fork warehouse
732. Submission code
743. Create a new pull request
754. Commit is complete
76
77

README_ZH.md

1# 锁屏管理服务
2
3## 简介
4### 内容介绍
5锁屏管理服务是OpenHarmony中系统服务,为锁屏应用提供注册亮屏、灭屏、开启屏幕、结束休眠、退出动画、请求解锁结果监听,并提供回调结果给锁屏应用。锁屏管理服务向三方应用提供请求解锁、查询锁屏状态、查询是否设置锁屏密码的能力。
6
7**图 1** 架构图
8
9![](figures/subsystem_architecture_zh.png "子系统架构图")
10
11### 框架图介绍
121.三方应用支持操作请求解锁、查询锁屏状态、查询是否设置锁屏密码接口调用。\
132.锁屏应用注册亮屏、灭屏、开启屏幕、结束休眠、退出动画、请求解锁结果监听等事件 \
143.框架层API用来处理三方应用和锁屏应用的js接口请求处理,NAPI层进行js调用的处理 \
154.框架层IDL用来处理NAPI接口向锁屏管理服务之间的桥梁,进行IPC通讯 \
165.锁屏管理服务用来处理三方应用和锁屏应用接口请求,并作出对应处理,提供相应的返回结果。
17
18## 目录
19
20```
21/base/theme/screenlock_mgr
22├── figures                  # 构架图
23├── frameworks
24│   ├── js/napi              # js接口解析成napi接口
25│   └── native               # 对客户端提供的接口
26├── sa_profile               # 组件包含的系统服务的配置文件和进程的配置文件
27├── services                 # 锁屏管理服务实现
28├── test                     # 接口的单元测试
29└── utils                    # 组件包含日志打印和有序公共事件定义的常量
30```
31
32## 说明
33
34### 接口说明
35
36**表 1**   锁屏管理服务的主要方法说明
37
38| 接口名                      | 描述                       |
39| -------------------------- | -------------------------- |
40| isScreenLocked(callback: AsyncCallback&lt;boolean&gt;): void; | 判断屏幕是否锁屏。callback方式 |
41| isScreenLocked(): Promise&lt;boolean&gt;; | 判断屏幕是否锁屏。Promise方式 |
42| isLocked(): boolean; | 判断屏幕是否锁屏。返回true表示屏幕已锁屏;返回false表示屏幕未锁屏。同步方式 |
43| isSecureMode(callback: AsyncCallback&lt;boolean&gt;): void; | 判断当前设备的屏幕锁定是否安全(安全屏幕锁定意味着解锁屏幕需要密码、图案或其他用户身份识别)。callback方式 |
44| isSecureMode(): Promise&lt;boolean&gt;; | 判断当前设备的屏幕锁定是否安全(安全屏幕锁定意味着解锁屏幕需要密码、图案或其他用户身份识别)。Promise方式 |
45| isSecure(): boolean; | 判断当前设备的屏幕锁定是否安全(安全屏幕锁定意味着解锁屏幕需要密码、图案或其他用户身份识别)。返回true表示当前设备的屏幕锁定安全;返回false表示当前设备的屏幕锁定不安全。同步方式 |
46| unlockScreen(callback: AsyncCallback&lt;void&gt;): void; | 三方应用解锁屏幕。callback方式 |
47| unlockScreen(): Promise&lt;void&gt;; | 三方应用解锁屏幕。Promise方式 |
48| unlock(callback: AsyncCallback&lt;boolean&gt;): void; | 三方应用解锁屏幕。如果屏幕解锁成功,则返回true,否则返回false。callback方式 |
49| unlock():Promise&lt;boolean&gt;; | 三方应用解锁屏幕。如果屏幕解锁成功,则返回true,否则返回false。Promise方式 |
50| lock(callback: AsyncCallback&lt;boolean&gt;): void; | 系统API,锁定屏幕。如果屏幕锁定成功,则返回true,否则返回false。callback方式 |
51| lock():Promise&lt;boolean&gt;; | 系统API,锁定屏幕。如果屏幕锁定成功,则返回true,否则返回false。Promise方式 |
52| SystemEvent { eventType: EventType, params: string } | 定义了系统事件回调参数结构,包含事件类型以及string类型的参数 |
53| onSystemEvent(callback: Callback&lt;SystemEvent&gt;): boolean; | 系统API,注册与系统屏幕锁定相关的系统事件。如果注册系统事件成功,则返回true,否则返回false。callback方式 |
54| sendScreenLockEvent(event: String, parameter: number, callback: AsyncCallback&lt;boolean&gt;): void; | 系统API,锁屏应用给锁屏管理服务发送事件。callback方式 |
55| sendScreenLockEvent(event: String, parameter: number): Promise&lt;boolean&gt;; | 系统API,锁屏应用给锁屏管理服务发送事件。promise方式 |
56
57
58**表 2**   EventType-事件类型说明
59
60| 事件类型                     | 描述                       |
61| -------------------------- | -------------------------- |
62| beginWakeUp | 表示设备开始唤醒。 |
63| endWakeUp | 表示设备结束唤醒。 |
64| beginScreenOn | 表示设备开始亮屏。 |
65| endScreenOn | 表示设备结束亮屏。 |
66| beginScreenOff | 表示设备开始灭屏。 |
67| endScreenOff | 表示设备结束灭屏。 |
68| unlockScreen | 表示请求屏幕解锁。 |
69| lockScreen | 表示请求屏幕锁定。 |
70| beginExitAnimation | 表示开始退场动画。 |
71| beginSleep | 表示设备开始休眠。 |
72| endSleep | 表示设备结束休眠。 |
73| changeUser | 表示切换用户。 |
74| screenlockEnabled | 表示锁屏是否启用。 |
75| serviceRestart | 表示锁屏服务进行重启。 |
76
77### JS 接口使用示例
78
79三方应用向锁屏管理服务进行查询屏幕锁屏状态
80
81```js
82导入模块
83import screenLock from '@ohos.screenlock';
84
85// Promise方式,在异步回调里面获取锁屏状态结果
86screenLock.isScreenLocked()
87    .then((data) => {
88        // 异步回调打印查询锁屏状态的结果
89        console.log(`Obtain whether the screen is locked successfully. result: ${data}`);
90    }).catch((err) => {
91        // 打印错误信息
92        console.error(`Failed to obtain whether the screen is locked, because: ${err.message}`)
93});
94
95// callback方式,在异步回调里面获取锁屏状态结果
96screenLock.isScreenLocked((err, data) => {
97    if (err) {
98        // 打印错误信息
99        console.error(`Failed to obtain whether the screen is locked, because: ${err.message}`)
100        return;
101        }
102    // 打印查询锁屏状态的结果
103    console.log(`Obtain whether the screen is locked successfully. result: ${data}`);
104});
105
106 // 同步方式里面获取锁屏状态结果。如果屏幕当前已锁定,则返回true,否则返回false
107let isLocked = screenLock.isLocked();
108
109```
110
111判断当前设备的屏幕锁定是否安全
112
113```js
114
115// Promise方式,在异步回调里面获取当前设备的屏幕锁定是否安全结果
116screenLock.isSecureMode().then((data) => {
117    console.log(`Obtain whether the device is in secure mode successfully. result: ${data}`);
118}).catch((err) => {
119    console.error(`Failed to obtain whether the device is in secure mode, because: ${err.message}`);
120});
121
122// callback方式,在异步回调里面获取当前设备的屏幕锁定是否安全结果
123screenLock.isSecureMode((err, data)=>{
124    if (err) {
125        console.error(`Failed to obtain whether the device is in secure mode, because: ${err.message}`);
126        return;
127    }
128    console.info(`Obtain whether the device is in secure mode successfully. result: ${data}`);
129});
130
131 // 同步方式里面获取当前设备的屏幕锁定是否安全结果。如果当前设备的屏幕锁定安全,则返回true,否则返回false
132let isSecure = screenLock.isSecure();
133
134```
135
136锁定屏幕
137
138```js
139
140// Promise方式,在异步回调里面获取锁屏是否成功的结果
141screenLock.lock().then((data) => {
142    console.log(`lock the screen successfully. result: ${data}`);
143}).catch((err) => {
144    console.error(`Failed to lock the screen, because: ${err.message}`);
145});
146
147// callback方式,在异步回调里面获取锁屏是否成功的结果
148screenLock.lock((err, data) => {
149    if (err) {
150        console.error(`Failed to lock the screen, because: ${err.message}`);
151        return;
152    }
153    console.info(`lock the screen successfully. result: ${data}`);
154});
155
156```
157
158锁屏应用注册事件说明:锁屏应用向锁屏管理服务注册相关监听事件
159
160 ```js
161try {
162    let isSuccess = screenLock.onSystemEvent((event) => {
163        console.log(`Register the system event which related to screenlock successfully. eventType: ${event.eventType}`)
164    });
165} catch (err) {
166    console.error(`Failed to register the system event which related to screenlock, because: ${err.message}`)
167}
168 ```
169
170三方应用向锁屏管理服务发起解锁屏幕请求
171
172 ```js
173
174// 三方应用callback方式调用请求解锁
175screenLock.unlockScreen((err) => {
176    if (err) {
177        console.error(`Failed to unlock the screen, because: ${err.message}`);
178        return;
179    }
180    console.info('unlock the screen success successfully.');
181});
182
183screenLock.unlock((err, data) => {
184    if (err) {
185        console.error(`Failed to unlock the screen, because: ${err.message}`);
186        return;
187    }
188    console.info(`unlock the screen success successfully. result: ${data}`);
189});
190
191// 三方应用Promise方式调用请求解锁
192screenLock.unlockScreen().then(() => {
193    console.info('unlock the screen success successfully.');
194}).catch((err) => {
195    console.error(`Failed to unlock the screen, because: ${err.message}`);
196});
197
198screenLock.unlock().then((data) => {
199    console.info(`unlock the screen success successfully. result: ${data}`);
200}).catch((err) => {
201    console.error(`Failed to unlock the screen, because: ${err.message}`);
202});
203
204```
205
206## 相关仓
207
208**主题框架子系统**
209
210[theme\_screenlock_mgr](https://gitee.com/openharmony/theme_screenlock_mgr)
211
212