diff --git a/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts b/permissionmanager/src/main/ets/SecurityExtAbility/SecurityExtAbility.ts index f7d2b587539fa67e2c0a9865e6c0cbbe140adfb9..13c0d0036a2babcb7f2612d6b745d4ec7e840574 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,27 +64,34 @@ 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'); + 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: string = want.parameters['ohos.aafwk.param.callerBundleName']; - console.info(TAG + 'callerToken = ' + callerToken); + let callerToken: number = want.parameters['ohos.caller.uid']; if (dialogSet.has(callerToken)) { console.info(TAG + 'window of ' + callerToken + ' already exists'); return; } 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'); - let callerToken: string = want.parameters['ohos.aafwk.param.callerBundleName']; + let dialogSet: Set = GlobalContext.load('dialogSet'); + let callerToken: number = want.parameters['ohos.caller.uid']; dialogSet.delete(callerToken); console.info(TAG + 'window of ' + callerToken + ' is destroyed'); GlobalContext.store('dialogSet', dialogSet); diff --git a/permissionmanager/src/main/ets/common/utils/globalContext.ts b/permissionmanager/src/main/ets/common/utils/globalContext.ts index edb3b593ba625730e931d18a2810c144582f1118..06bcf12aeba3a7381e1ecca6bfdd71a156059fe5 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 668c03279b626029f01ca9dd29143d5937eb38ca..63b403e096fd89db8440586c2e2af97fb3ee591c 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/utils/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; @@ -63,10 +65,9 @@ struct SecurityDialog { action: () => { this.dialogController?.close(); this.win.destroyWindow(); - let dialogSet: Set = GlobalContext.load('dialogSet'); - let callerToken: string = this.want.parameters['ohos.aafwk.param.callerBundleName']; + let dialogSet: Set = GlobalContext.load('dialogSet'); + let callerToken: number = this.want.parameters['ohos.caller.uid']; dialogSet.delete(callerToken); - Log.info(TAG + 'window of ' + callerToken + ' is destroyed'); GlobalContext.store('dialogSet', dialogSet); if (dialogSet.size === 0) { this.context.terminateSelf(); @@ -86,10 +87,9 @@ struct SecurityDialog { autoCancel: false, cancel: () => { this.win.destroyWindow(); - let dialogSet: Set = GlobalContext.load('dialogSet'); - let callerToken: string = this.want.parameters['ohos.aafwk.param.callerBundleName']; + let dialogSet: Set = GlobalContext.load('dialogSet'); + let callerToken: number = this.want.parameters['ohos.caller.uid']; dialogSet.delete(callerToken); - Log.info(TAG + 'window of ' + callerToken + ' is destroyed'); GlobalContext.store('dialogSet', dialogSet); if (dialogSet.size === 0) { this.context.terminateSelf(); @@ -203,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() { @@ -210,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() { @@ -240,10 +251,9 @@ struct SecurityDialog { data.reclaim(); reply.reclaim(); this.win.destroyWindow(); - let dialogSet: Set = GlobalContext.load('dialogSet'); - let callerToken: string = this.want.parameters['ohos.aafwk.param.callerBundleName']; + let dialogSet: Set = GlobalContext.load('dialogSet'); + let callerToken: number = this.want.parameters['ohos.caller.uid']; dialogSet.delete(callerToken); - Log.info(TAG + 'window of ' + callerToken + ' is destroyed'); GlobalContext.store('dialogSet', dialogSet); if (dialogSet.size === 0) { this.context.terminateSelf(); diff --git a/permissionmanager/src/main/module.json b/permissionmanager/src/main/module.json index c89e9e7bbcd993f96c069f98db1f8e6a58f780ba..3682cfcfbbf92b34db7b550a5a9050e9b3a8a90a 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 6c52a168f59ccc0d27ef4f01e4a6a0535305f281..ee4cfeeb0a219bb3941cbfff60b4e5a269ca06f9 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