• 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 Trace from '../../../../../../../../common/src/main/ets/default/Trace'
17import Log from '../../../../../../../../common/src/main/ets/default/Log'
18import {SysFaultLogger, FaultID} from '../../../../../../../../common/src/main/ets/default/SysFaultLogger'
19import ScreenLockMar from '@ohos.screenLock';
20import windowManager  from '@ohos.window'
21import Constants from '../common/constants'
22import { Callback } from '@ohos.base';
23
24const TAG = 'ScreenLock-ScreenLockModel';
25
26export default class ScreenLockModel {
27    @SysFaultLogger({FAULT_ID: FaultID.SCREEN_LOCK_MANAGER, MSG: "call func on failed"})
28    eventListener(callback: Callback<String>) {
29        let isSuccess = null
30        try {
31            isSuccess = ScreenLockMar.onSystemEvent((event)=>{
32                Log.showInfo(TAG, `eventListener:callback:${event.eventType}`)
33                callback(event.eventType);
34            });
35        }  catch (err: any) {
36            Log.showError(TAG, `on callback error -> ${JSON.stringify(err)}`);
37        }
38        if (!isSuccess) {
39            callback('serviceRestart');
40        }
41    }
42
43    eventCancelListener(typeName: string) {
44        Log.showDebug(TAG, `eventCancleListener:typeName ${typeName}`);
45        // As off has some problem and there is no case to cancel, do nothing
46    }
47
48    @SysFaultLogger({FAULT_ID: FaultID.SCREEN_LOCK_MANAGER, MSG: "call func sendScreenLockEvent failed"})
49    sendScreenLockEvent(typeName: string, typeNo: number, callback) {
50        Log.showInfo(TAG, `sendScreenLockEvent: typeName ${typeName} typeNo  ${typeNo} `);
51        ScreenLockMar.sendScreenLockEvent(typeName, typeNo, (err, data) => {
52            callback(err, data);
53        })
54    }
55
56    showScreenLockWindow(callback: Callback<void>) {
57        Log.showInfo(TAG, `isWallpaperShow is true: ${AppStorage.Get('isWallpaperShow')}`);
58        AppStorage.SetOrCreate('isWallpaperShow', true);
59        windowManager.find(Constants.WIN_NAME).then((win) => {
60            win.show().then(() => {
61                Log.showInfo(TAG, `window show`);
62                callback();
63            })
64        })
65    }
66
67    hiddenScreenLockWindow(callback: Callback<void>) {
68        Log.showInfo(TAG, `window hide`);
69        Trace.end(Trace.CORE_METHOD_PASS_ACCOUNT_SYSTEM_RESULT);
70        windowManager.find(Constants.WIN_NAME).then((win) => {
71            Trace.start(Trace.CORE_METHOD_HIDE_PSD_PAGE);
72            win.hide().then(() => {
73                Log.showInfo(TAG, `window hide`);
74                callback();
75                AppStorage.SetOrCreate('isWallpaperShow', false);
76            })
77        })
78    }
79}
80