diff --git a/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts b/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts index e2fa2af7164ae4234d72eacdd1d7c2d98148da98..5e174a37b22a3f93a46a89c5086415bc217481bf 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 8d552a632e37eb0d24fceeac752e0dcc6d832a84..cbdaa211154429daa7061073a4c593f549e71da9 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 b7dc81a6a05083cacd1a679224b400c17ef01959..2a40907a50940086aed574533749ec456c8fea39 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 7665e0fe5c1b35ec0c8ab3a563dee160faabd006..c775d042cdb8fe305bd2e7f29786a6e47de96443 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 Binary files a/signature/pm.p7b and b/signature/pm.p7b differ