mirror of
https://gitee.com/openharmony/applications_screenlock
synced 2024-11-23 06:19:47 +00:00
CommonEvent
Signed-off-by: lvxiaoqiang <lvxiaoqiang1@huawei.com>
This commit is contained in:
parent
e851d9f99a
commit
0783a454b5
@ -73,11 +73,11 @@ export enum ResultCode {
|
||||
FAIL = 1,
|
||||
}
|
||||
|
||||
let mCurrentUserId: number = 100
|
||||
|
||||
export default class AccountsModel {
|
||||
userAuthManager = new osAccount.UserAuth();
|
||||
pinAuthManager = new osAccount.PINAuth();
|
||||
mCurrentUserId: number = 100
|
||||
|
||||
modelInit() {
|
||||
Log.showDebug(TAG, "start ModelInit")
|
||||
@ -87,7 +87,7 @@ export default class AccountsModel {
|
||||
Log.showInfo(TAG, `eventListener:typeName ${typeName}`);
|
||||
osAccount.getAccountManager().on(typeName, name, (userId: number) => {
|
||||
Log.showInfo(TAG, `on ${typeName} callback userId = ${userId}`)
|
||||
mCurrentUserId = userId
|
||||
this.mCurrentUserId = userId
|
||||
callback()
|
||||
})
|
||||
}
|
||||
@ -119,7 +119,7 @@ export default class AccountsModel {
|
||||
for (const user of list) {
|
||||
Log.showDebug(TAG, `start get user, localId=${user.localId}, localName=${user.localName}`);
|
||||
if (user.isActived) {
|
||||
mCurrentUserId = user.localId
|
||||
this.mCurrentUserId = user.localId
|
||||
}
|
||||
let userData: UserData = {
|
||||
userId: user.localId,
|
||||
@ -157,9 +157,9 @@ export default class AccountsModel {
|
||||
}
|
||||
|
||||
authUser(challenge, authType: AuthType, authLevel: number, callback) {
|
||||
Log.showDebug(TAG, `authUser param: userId ${mCurrentUserId} challenge ${challenge}`);
|
||||
Log.showDebug(TAG, `authUser param: userId ${this.mCurrentUserId} challenge ${challenge}`);
|
||||
Trace.end(Trace.CORE_METHOD_CALL_ACCOUNT_SYSTEM);
|
||||
this.userAuthManager.authUser(mCurrentUserId, challenge, authType, authLevel, {
|
||||
this.userAuthManager.authUser(this.mCurrentUserId, challenge, authType, authLevel, {
|
||||
onResult: (result, extraInfo) => {
|
||||
Log.showInfo(TAG, `authUser UserAuthManager.authUser onResult`);
|
||||
Trace.start(Trace.CORE_METHOD_PASS_ACCOUNT_SYSTEM_RESULT);
|
||||
@ -220,10 +220,13 @@ export default class AccountsModel {
|
||||
}
|
||||
|
||||
isActivateAccount(callback: Callback<boolean>) {
|
||||
Log.showDebug(TAG, `isActivateAccount userId:${mCurrentUserId}`)
|
||||
osAccount.getAccountManager().isOsAccountActived(mCurrentUserId).then((isActivate) => {
|
||||
Log.showInfo(TAG, `isActivateAccount userId:${mCurrentUserId} result: ${isActivate}`)
|
||||
Log.showDebug(TAG, `isActivateAccount userId:${this.mCurrentUserId}`)
|
||||
osAccount.getAccountManager().isOsAccountActived(this.mCurrentUserId).then((isActivate) => {
|
||||
Log.showInfo(TAG, `isActivateAccount userId:${this.mCurrentUserId} result: ${isActivate}`)
|
||||
callback(isActivate)
|
||||
})
|
||||
}
|
||||
getCurrentUserId() {
|
||||
return this.mCurrentUserId;
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ import {ScreenLockStatus} from '../../../../../../../../common/src/main/ets/defa
|
||||
import createOrGet from '../../../../../../../../common/src/main/ets/default/SingleInstanceHelper'
|
||||
import Router from '@system.router';
|
||||
import commonEvent from '@ohos.commonEvent';
|
||||
import { CommonEventPublishData } from 'commonEvent/commonEventPublishData';
|
||||
import {Callback} from 'basic';
|
||||
|
||||
const TAG = 'ScreenLock-ScreenLockService';
|
||||
@ -72,7 +73,7 @@ let mUnLockBeginAnimation: Callback<Callback<void>> = (callback: Callback<void>)
|
||||
export class ScreenLockService {
|
||||
accountModel: AccountModel = new AccountModel()
|
||||
screenLockModel: ScreenLockModel = new ScreenLockModel()
|
||||
|
||||
currentLockStatus : ScreenLockStatus;
|
||||
init() {
|
||||
Log.showDebug(TAG, 'init');
|
||||
this.accountModel.modelInit();
|
||||
@ -138,7 +139,13 @@ export class ScreenLockService {
|
||||
Log.showInfo(TAG, `showScreenLockWindow finish`);
|
||||
this.checkPinAuthProperty(() => {
|
||||
});
|
||||
this.publish("common.event.LOCK_SCREEN");
|
||||
Log.showInfo(TAG, `screenlock status:${this.currentLockStatus}, userId : ${this.accountModel.getCurrentUserId()}`);
|
||||
if (this.currentLockStatus == ScreenLockStatus.Locking) {
|
||||
Log.showInfo(TAG, `had locked, no need to publish lock_screen`);
|
||||
} else {
|
||||
this.publishByUser("common.event.LOCK_SCREEN", this.accountModel.getCurrentUserId());
|
||||
this.currentLockStatus = ScreenLockStatus.Locking;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -215,12 +222,13 @@ export class ScreenLockService {
|
||||
Log.showInfo(TAG, `unlocking`);
|
||||
//set the lockStatus to 'Unlock'
|
||||
AppStorage.SetOrCreate('lockStatus', ScreenLockStatus.Unlock);
|
||||
this.currentLockStatus = ScreenLockStatus.Unlock;
|
||||
//unlock the screen
|
||||
this.screenLockModel.hiddenScreenLockWindow(() => {
|
||||
Log.showInfo(TAG, `hiddenScreenLockWindow finish`);
|
||||
//notify the base service that the unlock is completed
|
||||
this.notifyScreenResult(UnlockResult.Success);
|
||||
this.publish("common.event.UNLOCK_SCREEN");
|
||||
this.publishByUser("common.event.UNLOCK_SCREEN", this.accountModel.getCurrentUserId());
|
||||
});
|
||||
}
|
||||
|
||||
@ -272,6 +280,7 @@ export class ScreenLockService {
|
||||
this.unlockScreen()
|
||||
} else {
|
||||
AppStorage.SetOrCreate('lockStatus', ScreenLockStatus.FaceNotRecognized);
|
||||
this.currentLockStatus = ScreenLockStatus.FaceNotRecognized;
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -306,9 +315,14 @@ export class ScreenLockService {
|
||||
})
|
||||
}
|
||||
|
||||
private publish(eventName: string) {
|
||||
Log.showInfo(TAG, `publish event name: ${eventName}`)
|
||||
commonEvent.publish(eventName, (error, value) => {
|
||||
private publishByUser(eventName: string, activeUserId: number) {
|
||||
Log.showDebug(TAG, `publishByUser event name: ${eventName}, userId: ${activeUserId}`)
|
||||
let publishData : CommonEventPublishData = {
|
||||
parameters : {
|
||||
userId : activeUserId
|
||||
}
|
||||
};
|
||||
commonEvent.publish(eventName, publishData, (error, value) => {
|
||||
if (error.code) {
|
||||
Log.showError(TAG, 'Operation failed. Cause: ' + JSON.stringify(error));
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user