1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit BasicServicesKit 19 */ 20 21import { AsyncCallback } from './@ohos.base'; 22import { Callback } from './@ohos.base'; 23 24/** 25 * systemScreenLock 26 * 27 * @namespace screenLock 28 * @syscap SystemCapability.MiscServices.ScreenLock 29 * @since 7 30 */ 31declare namespace screenLock { 32 /** 33 * Checks whether the screen is currently locked. 34 * 35 * @param { AsyncCallback<boolean> } callback - the callback of isScreenLocked. 36 * @syscap SystemCapability.MiscServices.ScreenLock 37 * @since 7 38 * @deprecated since 9 39 */ 40 function isScreenLocked(callback: AsyncCallback<boolean>): void; 41 42 /** 43 * Checks whether the screen is currently locked. 44 * 45 * @returns { Promise<boolean> } the promise returned by the function. 46 * @syscap SystemCapability.MiscServices.ScreenLock 47 * @since 7 48 * @deprecated since 9 49 */ 50 function isScreenLocked(): Promise<boolean>; 51 52 /** 53 * Checks whether the screen is currently locked. 54 * 55 * @returns { boolean } returns true if the screen is currently locked, returns false otherwise. 56 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 57 * @syscap SystemCapability.MiscServices.ScreenLock 58 * @systemapi Hide this for inner system use. 59 * @since 9 60 */ 61 function isLocked(): boolean; 62 63 /** 64 * Checks whether the screen lock of the current device is secure. 65 * 66 * @param { AsyncCallback<boolean> } callback - the callback of isSecureMode. 67 * @syscap SystemCapability.MiscServices.ScreenLock 68 * @since 7 69 * @deprecated since 9 70 */ 71 function isSecureMode(callback: AsyncCallback<boolean>): void; 72 73 /** 74 * Checks whether the screen lock of the current device is secure. 75 * 76 * @returns { Promise<boolean> } the promise returned by the function. 77 * @syscap SystemCapability.MiscServices.ScreenLock 78 * @since 7 79 * @deprecated since 9 80 */ 81 function isSecureMode(): Promise<boolean>; 82 83 /** 84 * Unlock the screen. 85 * 86 * @param { AsyncCallback<void> } callback - the callback of unlockScreen. 87 * @syscap SystemCapability.MiscServices.ScreenLock 88 * @since 7 89 * @deprecated since 9 90 */ 91 function unlockScreen(callback: AsyncCallback<void>): void; 92 93 /** 94 * Unlock the screen. 95 * 96 * @returns { Promise<void> } the promise returned by the function. 97 * @syscap SystemCapability.MiscServices.ScreenLock 98 * @since 7 99 * @deprecated since 9 100 */ 101 function unlockScreen(): Promise<void>; 102 103 /** 104 * Unlock the screen. 105 * 106 * @param { AsyncCallback<boolean> } callback - the callback of unlock. 107 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 108 * <br>2. Incorrect parameter types. 109 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 110 * @throws { BusinessError } 13200002 - the screenlock management service is abnormal. 111 * @syscap SystemCapability.MiscServices.ScreenLock 112 * @systemapi Hide this for inner system use. 113 * @since 9 114 */ 115 /** 116 * Unlock the screen. 117 * 118 * @param { AsyncCallback<boolean> } callback - the callback of unlock. 119 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 120 * <br>2. Incorrect parameter types. 121 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 122 * @throws { BusinessError } 13200002 - the screenlock management service is abnormal. 123 * @throws { BusinessError } 13200003 - illegal use. 124 * @syscap SystemCapability.MiscServices.ScreenLock 125 * @systemapi Hide this for inner system use. 126 * @since 11 127 */ 128 function unlock(callback: AsyncCallback<boolean>): void; 129 130 /** 131 * Unlock the screen. 132 * 133 * @returns { Promise<boolean> } the promise returned by the function. 134 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 135 * @throws { BusinessError } 13200002 - the screenlock management service is abnormal. 136 * @syscap SystemCapability.MiscServices.ScreenLock 137 * @systemapi Hide this for inner system use. 138 * @since 9 139 */ 140 /** 141 * Unlock the screen. 142 * 143 * @returns { Promise<boolean> } the promise returned by the function. 144 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 145 * @throws { BusinessError } 13200002 - the screenlock management service is abnormal. 146 * @throws { BusinessError } 13200003 - illegal use. 147 * @syscap SystemCapability.MiscServices.ScreenLock 148 * @systemapi Hide this for inner system use. 149 * @since 11 150 */ 151 function unlock(): Promise<boolean>; 152 153 /** 154 * Lock the screen. 155 * 156 * @permission ohos.permission.ACCESS_SCREEN_LOCK_INNER 157 * @param { AsyncCallback<boolean> } callback - the callback of lock. 158 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 159 * <br>2. Incorrect parameter types. 160 * @throws { BusinessError } 201 - permission denied. 161 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 162 * @throws { BusinessError } 13200002 - the screenlock management service is abnormal. 163 * @syscap SystemCapability.MiscServices.ScreenLock 164 * @systemapi Hide this for inner system use. 165 * @since 9 166 */ 167 function lock(callback: AsyncCallback<boolean>): void; 168 169 /** 170 * Lock the screen. 171 * 172 * @permission ohos.permission.ACCESS_SCREEN_LOCK_INNER 173 * @returns { Promise<boolean> } the promise returned by the function. 174 * @throws { BusinessError } 201 - permission denied. 175 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 176 * @throws { BusinessError } 13200002 - the screenlock management service is abnormal. 177 * @syscap SystemCapability.MiscServices.ScreenLock 178 * @systemapi Hide this for inner system use. 179 * @since 9 180 */ 181 function lock(): Promise<boolean>; 182 183 /** 184 * Indicates the system event type related to the screenlock management service. 185 * 186 * @syscap SystemCapability.MiscServices.ScreenLock 187 * @systemapi Hide this for inner system use. 188 * @since 9 189 */ 190 type EventType = 191 'beginWakeUp' 192 | 'endWakeUp' 193 | 'beginScreenOn' 194 | 'endScreenOn' 195 | 'beginScreenOff' 196 | 'endScreenOff' 197 | 'unlockScreen' 198 | 'lockScreen' 199 | 'beginExitAnimation' 200 | 'beginSleep' 201 | 'endSleep' 202 | 'changeUser' 203 | 'screenlockEnabled' 204 | 'serviceRestart'; 205 206 /** 207 * Indicates the system event type and parameter related to the screenlock management service. 208 * 209 * @typedef SystemEvent 210 * @syscap SystemCapability.MiscServices.ScreenLock 211 * @systemapi Hide this for inner system use. 212 * @since 9 213 */ 214 interface SystemEvent { 215 /** 216 * Indicates the system event type related to the screenlock management service. 217 * 218 * @syscap SystemCapability.MiscServices.ScreenLock 219 * @systemapi Hide this for inner system use. 220 * @since 9 221 */ 222 eventType: EventType; 223 /** 224 * Identifies the customized extended parameter of an event. 225 * 226 * @syscap SystemCapability.MiscServices.ScreenLock 227 * @systemapi Hide this for inner system use. 228 * @since 9 229 */ 230 params: string; 231 } 232 233 /** 234 * Register system event related to screen lock service. 235 * 236 * @permission ohos.permission.ACCESS_SCREEN_LOCK_INNER 237 * @param { Callback<SystemEvent> } callback - the callback of onSystemEvent. 238 * @returns { boolean } returns true if register system event is success, returns false otherwise. 239 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 240 * <br>2. Incorrect parameter types. 241 * @throws { BusinessError } 201 - permission denied. 242 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 243 * @throws { BusinessError } 13200002 - the screenlock management service is abnormal. 244 * @syscap SystemCapability.MiscServices.ScreenLock 245 * @systemapi Hide this for inner system use. 246 * @since 9 247 */ 248 function onSystemEvent(callback: Callback<SystemEvent>): boolean; 249 250 /** 251 * The screen lock app sends the event to the screen lock service. 252 * 253 * @permission ohos.permission.ACCESS_SCREEN_LOCK_INNER 254 * @param { String } event - event type. 255 * @param { number } parameter - operation result of the event. 256 * @param { AsyncCallback<boolean> } callback - the callback of sendScreenLockEvent. 257 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 258 * <br>2. Incorrect parameter types. 259 * @throws { BusinessError } 201 - permission denied. 260 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 261 * @throws { BusinessError } 13200002 - the screenlock management service is abnormal. 262 * @syscap SystemCapability.MiscServices.ScreenLock 263 * @systemapi Hide this for inner system use. 264 * @since 9 265 */ 266 function sendScreenLockEvent(event: String, parameter: number, callback: AsyncCallback<boolean>): void; 267 268 /** 269 * The screen lock app sends the event to the screen lock service. 270 * 271 * @permission ohos.permission.ACCESS_SCREEN_LOCK_INNER 272 * @param { String } event - event type. 273 * @param { number } parameter - operation result of the event. 274 * @returns { Promise<boolean> } the promise returned by the function. 275 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 276 * <br>2. Incorrect parameter types. 277 * @throws { BusinessError } 201 - permission denied. 278 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 279 * @throws { BusinessError } 13200002 - the screenlock management service is abnormal. 280 * @syscap SystemCapability.MiscServices.ScreenLock 281 * @systemapi Hide this for inner system use. 282 * @since 9 283 */ 284 function sendScreenLockEvent(event: String, parameter: number): Promise<boolean>; 285} 286 287export default screenLock;