• 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 'basic';
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 = ScreenLockMar.onSystemEvent((err, event)=>{
30            Log.showInfo(TAG, `eventListener:callback:${event.eventType}`)
31            callback(event.eventType);
32            if (err) {
33                Log.showError(TAG, `on callback error -> ${JSON.stringify(err)}`);
34            }
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        Trace.end(Trace.CORE_METHOD_PASS_ACCOUNT_SYSTEM_RESULT);
68        windowManager.find(Constants.WIN_NAME).then((win) => {
69            Trace.start(Trace.CORE_METHOD_HIDE_PSD_PAGE);
70            win.hide().then(() => {
71                Log.showInfo(TAG, `window hide`);
72                callback();
73                AppStorage.SetOrCreate('isWallpaperShow', false);
74            })
75        })
76    }
77}
78