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 Trace from '../../../../../../../../common/src/main/ets/default/Trace' 17import Log from '../../../../../../../../common/src/main/ets/default/Log' 18import BaseViewModel, {service, AuthType, AuthSubType} from './baseViewModel' 19import {Callback} from 'basic'; 20 21const TAG = 'ScreenLock-MixedPSDViewModel' 22 23export default class MixedPSDViewModel extends BaseViewModel { 24 password: string= ''; 25 26 constructor() { 27 super(); 28 } 29 30 ViewModelInit(): void{ 31 Log.showDebug(TAG, 'ViewModelInit'); 32 super.ViewModelInit(); 33 } 34 35 onInputChange(value: string) { 36 Log.showInfo(TAG, `onInputChange`); 37 this.password = value; 38 } 39 40 onCallPhone() { 41 Log.showInfo(TAG, 'onCallPhone'); 42 } 43 44 onAuthPassword(callback: Callback<void>) { 45 Log.showInfo(TAG, `onAuthPassword`); 46 if (!this.password || this.inhibitInput) { 47 callback(); 48 return; 49 } 50 Trace.start(Trace.CORE_METHOD_UNLOCK_SCREEN); 51 Trace.start(Trace.CORE_METHOD_CALL_ACCOUNT_SYSTEM); 52 service.authUser(AuthSubType.PIN_MIXED, this.password, (result, extraInfo) => { 53 this.clearPassword(); 54 if (result == 0) { 55 //unlock the screen 56 service.unlocking(); 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