From 97282833f6020887ea7d913cedf57fd402704d27 Mon Sep 17 00:00:00 2001 From: adelelimi Date: Sat, 26 Jul 2025 17:18:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=A1=86=E6=9E=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=A4=84=E7=90=86=E9=87=8D=E5=A4=8Drelease=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: adelelimi --- entry/src/main/ets/common/vm/Constants.ts | 1 + .../ets/extensionability/UserAuthAbility.ts | 5 ++++- .../main/ets/pages/components/FaceAuth.ets | 19 +++++++++++++------ .../ets/pages/components/FingerprintAuth.ets | 11 ++++++++--- .../ets/pages/components/PasswordAuth.ets | 2 +- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/entry/src/main/ets/common/vm/Constants.ts b/entry/src/main/ets/common/vm/Constants.ts index 2cad77f..da9e593 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 36bb785..45a659b 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 28b0641..cd4609e 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 8102f7f..431c881 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 8721c00..b922d63 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'); -- Gitee