From 03ce6a0be7a6417671848ea1db78d777fca6cd1b Mon Sep 17 00:00:00 2001 From: fanchenxuan Date: Wed, 27 Nov 2024 15:57:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E8=AF=AD=E8=A8=80=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=9C=89=E6=A6=82=E7=8E=87=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fanchenxuan --- .../SecurityExtAbility/SecurityExtAbility.ts | 9 +++-- .../src/main/ets/pages/securityDialog.ets | 40 ++++++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts b/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts index 5e174a3..298d700 100644 --- a/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts +++ b/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts @@ -20,6 +20,7 @@ import { GlobalContext } from '../common/utils/globalContext'; import { preferences } from '@kit.ArkData'; import { Configuration } from '@ohos.app.ability.Configuration'; +const DELAY = 1000; const TAG = 'PermissionManager_Log:'; const BG_COLOR = '#00000000'; let dataPreferences: preferences.Preferences | null = null; @@ -67,9 +68,11 @@ export default class SecurityExtensionAbility extends extension { onConfigurationUpdate(newConfig: Configuration): void { console.info(TAG + 'onConfigurationUpdate: ' + JSON.stringify(newConfig)); dataPreferences?.putSync('language', newConfig.language); - dataPreferences?.flush(() => { - console.info(TAG + 'dataPreferences update.'); - }); + setTimeout(() => { + dataPreferences?.flush(() => { + console.info(TAG + 'dataPreferences update.'); + }); + }, DELAY); } private async createWindow(name: string, windowType, rect, want): Promise { diff --git a/permissionmanager/src/main/ets/pages/securityDialog.ets b/permissionmanager/src/main/ets/pages/securityDialog.ets index cbdaa21..e3cd5de 100644 --- a/permissionmanager/src/main/ets/pages/securityDialog.ets +++ b/permissionmanager/src/main/ets/pages/securityDialog.ets @@ -30,6 +30,7 @@ import { preferences } from '@kit.ArkData'; import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; let storage = LocalStorage.getShared(); +const RESOURCE_TYPE: number = 10003; @Entry(storage) @Component @@ -39,7 +40,7 @@ struct SecurityDialog { @LocalStorageLink('win') win: window.Window = {} as window.Window; @LocalStorageLink('dataPreferences') dataPreferences: preferences.Preferences | null = null; @State appName: ResourceStr = 'Application'; - @State refreshAppName: boolean = false; + @State appIndex: number = 0; @State index: number = 0; @State scrollBarWidth: number = Constants.SCROLL_BAR_WIDTH_DEFAULT; @@ -205,8 +206,7 @@ struct SecurityDialog { this.dialogController?.open(); this.dataPreferences?.on('change', (key: string) => { Log.info('dataPreferences change.'); - this.refreshAppName = true; - this.GetAppName(); + this.appIndex === 0 ? null : this.GetAppName(); }) } @@ -215,16 +215,12 @@ struct SecurityDialog { } GetAppName() { - let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; let uid: number = this.want.parameters['ohos.caller.uid']; try { bundleManager.getAppCloneIdentity(uid).then(cloneInfo => { Log.info(`getAppCloneIdentity: ${JSON.stringify(cloneInfo)}`); - let resourceInfo = - bundleResourceManager.getBundleResourceInfo(cloneInfo.bundleName, resourceFlag, cloneInfo.appIndex); - this.appName === resourceInfo?.label && this.refreshAppName ? - this.GetAppName() : this.appName = resourceInfo?.label; - this.refreshAppName = false; + this.appIndex = cloneInfo.appIndex; + cloneInfo.appIndex === 0 ? this.getSelfName(cloneInfo) : this.getCloneName(cloneInfo); }).catch((err: BusinessError) => { Log.error(`getAppCloneIdentity failed: ${JSON.stringify(err)}`); }) @@ -233,6 +229,32 @@ struct SecurityDialog { } } + getSelfName(cloneInfo: bundleManager.AppCloneIdentity) { + try { + bundleManager.getApplicationInfo(cloneInfo.bundleName, bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT) + .then(data => { + data.labelResource.params = []; + data.labelResource.type = RESOURCE_TYPE; + this.appName = data.labelResource; + }).catch((error: BusinessError) => { + Log.error('getApplicationInfo failed. err is ' + JSON.stringify(error)); + }); + } catch (err) { + Log.error('getSelfName failed. err is ' + JSON.stringify(err)); + } + } + + getCloneName(cloneInfo: bundleManager.AppCloneIdentity) { + try { + let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; + let resourceInfo = + bundleResourceManager.getBundleResourceInfo(cloneInfo.bundleName, resourceFlag, cloneInfo.appIndex); + this.appName = resourceInfo?.label; + } catch (err) { + Log.error('getCloneName failed. err is ' + JSON.stringify(err)); + } + } + destruction() { let option = new rpc.MessageOption(); let data = new rpc.MessageSequence(); -- Gitee