• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// @ts-nocheck
2/*
3 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import {Log, Trace, SysFaultLogger, FaultID} from '@ohos/common'
17import ScreenLockMar from '@ohos.screenLock';
18import windowManager  from '@ohos.window'
19import Constants from '../common/constants'
20import {Callback} from '@ohos.base';
21
22const TAG = 'ScreenLock-ScreenLockModel';
23
24export default class ScreenLockModel {
25    @SysFaultLogger({FAULT_ID: FaultID.SCREEN_LOCK_MANAGER, MSG: "call func on failed"})
26    eventListener(callback: Callback<String>) {
27        let isSuccess = null
28        try {
29            isSuccess = ScreenLockMar.onSystemEvent((event)=>{
30                Log.showInfo(TAG, `eventListener:callback:${event.eventType}`)
31                callback(event.eventType);
32            });
33        }  catch (err: any) {
34            Log.showError(TAG, `on callback error -> ${JSON.stringify(err)}`);
35        }
36        if (!isSuccess) {
37            callback('serviceRestart');
38        }
39    }
40
41    eventCancelListener(typeName: string) {
42        Log.showDebug(TAG, `eventCancleListener:typeName ${typeName}`);
43        // As off has some problem and there is no case to cancel, do nothing
44    }
45
46    @SysFaultLogger({FAULT_ID: FaultID.SCREEN_LOCK_MANAGER, MSG: "call func sendScreenLockEvent failed"})
47    sendScreenLockEvent(typeName: string, typeNo: number, callback) {
48        Log.showInfo(TAG, `sendScreenLockEvent: typeName ${typeName} typeNo  ${typeNo} `);
49        ScreenLockMar.sendScreenLockEvent(typeName, typeNo, (err, data) => {
50            callback(err, data);
51        })
52    }
53
54    showScreenLockWindow(callback: Callback<void>) {
55        Log.showInfo(TAG, `isWallpaperShow is true: ${AppStorage.Get('isWallpaperShow')}`);
56        AppStorage.SetOrCreate('isWallpaperShow', true);
57        windowManager.find(Constants.WIN_NAME).then((win) => {
58            win.show().then(() => {
59                Log.showInfo(TAG, `window show`);
60                callback();
61            })
62        })
63    }
64
65    hiddenScreenLockWindow(callback: Callback<void>) {
66        Log.showInfo(TAG, `window hide`);
67        AppStorage.SetOrCreate('isWallpaperShow', false);
68        Trace.end(Trace.CORE_METHOD_PASS_ACCOUNT_SYSTEM_RESULT);
69        windowManager.find(Constants.WIN_NAME).then((win) => {
70            Trace.start(Trace.CORE_METHOD_HIDE_PSD_PAGE);
71            win.hide().then(() => {
72                Log.showInfo(TAG, `window hide`);
73                callback();
74            })
75        })
76    }
77}
78