mirror of
https://gitee.com/openharmony/applications_permission_manager
synced 2024-11-23 11:19:46 +00:00
多ability整合
Signed-off-by: fanchenxuan <fanchenxuan@huawei.com>
This commit is contained in:
parent
0b63d27085
commit
ca5bc0d7a5
@ -25,13 +25,77 @@ export default class MainAbility extends UIAbility {
|
||||
onCreate(want, launchParam): void {
|
||||
console.log(TAG + 'MainAbility onCreate, ability name is ' + want.abilityName + '.');
|
||||
|
||||
globalThis.bundleName = want.parameters.bundleName;
|
||||
GlobalContext.store('bundleName', want.parameters.bundleName);
|
||||
GlobalContext.store('context', this.context);
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage): void {
|
||||
// Main window is created, set main page for this ability
|
||||
console.log(TAG + 'MainAbility onWindowStageCreate.');
|
||||
globalThis.windowStage = windowStage;
|
||||
|
||||
if (globalThis.bundleName) {
|
||||
globalThis.currentApp = globalThis.bundleName;
|
||||
this.getSperifiedApplication(globalThis.bundleName);
|
||||
} else {
|
||||
globalThis.currentApp = 'all';
|
||||
this.getAllApplications();
|
||||
}
|
||||
}
|
||||
|
||||
onNewWant(want): void {
|
||||
console.log(TAG + 'MainAbility onNewWant. want: ' + JSON.stringify(want));
|
||||
console.log(TAG + 'MainAbility onNewWant. bundleName: ' + JSON.stringify(want.parameters.bundleName));
|
||||
|
||||
let bundleName = want.parameters.bundleName ? want.parameters.bundleName : 'all';
|
||||
if (globalThis.currentApp === 'all') {
|
||||
if (globalThis.currentApp !== bundleName) {
|
||||
console.log(TAG + 'MainAbility onNewWant. all -> app');
|
||||
globalThis.windowStage.setUIContent(this.context, 'pages/transition', null);
|
||||
globalThis.currentApp = bundleName;
|
||||
GlobalContext.store('bundleName', bundleName);
|
||||
this.getSperifiedApplication(bundleName);
|
||||
}
|
||||
} else {
|
||||
if (bundleName === 'all') {
|
||||
console.log(TAG + 'MainAbility onNewWant. app -> all');
|
||||
globalThis.windowStage.setUIContent(this.context, 'pages/transition', null);
|
||||
globalThis.currentApp = 'all';
|
||||
this.getAllApplications();
|
||||
} else {
|
||||
if (globalThis.currentApp !== bundleName) {
|
||||
console.log(TAG + 'MainAbility onNewWant. app -> app');
|
||||
globalThis.windowStage.setUIContent(this.context, 'pages/transition', null);
|
||||
globalThis.currentApp = bundleName;
|
||||
GlobalContext.store('bundleName', bundleName);
|
||||
this.getSperifiedApplication(bundleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
// Ability has brought to foreground
|
||||
console.log(TAG + 'MainAbility onForeground.');
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
// Ability has back to background
|
||||
console.log(TAG + 'MainAbility onBackground.');
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
console.log(TAG + 'MainAbility onDestroy.');
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
// Main window is destroyed, release UI related resources
|
||||
console.log(TAG + 'MainAbility onWindowStageDestroy.');
|
||||
}
|
||||
|
||||
getAllApplications(): void {
|
||||
const flag = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
||||
let accountManager = account_osAccount.getAccountManager();
|
||||
try {
|
||||
@ -62,32 +126,43 @@ export default class MainAbility extends UIAbility {
|
||||
initialGroups.push(info);
|
||||
}
|
||||
let storage: LocalStorage = new LocalStorage({ 'initialGroups': initialGroups });
|
||||
windowStage.loadContent('pages/authority-management', storage);
|
||||
globalThis.windowStage.loadContent('pages/authority-management', storage);
|
||||
}).catch((error) => {
|
||||
console.error(TAG + 'bundle.getAllBundleInfo failed. Cause: ' + JSON.stringify(error));
|
||||
})
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(TAG + 'getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
// Ability has brought to foreground
|
||||
console.log(TAG + 'MainAbility onForeground.');
|
||||
}
|
||||
getSperifiedApplication(bundleName): void {
|
||||
const flag = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
||||
bundleManager.getBundleInfo(bundleName, flag).then(bundleInfo => {
|
||||
let reqPermissions: Array<string> = [];
|
||||
bundleInfo.reqPermissionDetails.forEach(item => {
|
||||
reqPermissions.push(item.name);
|
||||
});
|
||||
|
||||
onBackground(): void {
|
||||
// Ability has back to background
|
||||
console.log(TAG + 'MainAbility onBackground.');
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
console.log(TAG + 'MainAbility onDestroy.');
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
// Main window is destroyed, release UI related resources
|
||||
console.log(TAG + 'MainAbility onWindowStageDestroy.');
|
||||
let info = {
|
||||
'bundleName': bundleInfo.name,
|
||||
'api': bundleInfo.targetVersion,
|
||||
'tokenId': bundleInfo.appInfo.accessTokenId,
|
||||
'icon': '',
|
||||
'iconId': bundleInfo.appInfo.iconId,
|
||||
'label': '',
|
||||
'labelId': bundleInfo.appInfo.labelId,
|
||||
'permissions': reqPermissions,
|
||||
'groupId': [],
|
||||
'zhTag': '',
|
||||
'indexTag': '',
|
||||
'language': ''
|
||||
};
|
||||
GlobalContext.store('applicationInfo', info);
|
||||
globalThis.windowStage.setUIContent(this.context, 'pages/application-secondary', null);
|
||||
}).catch(() => {
|
||||
console.log(TAG + 'MainAbility getSperifiedApplication failed.');
|
||||
this.context.terminateSelf();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -1,55 +0,0 @@
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import bundle from '@ohos.bundle.bundleManager';
|
||||
import { GlobalContext } from '../common/utils/globalContext';
|
||||
|
||||
export default class SpecificAbility extends UIAbility {
|
||||
onCreate(want): void {
|
||||
globalThis.bundleName = want.parameters.bundleName;
|
||||
GlobalContext.store('bundleName', want.parameters.bundleName);
|
||||
}
|
||||
|
||||
onDestroy(): void {}
|
||||
|
||||
onWindowStageCreate(windowStage): void {
|
||||
// Main window is created, set main page for this ability
|
||||
|
||||
const flag = bundle.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundle.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
||||
bundle.getBundleInfo(globalThis.bundleName, flag).then(bundleInfo => {
|
||||
let reqPermissions: Array<string> = [];
|
||||
bundleInfo.reqPermissionDetails.forEach(item => {
|
||||
reqPermissions.push(item.name);
|
||||
});
|
||||
|
||||
let info = {
|
||||
'bundleName': bundleInfo.name,
|
||||
'api': bundleInfo.targetVersion,
|
||||
'tokenId': bundleInfo.appInfo.accessTokenId,
|
||||
'icon': '',
|
||||
'iconId': bundleInfo.appInfo.iconId,
|
||||
'label': '',
|
||||
'labelId': bundleInfo.appInfo.labelId,
|
||||
'permissions': reqPermissions,
|
||||
'groupId': [],
|
||||
'zhTag': '',
|
||||
'indexTag': '',
|
||||
'language': ''
|
||||
};
|
||||
GlobalContext.store('applicationInfo', info);
|
||||
windowStage.setUIContent(this.context, 'pages/application-secondary', null);
|
||||
}).catch(() => {
|
||||
this.context.terminateSelf();
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
// Main window is destroyed, release UI related resources
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
// Ability has brought to foreground
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
// Ability has back to background
|
||||
}
|
||||
}
|
@ -171,7 +171,7 @@ struct mediaDocumentItem {
|
||||
console.error(TAG + 'getApplicationInfo error: ' + JSON.stringify(error));
|
||||
})
|
||||
let context = this.context.createModuleContext(this.bundleName, reqPermissionInfo.moduleName);
|
||||
context.resourceManager.getString(reqPermissionInfo.reasonId).then(value => {
|
||||
context.resourceManager.getStringValue(reqPermissionInfo.reasonId).then(value => {
|
||||
if (value !== undefined) {
|
||||
this.reason = value.slice(Constants.START_SUBSCRIPT, Constants.END_SUBSCRIPT);
|
||||
}
|
||||
@ -199,7 +199,7 @@ struct mediaDocumentItem {
|
||||
if (reqPermissionDetail.name == permission) {
|
||||
console.info("reqPermissionDetail: " + JSON.stringify(reqPermissionDetail));
|
||||
let context = this.context.createModuleContext(this.bundleName, reqPermissionDetail.moduleName);
|
||||
context.resourceManager.getString(reqPermissionDetail.reasonId).then(value => {
|
||||
context.resourceManager.getStringValue(reqPermissionDetail.reasonId).then(value => {
|
||||
if (value !== undefined && !hasReason) {
|
||||
this.reason = value.slice(Constants.START_SUBSCRIPT, Constants.END_SUBSCRIPT);
|
||||
reqPermissionInfo = reqPermissionDetail;
|
||||
|
@ -425,7 +425,7 @@ struct PermissionDialog {
|
||||
Log.info("getApplicationName bundleName:" + bundleName);
|
||||
bundleManager.getApplicationInfo(bundleName, bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT).then(applicationInfo => {
|
||||
let context = this.context.createBundleContext(bundleName);
|
||||
context.resourceManager.getString(applicationInfo.labelId, (err, value) => {
|
||||
context.resourceManager.getStringValue(applicationInfo.labelId, (err, value) => {
|
||||
if (value == undefined) {
|
||||
this.appName = titleTrim(applicationInfo.label);
|
||||
} else {
|
||||
@ -449,7 +449,7 @@ struct PermissionDialog {
|
||||
if (reqPermissionDetail.name == permission) {
|
||||
Log.info("reqPermissionDetail: " + JSON.stringify(reqPermissionDetail));
|
||||
let context = this.context.createModuleContext(bundleName, reqPermissionDetail.moduleName);
|
||||
context.resourceManager.getString(reqPermissionDetail.reasonId, (err, value) => {
|
||||
context.resourceManager.getStringValue(reqPermissionDetail.reasonId, (err, value) => {
|
||||
if (value !== undefined && group.reason === '') {
|
||||
group.reason = value.slice(Constants.START_SUBSCRIPT, Constants.END_SUBSCRIPT);
|
||||
this.refresh ++;
|
||||
|
@ -446,10 +446,10 @@ struct permissionRecordPage {
|
||||
}
|
||||
|
||||
getStrings() {
|
||||
this.context.resourceManager.getString($r("app.string.morning").id, (err, val) => {
|
||||
this.context.resourceManager.getStringValue($r("app.string.morning").id, (err, val) => {
|
||||
this.strings.morning = val;
|
||||
})
|
||||
this.context.resourceManager.getString($r("app.string.afternoon").id, (err, val) => {
|
||||
this.context.resourceManager.getStringValue($r("app.string.afternoon").id, (err, val) => {
|
||||
this.strings.afternoon = val;
|
||||
})
|
||||
}
|
||||
|
31
permissionmanager/src/main/ets/pages/transition.ets
Normal file
31
permissionmanager/src/main/ets/pages/transition.ets
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Constants from '../common/utils/constant';
|
||||
const ICON_SIZE = 150;
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Transition {
|
||||
|
||||
build() {
|
||||
Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
|
||||
Image($r('app.media.app_icon'))
|
||||
.width(ICON_SIZE)
|
||||
}
|
||||
.width(Constants.FULL_WIDTH)
|
||||
.height(Constants.FULL_HEIGHT)
|
||||
}
|
||||
}
|
@ -33,18 +33,6 @@
|
||||
"exported": false,
|
||||
"launchType": "singleton",
|
||||
"orientation": "auto_rotation_restricted"
|
||||
},
|
||||
{
|
||||
"name": "com.ohos.permissionmanager.SpecificAbility",
|
||||
"srcEntry": "./ets/SpecificAbility/SpecificAbility.ts",
|
||||
"description": "$string:SpecificAbility_desc",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:SpecificAbility_label",
|
||||
"startWindowIcon": "$media:app_icon",
|
||||
"startWindowBackground": "$color:default_background_color",
|
||||
"exported": false,
|
||||
"launchType": "standard",
|
||||
"orientation": "auto_rotation_restricted"
|
||||
}
|
||||
],
|
||||
"extensionAbilities": [
|
||||
|
@ -10,6 +10,7 @@
|
||||
"pages/permission-access-record",
|
||||
"pages/dialogPlus",
|
||||
"pages/globalSwitch",
|
||||
"pages/securityDialog"
|
||||
"pages/securityDialog",
|
||||
"pages/transition"
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user