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, Trace} from '@ohos/common' 17import BaseViewModel, {service, AuthSubType} from './baseViewModel' 18import {Callback} from '@ohos.base'; 19 20const TAG = 'ScreenLock-MixedPSDViewModel' 21 22export default class MixedPSDViewModel extends BaseViewModel { 23 password: string= ''; 24 25 constructor() { 26 super(); 27 } 28 29 ViewModelInit(): void{ 30 Log.showDebug(TAG, 'ViewModelInit'); 31 super.ViewModelInit(); 32 } 33 34 onInputChange(value: string) { 35 Log.showInfo(TAG, `onInputChange`); 36 this.password = value; 37 } 38 39 onCallPhone() { 40 Log.showInfo(TAG, 'onCallPhone'); 41 } 42 43 onAuthPassword(callback: Callback<void>) { 44 Log.showInfo(TAG, `onAuthPassword`); 45 if (!this.password || this.inhibitInput) { 46 callback(); 47 return; 48 } 49 Trace.start(Trace.CORE_METHOD_UNLOCK_SCREEN); 50 Trace.start(Trace.CORE_METHOD_CALL_ACCOUNT_SYSTEM); 51 service.authUser(AuthSubType.PIN_MIXED, this.password, (result, extraInfo) => { 52 this.clearPassword(); 53 if (result == 0) { 54 //unlock the screen 55 service.unlocking(); 56 service.goBack(); 57 } else { 58 //Clear the entered password 59 super.changePrompt(extraInfo.remainTimes, extraInfo.freezingTime, callback); 60 } 61 }); 62 } 63 64 clearPassword() { 65 Log.showInfo(TAG, `clearPassword`) 66 this.password = ''; 67 } 68} 69