mirror of
https://gitee.com/openharmony/applications_permission_manager
synced 2024-11-23 03:09:41 +00:00
commit
46fe51944b
@ -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<void> {
|
||||
console.info(TAG + 'create securityWindow');
|
||||
let dialogSet: Set<number> = 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<number> = GlobalContext.load('dialogSet');
|
||||
|
@ -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() {
|
||||
|
@ -99,6 +99,9 @@
|
||||
{
|
||||
"name": "ohos.permission.GET_BUNDLE_INFO"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_BUNDLE_RESOURCES"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.PERMISSION_USED_STATS"
|
||||
},
|
||||
|
@ -111,6 +111,9 @@
|
||||
{
|
||||
"name": "ohos.permission.GET_BUNDLE_INFO"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_BUNDLE_RESOURCES"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.PERMISSION_USED_STATS"
|
||||
},
|
||||
|
BIN
signature/pm.p7b
BIN
signature/pm.p7b
Binary file not shown.
Loading…
Reference in New Issue
Block a user