diff --git a/entry/src/main/ets/common/vm/Constants.ts b/entry/src/main/ets/common/vm/Constants.ts index 2cad77f3d1675e47740535a05a33d0131dfa830c..da9e59380d596460587cd1451b75ead6264a2531 100644 --- a/entry/src/main/ets/common/vm/Constants.ts +++ b/entry/src/main/ets/common/vm/Constants.ts @@ -48,6 +48,7 @@ export default class Constants { static noticeEventWidgetLoaded = 'EVENT_AUTH_WIDGET_LOADED'; static noticeEventWidgetReleased = 'EVENT_AUTH_WIDGET_RELEASED'; static noticeEventUserNavigation = 'EVENT_AUTH_USER_NAVIGATION'; + static noticeEventProcessTerminate = 'EVENT_AUTH_PROCESS_TERMINATE'; static numKeyBoard : NumKeyBoardItem[] = [ { diff --git a/entry/src/main/ets/extensionability/UserAuthAbility.ts b/entry/src/main/ets/extensionability/UserAuthAbility.ts index 36bb785a9c722cad1f4c10864e31adde6e67e2ff..45a659b5d9ada8c98366bf74147d69a14b890ebf 100644 --- a/entry/src/main/ets/extensionability/UserAuthAbility.ts +++ b/entry/src/main/ets/extensionability/UserAuthAbility.ts @@ -13,11 +13,12 @@ * limitations under the License. */ +import AuthUtils from '../common/utils/AuthUtils'; +import Constants, { WantParams } from '../common/vm/Constants'; import LogUtils from '../common/utils/LogUtils'; import UserAuthExtensionAbility from '@ohos.app.ability.UserAuthExtensionAbility'; import WindowPrivacyUtils from '../common/utils/WindowPrivacyUtils'; import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; -import { WantParams } from '../common/vm/Constants'; const TAG = 'UserAuthAbility'; // The current interface only support string type @@ -63,6 +64,8 @@ export default class UserAuthAbility extends UserAuthExtensionAbility { onSessionDestroy(session): void { LogUtils.info(TAG, 'UserAuthExtensionAbility onSessionDestroy'); + const currentPageAuthType: string = AppStorage.get('currentPageAuthType') as string ?? ''; + AuthUtils.getInstance().sendNotice(Constants.noticeEventProcessTerminate, [currentPageAuthType]); WindowPrivacyUtils.setWindowPrivacyMode(session, false); } } diff --git a/entry/src/main/ets/pages/components/FaceAuth.ets b/entry/src/main/ets/pages/components/FaceAuth.ets index 28b0641ce49c161b80550d5d0bb73be14831af41..cd4609e9993276488b7faf7d6f9785829a97b112 100644 --- a/entry/src/main/ets/pages/components/FaceAuth.ets +++ b/entry/src/main/ets/pages/components/FaceAuth.ets @@ -110,6 +110,7 @@ export default struct FaceAuth { aboutToAppear(): void { LogUtils.debug(TAG, 'aboutToAppear'); + AppStorage.setOrCreate('currentPageAuthType', Constants.noticeTypeFace); try { if (this.dialogType === DialogType.PIN_FACE || this.dialogType === DialogType.FACE) { this.prompt = @@ -249,7 +250,9 @@ export default struct FaceAuth { if (payload.type === Constants.noticeTypePin) { if (payload.result === 0) { AuthUtils.getInstance().sendNotice(Constants.noticeEventWidgetReleased, [Constants.noticeTypePin]); - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + setTimeout(() => { + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + }, SECOND); } else if (payload.result && payload.result === Constants.authResultPinExpired) { this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); @@ -320,13 +323,15 @@ export default struct FaceAuth { AuthUtils.getInstance() .sendNotice(Constants.noticeEventWidgetReleased, [Constants.noticeTypeFace]); } - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + setTimeout(() => { + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + }, SECOND); } } else if (payload.type === Constants.noticeTypeFinger) { const payload: CmdData = item.payload; - let lockoutDuration: number; - let remainAttempts: number; - let authResult: number; + let lockoutDuration: number = 0; + let remainAttempts: number = 0; + let authResult: number = 0; if (item?.event === CmdNotifyEvents.CMD_NOTIFY_AUTH_TIP) { const tipInfo: string = FuncUtils.getStringFromCharCode(payload.tipInfo); if (tipInfo) { @@ -412,7 +417,9 @@ export default struct FaceAuth { AuthUtils.getInstance() .sendNotice(Constants.noticeEventCancel, [Constants.noticeTypeFace, Constants.noticeTypeFinger]); } - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + setTimeout(() => { + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + }, SECOND); } } else { LogUtils.error(TAG, 'onCmdDataChange default'); diff --git a/entry/src/main/ets/pages/components/FingerprintAuth.ets b/entry/src/main/ets/pages/components/FingerprintAuth.ets index 8102f7f9c9bd009eaa1f9ce3255b09b1f1e73b76..431c881821ab8053b481d3a0c2316bde8a88faf6 100644 --- a/entry/src/main/ets/pages/components/FingerprintAuth.ets +++ b/entry/src/main/ets/pages/components/FingerprintAuth.ets @@ -81,6 +81,7 @@ export default struct FingerprintAuth { @Link skipLockedBiometricAuth: boolean; aboutToAppear(): void { + AppStorage.setOrCreate('currentPageAuthType', Constants.noticeTypeFinger); AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); try { if (this.cmdData && this.cmdData.length > 0) { @@ -154,7 +155,7 @@ export default struct FingerprintAuth { } else { lockoutDuration = payload.lockoutDuration; remainAttempts = payload.remainAttempts; - if (payload.result) { + if (payload.result || authResult === 0) { authResult = payload.result; } else { authResult = -1; @@ -165,7 +166,9 @@ export default struct FingerprintAuth { if (payload.type === Constants.noticeTypePin) { if (authResult === 0) { AuthUtils.getInstance().sendNotice(Constants.noticeEventWidgetReleased, [Constants.noticeTypePin]); - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + setTimeout(() => { + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + }, SECOND) } else if (authResult && authResult === Constants.authResultPinExpired) { this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); @@ -276,7 +279,9 @@ export default struct FingerprintAuth { if (payload.tipType === UserAuthTipType.SINGLE_AUTH_RESULT) { AuthUtils.getInstance().sendNotice(Constants.noticeEventWidgetReleased, [Constants.noticeTypeFinger]); } - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + setTimeout(() => { + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + }, SECOND); } } else { LogUtils.error(TAG, 'onCmdDataChange default'); diff --git a/entry/src/main/ets/pages/components/PasswordAuth.ets b/entry/src/main/ets/pages/components/PasswordAuth.ets index 8721c0046c806b79a158b1068615f2998df03a0e..b922d6370c628d3e3ce1afa96df6764380b43ab9 100644 --- a/entry/src/main/ets/pages/components/PasswordAuth.ets +++ b/entry/src/main/ets/pages/components/PasswordAuth.ets @@ -84,7 +84,6 @@ export default struct PasswordAuth { return; } if (payload.result === 0) { - AuthUtils.getInstance().sendNotice(Constants.noticeEventWidgetReleased, [Constants.noticeTypePin]); (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); } this.inputValue = ' '; @@ -94,6 +93,7 @@ export default struct PasswordAuth { } aboutToAppear(): void { + AppStorage.setOrCreate('currentPageAuthType', Constants.noticeTypePin); try { if (this.cmdData && this.cmdData.length > 0) { this.onCmdDataChange('first');