From f61b3b0c19a2e4c64c7bd5eff9442ea97554e380 Mon Sep 17 00:00:00 2001 From: baoyang Date: Wed, 19 Feb 2025 11:58:56 +0800 Subject: [PATCH] fit multiton Signed-off-by: baoyang Change-Id: Icc8055b6777a674958b56e686ed5bf9ee40e3842 --- .../SecurityExtAbility/SecurityExtAbility.ts | 16 ++++++++----- .../main/ets/common/utils/globalContext.ts | 2 +- .../src/main/ets/pages/securityDialog.ets | 24 ++++++++++++------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts b/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts index 7fb4c25..e35b4fd 100644 --- a/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts +++ b/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts @@ -67,14 +67,16 @@ export default class SecurityExtensionAbility extends extension { private async createWindow(name: string, windowType, rect, want): Promise { console.info(TAG + 'create securityWindow'); - let dialogSet: Set = GlobalContext.load('dialogSet'); + let dialogSet: Set = GlobalContext.load('dialogSet'); if (!dialogSet) { - dialogSet = new Set(); + dialogSet = new Set(); console.info(TAG + 'new dialogSet'); GlobalContext.store('dialogSet', dialogSet); } let callerToken: number = want.parameters['ohos.caller.uid']; - if (dialogSet.has(callerToken)) { + let windId: number = want.parameters['ohos.ability.params.windowId']; + let token: String = String(callerToken) + '_' + String(windId); + if (dialogSet.has(token)) { console.info(TAG + 'window already exists'); return; } @@ -83,9 +85,11 @@ export default class SecurityExtensionAbility extends extension { let storage: LocalStorage = new LocalStorage({ 'want': want, 'win': win }); await win.bindDialogTarget(want.parameters['ohos.ability.params.token'].value, () => { win.destroyWindow(); - let dialogSet: Set = GlobalContext.load('dialogSet'); + let dialogSet: Set = GlobalContext.load('dialogSet'); let callerToken: number = want.parameters['ohos.caller.uid']; - dialogSet.delete(callerToken); + let windId: number = want.parameters['ohos.ability.params.windowId']; + let token: String = String(callerToken) + '_' + String(windId); + dialogSet.delete(token); GlobalContext.store('dialogSet', dialogSet); if (dialogSet.size === 0) { this.context.terminateSelf(); @@ -97,7 +101,7 @@ export default class SecurityExtensionAbility extends extension { win.setWindowBackgroundColor(BG_COLOR); await win.showWindow(); console.info(TAG + 'showWindow end.'); - dialogSet.add(callerToken); + dialogSet.add(token); GlobalContext.store('dialogSet', dialogSet); } catch (err) { console.error(TAG + `window create failed! err: ${JSON.stringify(err)}`); diff --git a/permissionmanager/src/main/ets/common/utils/globalContext.ts b/permissionmanager/src/main/ets/common/utils/globalContext.ts index 06bcf12..c3c9266 100644 --- a/permissionmanager/src/main/ets/common/utils/globalContext.ts +++ b/permissionmanager/src/main/ets/common/utils/globalContext.ts @@ -20,7 +20,7 @@ export class GlobalContext { bundleName: string; globalState: string; windowNum: number; - dialogSet: Set; + dialogSet: Set; public static getContext(): GlobalContext { if (!GlobalContext.instance) { diff --git a/permissionmanager/src/main/ets/pages/securityDialog.ets b/permissionmanager/src/main/ets/pages/securityDialog.ets index 6b512df..4541de6 100644 --- a/permissionmanager/src/main/ets/pages/securityDialog.ets +++ b/permissionmanager/src/main/ets/pages/securityDialog.ets @@ -260,9 +260,11 @@ struct SecurityDialog { action: () => { this.dialogController?.close(); this.win.destroyWindow(); - let dialogSet: Set = GlobalContext.load('dialogSet'); + let dialogSet: Set = GlobalContext.load('dialogSet'); let callerToken: number = this.want.parameters['ohos.caller.uid']; - dialogSet.delete(callerToken); + let windId: number = this.want.parameters['ohos.ability.params.windowId']; + let token: String = String(callerToken) + '_' + String(windId); + dialogSet.delete(token); GlobalContext.store('dialogSet', dialogSet); if (dialogSet.size === 0) { this.context.terminateSelf(); @@ -282,9 +284,11 @@ struct SecurityDialog { autoCancel: false, cancel: () => { this.win.destroyWindow(); - let dialogSet: Set = GlobalContext.load('dialogSet'); + let dialogSet: Set = GlobalContext.load('dialogSet'); let callerToken: number = this.want.parameters['ohos.caller.uid']; - dialogSet.delete(callerToken); + let windId: number = this.want.parameters['ohos.ability.params.windowId']; + let token: String = String(callerToken) + '_' + String(windId); + dialogSet.delete(token); GlobalContext.store('dialogSet', dialogSet); if (dialogSet.size === 0) { this.context.terminateSelf(); @@ -342,9 +346,11 @@ struct SecurityDialog { onCancel() { Log.info('Callback when the first button is clicked'); this.win.destroyWindow(); - let dialogSet: Set = GlobalContext.load('dialogSet'); + let dialogSet: Set = GlobalContext.load('dialogSet'); let callerToken: number = this.want.parameters['ohos.caller.uid']; - dialogSet.delete(callerToken); + let windId: number = this.want.parameters['ohos.ability.params.windowId']; + let token: String = String(callerToken) + '_' + String(windId); + dialogSet.delete(token); GlobalContext.store('dialogSet', dialogSet); if (dialogSet.size === 0) { this.context.terminateSelf(); @@ -415,9 +421,11 @@ struct SecurityDialog { data.reclaim(); reply.reclaim(); this.win.destroyWindow(); - let dialogSet: Set = GlobalContext.load('dialogSet'); + let dialogSet: Set = GlobalContext.load('dialogSet'); let callerToken: number = this.want.parameters['ohos.caller.uid']; - dialogSet.delete(callerToken); + let windId: number = this.want.parameters['ohos.ability.params.windowId']; + let token: String = String(callerToken) + '_' + String(windId); + dialogSet.delete(token); GlobalContext.store('dialogSet', dialogSet); if (dialogSet.size === 0) { this.context.terminateSelf(); -- Gitee