From f4306b2e47249b5b22e17447edfbdff375c6473d Mon Sep 17 00:00:00 2001 From: fanchenxuan Date: Sat, 16 Nov 2024 09:02:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E5=BA=94=E7=94=A8=E5=88=86?= =?UTF-8?q?=E8=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fanchenxuan --- .../SecurityExtAbility/SecurityExtAbility.ts | 15 ++++++- .../src/main/ets/pages/securityDialog.ets | 37 ++++++++++++------ permissionmanager/src/main/module.json | 3 ++ permissionmanager/src/main/module.json5 | 3 ++ signature/pm.p7b | Bin 4148 -> 4199 bytes 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts b/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts index e2fa2af..5e174a3 100644 --- a/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts +++ b/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts @@ -17,9 +17,12 @@ import extension from '@ohos.app.ability.ServiceExtensionAbility'; import window from '@ohos.window'; import display from '@ohos.display'; import { GlobalContext } from '../common/utils/globalContext'; +import { preferences } from '@kit.ArkData'; +import { Configuration } from '@ohos.app.ability.Configuration'; const TAG = 'PermissionManager_Log:'; const BG_COLOR = '#00000000'; +let dataPreferences: preferences.Preferences | null = null; export default class SecurityExtensionAbility extends extension { /** @@ -46,6 +49,8 @@ export default class SecurityExtensionAbility extends extension { width: dis.width, height: dis.height }; + let options: preferences.Options = { name: 'myStore' }; + dataPreferences = preferences.getPreferencesSync(this.context, options); this.createWindow('SecurityDialog' + startId, window.WindowType.TYPE_DIALOG, navigationBarRect, want); } catch (exception) { console.error(TAG + 'Failed to obtain the default display object. Code: ' + JSON.stringify(exception)); @@ -59,6 +64,14 @@ export default class SecurityExtensionAbility extends extension { console.info(TAG + 'SecurityExtensionAbility onDestroy.'); } + onConfigurationUpdate(newConfig: Configuration): void { + console.info(TAG + 'onConfigurationUpdate: ' + JSON.stringify(newConfig)); + dataPreferences?.putSync('language', newConfig.language); + dataPreferences?.flush(() => { + console.info(TAG + 'dataPreferences update.'); + }); + } + private async createWindow(name: string, windowType, rect, want): Promise { console.info(TAG + 'create securityWindow'); let dialogSet: Set = GlobalContext.load('dialogSet'); @@ -74,7 +87,7 @@ export default class SecurityExtensionAbility extends extension { } try { const win = await window.createWindow({ ctx: this.context, name, windowType }); - let storage: LocalStorage = new LocalStorage({ 'want': want, 'win': win }); + let storage: LocalStorage = new LocalStorage({ 'want': want, 'win': win, 'dataPreferences': dataPreferences }); await win.bindDialogTarget(want.parameters['ohos.ability.params.token'].value, () => { win.destroyWindow(); let dialogSet: Set = GlobalContext.load('dialogSet'); diff --git a/permissionmanager/src/main/ets/pages/securityDialog.ets b/permissionmanager/src/main/ets/pages/securityDialog.ets index 8d552a6..cbdaa21 100644 --- a/permissionmanager/src/main/ets/pages/securityDialog.ets +++ b/permissionmanager/src/main/ets/pages/securityDialog.ets @@ -26,10 +26,10 @@ import { } from '../common/utils/utils'; import { Param, WantInfo } from '../common/model/typedef'; import { GlobalContext } from '../common/utils/globalContext'; +import { preferences } from '@kit.ArkData'; +import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; let storage = LocalStorage.getShared(); -const TAG = 'PermissionManager_Log:'; -const RESOURCE_TYPE: number = 10003; @Entry(storage) @Component @@ -37,7 +37,9 @@ struct SecurityDialog { private context = getContext(this) as common.ServiceExtensionContext; @LocalStorageLink('want') want: WantInfo = new WantInfo([]); @LocalStorageLink('win') win: window.Window = {} as window.Window; - @State appName: ResourceStr = 'ToBeInstead'; + @LocalStorageLink('dataPreferences') dataPreferences: preferences.Preferences | null = null; + @State appName: ResourceStr = 'Application'; + @State refreshAppName: boolean = false; @State index: number = 0; @State scrollBarWidth: number = Constants.SCROLL_BAR_WIDTH_DEFAULT; @@ -201,6 +203,11 @@ struct SecurityDialog { this.GetAppName(); this.index = this.want.parameters['ohos.user.security.type']; this.dialogController?.open(); + this.dataPreferences?.on('change', (key: string) => { + Log.info('dataPreferences change.'); + this.refreshAppName = true; + this.GetAppName(); + }) } aboutToDisappear() { @@ -208,16 +215,22 @@ struct SecurityDialog { } GetAppName() { - let bundleName: string = this.want.parameters['ohos.aafwk.param.callerBundleName']; - bundleManager.getApplicationInfo(bundleName, bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT) - .then(data => { - data.labelResource.params = []; - data.labelResource.type = RESOURCE_TYPE; - this.appName = data.labelResource; + 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; + }).catch((err: BusinessError) => { + Log.error(`getAppCloneIdentity failed: ${JSON.stringify(err)}`); }) - .catch((error: BusinessError) => { - Log.error('getApplicationInfo failed. err is ' + JSON.stringify(error)); - }); + } catch (err) { + Log.error(`get appName failed: ${JSON.stringify(err)}`); + } } destruction() { diff --git a/permissionmanager/src/main/module.json b/permissionmanager/src/main/module.json index b7dc81a..2a40907 100644 --- a/permissionmanager/src/main/module.json +++ b/permissionmanager/src/main/module.json @@ -99,6 +99,9 @@ { "name": "ohos.permission.GET_BUNDLE_INFO" }, + { + "name": "ohos.permission.GET_BUNDLE_RESOURCES" + }, { "name": "ohos.permission.PERMISSION_USED_STATS" }, diff --git a/permissionmanager/src/main/module.json5 b/permissionmanager/src/main/module.json5 index 7665e0f..c775d04 100644 --- a/permissionmanager/src/main/module.json5 +++ b/permissionmanager/src/main/module.json5 @@ -111,6 +111,9 @@ { "name": "ohos.permission.GET_BUNDLE_INFO" }, + { + "name": "ohos.permission.GET_BUNDLE_RESOURCES" + }, { "name": "ohos.permission.PERMISSION_USED_STATS" }, diff --git a/signature/pm.p7b b/signature/pm.p7b index 9def86a6d54191656b93f02dc687aa7190270f0b..1e133e6cd7baf2eb66d2ffd438660f71888e289a 100644 GIT binary patch delta 277 zcmdm@@La*cph+N^jZ>@5qwPB{BRkWACV>#3PyiDnqam*WHydX{n+IbmGYb==K@$fv zLLuXVCiX8ZP3#{wIvil-jt>a(4D`hjZ>@5qwPB{BRkWACILmDkSr4;qam*WHydX{n+IbmGYb==K@Q8bw^f+ zmXsK9v2g%hc+QrEnTf^Sz?DfMPTjEKm1ke=ERLf52oA@nU27yKRjXY*WD-C1N5%Rs rDJDgR%QvU2U-4ymc~2fk_K^^wW&i5U_ncwPsWP5&#iZlBQ1vDN$wgII