1/* 2 * Copyright (c) 2021-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 16import {Log, ReadConfigFile} from '@ohos/common' 17 18const SCREENLOCK_MODE_FILE_NAME = "screenlock.json"; 19const TAG = 'ScreenLock-ScreenlockStyle'; 20 21 22export enum LockStyleMode { 23 SlideScreenLock = 1, 24 JournalScreenLock = 2, 25 CustomScreenLock = 3 26} 27 28class ScreenlockStyle { 29 private screenMode: LockStyleMode = LockStyleMode.SlideScreenLock 30 31 setMode(mode: LockStyleMode): number { 32 Log.showDebug(TAG, `setMode:${mode}`); 33 return this.screenMode = mode 34 } 35 36 getMode(): number { 37 return this.screenMode 38 } 39 40 readMode(): number{ 41 Log.showInfo(TAG, `readMode`); 42 let that = this; 43 try { 44 ReadConfigFile(SCREENLOCK_MODE_FILE_NAME, (modeJson)=>{ 45 Log.showInfo(TAG, `ReadConfigFile content:` + JSON.stringify(modeJson)); 46 that.screenMode = modeJson.mode; 47 }); 48 } catch(error) { 49 Log.showInfo(TAG, `ReadConfigFile content error: ${error}`); 50 this.screenMode = LockStyleMode.SlideScreenLock; 51 } 52 return this.screenMode; 53 } 54} 55 56let screenlockStyle = new ScreenlockStyle() 57 58export default screenlockStyle as ScreenlockStyle