From 6e4c380d7001d88004b7845135469aade862cae9 Mon Sep 17 00:00:00 2001 From: fanchenxuan Date: Fri, 9 May 2025 11:17:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=E7=AE=A1=E7=90=86=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fanchenxuan --- .../src/main/ets/MainAbility/MainAbility.ets | 70 +++ .../src/main/ets/MainAbility/MainAbility.ts | 245 -------- .../MainAbility/PermissionManagerModel.ets | 355 +++++++++++ .../GlobalSwitchSheetDialog.ets | 17 +- .../PermissionStateSheetDialog.ets | 77 +-- .../common/components/alphabeticalIndex.ets | 4 +- .../main/ets/common/components/backBar.ets | 16 +- .../main/ets/common/components/location.ets | 8 +- .../src/main/ets/common/components/search.ets | 12 +- .../src/main/ets/common/model/typedef.ets | 86 +-- .../src/main/ets/common/utils/constant.ets | 258 ++------ .../src/main/ets/common/utils/utils.ets | 8 +- .../main/ets/pages/application-secondary.ets | 280 +++------ .../main/ets/pages/application-tertiary.ets | 418 +++++-------- .../main/ets/pages/authority-management.ets | 578 ++++++------------ .../main/ets/pages/authority-secondary.ets | 15 +- .../ets/pages/authority-tertiary-groups.ets | 91 +-- .../src/main/ets/pages/authority-tertiary.ets | 54 +- .../src/main/ets/pages/dialogPlus.ets | 12 +- .../src/main/ets/pages/globalSwitch.ets | 6 +- .../ets/pages/permission-access-record.ets | 142 +++-- permissionmanager/src/main/module.json | 2 +- permissionmanager/src/main/module.json5 | 2 +- 23 files changed, 1164 insertions(+), 1592 deletions(-) create mode 100644 permissionmanager/src/main/ets/MainAbility/MainAbility.ets delete mode 100644 permissionmanager/src/main/ets/MainAbility/MainAbility.ts create mode 100644 permissionmanager/src/main/ets/MainAbility/PermissionManagerModel.ets diff --git a/permissionmanager/src/main/ets/MainAbility/MainAbility.ets b/permissionmanager/src/main/ets/MainAbility/MainAbility.ets new file mode 100644 index 0000000..a23d6fa --- /dev/null +++ b/permissionmanager/src/main/ets/MainAbility/MainAbility.ets @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021-2022 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 UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import { Log } from '../common/utils/utils'; +import { PermissionManagerModel } from './PermissionManagerModel'; + +let bundleName: string; +let windowStageGlobal: window.WindowStage; +let permissionManagerModel: PermissionManagerModel = new PermissionManagerModel(); + +export default class MainAbility extends UIAbility { + onCreate(want: Want): void { + Log.info(`MainAbility onCreate, ability name is ${want.abilityName}.`); + if (!want.parameters) { + return; + } + + if (!permissionManagerModel.permissionCheck()) { + this.context.terminateSelf(); + return; + } + + bundleName = want.parameters.bundleName as string; + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + Log.info('MainAbility onWindowStageCreate.'); + windowStageGlobal = windowStage; + permissionManagerModel.init(this.context, bundleName, windowStage); + permissionManagerModel.register(this.context, bundleName, windowStage); + } + + onNewWant(want: Want): void { + Log.info('MainAbility onNewWant.'); + permissionManagerModel.refresh(want, windowStageGlobal); + } + + onWindowStageDestroy(): void { + permissionManagerModel.unregister(); + Log.info('MainAbility onWindowStageDestroy.'); + } + + onBackground(): void { + Log.info('MainAbility onBackground.'); + } + + onForeground(): void { + Log.info('MainAbility onForeground.'); + } + + onDestroy(): void { + Log.info('MainAbility onDestroy.'); + } + +}; diff --git a/permissionmanager/src/main/ets/MainAbility/MainAbility.ts b/permissionmanager/src/main/ets/MainAbility/MainAbility.ts deleted file mode 100644 index e43948f..0000000 --- a/permissionmanager/src/main/ets/MainAbility/MainAbility.ts +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 UIAbility from '@ohos.app.ability.UIAbility'; -import bundleMonitor from '@ohos.bundle.bundleMonitor'; -import account_osAccount from '@ohos.account.osAccount'; -import { GlobalContext } from '../common/utils/globalContext'; -import { abilityAccessCtrl, bundleManager } from '@kit.AbilityKit'; - -const TAG = 'PermissionManager_Log:'; -const USER_ID = 100; - -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); - } - - onWindowStageCreate(windowStage): void { - // Main window is created, set main page for this ability - console.log(TAG + 'MainAbility onWindowStageCreate.'); - globalThis.windowStage = windowStage; - globalThis.refresh = false; - if (!this.permissionCheck()) { - windowStage.loadContent('pages/transition'); - this.context.terminateSelf(); - return; - } - - if (globalThis.bundleName) { - globalThis.currentApp = globalThis.bundleName; - this.getSperifiedApplication(globalThis.bundleName); - } else { - globalThis.currentApp = 'all'; - this.getAllApplications(); - } - - try { - bundleMonitor.on('add', (bundleChangeInfo) => { - console.log(`${TAG} bundleMonitor.add: ${JSON.stringify(bundleChangeInfo)}`); - if (globalThis.currentApp === 'all') { - this.getAllApplications(); - globalThis.refresh = true; - } - }); - bundleMonitor.on('remove', (bundleChangeInfo) => { - console.log(`${TAG} bundleMonitor.remove: ${JSON.stringify(bundleChangeInfo)}`); - if (globalThis.currentApp === 'all') { - this.getAllApplications(); - globalThis.refresh = true; - } - }); - bundleMonitor.on('update', (bundleChangeInfo) => { - console.log(`${TAG} bundleMonitor.update: ${JSON.stringify(bundleChangeInfo)}`); - if (globalThis.currentApp === 'all') { - this.getAllApplications(); - globalThis.refresh = true; - } - }); - } catch (error) { - console.error(TAG + 'bundleMonitor failed.'); - } - - } - - 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 (globalThis.refresh === true) { - globalThis.windowStage?.setUIContent(this.context, 'pages/transition', null); - this.getAllApplications(); - globalThis.refresh = false; - } - } - } 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); - } - } - } - - } - - onWindowStageDestroy(): void { - try { - bundleMonitor.off('add'); - bundleMonitor.off('remove'); - bundleMonitor.off('update'); - console.log(TAG + 'MainAbility onWindowStageDestroy.'); - } catch (err) { - console.log(`errData is errCode:${err.code} message:${err.message}`); - } - } - - onBackground(): void { - console.log(TAG + ' onBackground.'); - } - - onDestroy(): void { - console.log(TAG + ' onDestroy.'); - } - - onForeground(): void { - console.log(TAG + ' onForeground.'); - } - - private permissionCheck(): boolean { - try { - let flag = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION; - let bundleInfo = bundleManager.getBundleInfoForSelfSync(flag); - let atManager = abilityAccessCtrl.createAtManager(); - let status = - atManager.verifyAccessTokenSync(bundleInfo.appInfo.accessTokenId, 'ohos.permission.GET_INSTALLED_BUNDLE_LIST'); - if (status === abilityAccessCtrl.GrantStatus.PERMISSION_DENIED) { - console.log(TAG + 'permission status is denied.'); - return false; - } - return true; - } catch (err) { - console.error(TAG + 'verifyAccessTokenSync failed.'); - return false; - } - } - - 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 { - accountManager.getActivatedOsAccountLocalIds((err, idArray: number[])=>{ - console.log(TAG + 'getActivatedOsAccountLocalIds err:' + JSON.stringify(err)); - console.log(TAG + 'getActivatedOsAccountLocalIds idArray: ' + JSON.stringify(idArray)); - let userId = idArray[0]; - bundleManager.getAllBundleInfo(flag, userId || USER_ID).then(async(bundleInfos) => { - if (bundleInfos.length <= 0) { - console.info(TAG + 'bundle.getAllBundleInfo result.length less than or equal to zero'); - this.context.terminateSelf(); - return; - } - let initialGroups = []; - for (let i = 0; i < bundleInfos.length; i++) { - let info = bundleInfos[i]; - // Filter blank icon icon and text label resources - try { - await bundleManager.queryAbilityInfo({ - bundleName: info.name, - action: 'action.system.home', - entities: ['entity.system.home'] - }, bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION); - } catch (error) { - console.error( - TAG + 'queryAbilityByWant catch app: ' + JSON.stringify(info.name) + 'err: ' + JSON.stringify(error) - ); - continue; - } - - initialGroups.push(info); - } - let storage: LocalStorage = new LocalStorage({ 'initialGroups': initialGroups }); - globalThis.windowStage?.loadContent('pages/authority-management', storage); - }).catch((error) => { - console.error(TAG + 'bundle.getAllBundleInfo failed. Cause: ' + JSON.stringify(error)); - this.context.terminateSelf(); - }); - }); - } catch (e) { - console.error(TAG + 'getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e)); - this.context.terminateSelf(); - } - } - - getSperifiedApplication(bundleName): void { - const flag = - bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | - bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; - try { - bundleManager.getBundleInfo(bundleName, flag).then(bundleInfo => { - let reqPermissions: Array = []; - 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, - 'iconResource': bundleInfo.appInfo.iconResource, - 'label': '', - 'labelId': bundleInfo.appInfo.labelId, - 'labelResource': bundleInfo.appInfo.labelResource, - 'permissions': reqPermissions, - 'groupId': [], - 'zhTag': '', - 'indexTag': '', - 'language': '' - }; - GlobalContext.store('applicationInfo', info); - globalThis.windowStage?.setUIContent(this.context, 'pages/application-secondary', null); - }).catch((error) => { - console.log(TAG + 'Special branch getBundleInfo failed:' + JSON.stringify(error)); - this.context.terminateSelf(); - }); - } catch (error) { - console.error(TAG + 'Special branch failed: ' + JSON.stringify(error)); - this.context.terminateSelf(); - } - } -}; diff --git a/permissionmanager/src/main/ets/MainAbility/PermissionManagerModel.ets b/permissionmanager/src/main/ets/MainAbility/PermissionManagerModel.ets new file mode 100644 index 0000000..f7edc7e --- /dev/null +++ b/permissionmanager/src/main/ets/MainAbility/PermissionManagerModel.ets @@ -0,0 +1,355 @@ +/* + * Copyright (c) 2025 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 { BaseModel } from '../common/base/BaseModel'; +import { groups } from '../common/model/permissionGroup'; +import { GlobalContext } from '../common/utils/globalContext'; +import { Permission, PermissionGroup } from '../common/model/definition'; +import { ManageAppInfo, AppResource, GroupInfo, PermissionApplications } from '../common/model/typedef'; +import { Log, supportPermission, getPermissionGroup, addLocalTag, getPermissionGroupByName, getGroupIdByPermission } from '../common/utils/utils'; +import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import common from '@ohos.app.ability.common'; +import osAccount from '@ohos.account.osAccount'; +import bundleManager from '@ohos.bundle.bundleManager'; +import bundleMonitor from '@ohos.bundle.bundleMonitor'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; + +export class PermissionManagerModel extends BaseModel { + /** + * 判断是否拥有获取所有应用信息的权限 + * return boolean + */ + public permissionCheck(): boolean { + try { + let flag = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION; + let bundleInfo = bundleManager.getBundleInfoForSelfSync(flag); + let atManager = abilityAccessCtrl.createAtManager(); + let status = + atManager.verifyAccessTokenSync(bundleInfo.appInfo.accessTokenId, 'ohos.permission.GET_INSTALLED_BUNDLE_LIST'); + if (status === abilityAccessCtrl.GrantStatus.PERMISSION_DENIED) { + Log.info('permission status is denied.'); + return false; + } + return true; + } catch (error) { + Log.error(`verifyAccessToken failed, code: ${error.code}, message: ${error.message}.`); + return false; + } + } + + /** + * 初始化页面信息 + * return + */ + public async init(context: common.UIAbilityContext, bundleName: string, windowStage: window.WindowStage): Promise { + let manageAppList: ManageAppInfo[] = []; + let appList: bundleManager.BundleInfo[] = []; + let userId: number = await this.getUserId(); + if (bundleName) { + appList = this.getApplicationInfo(userId, bundleName); + } else { + appList = await this.getAllApplicationInfo(userId); + } + + if (appList.length <= 0) { + Log.error('The number of applications must be less than or equal to 0.'); + context.terminateSelf(); + } + + for (let index = 0; index < appList.length; index++) { + let manageAppInfo = this.initApplicationInfo(appList[index]); + manageAppList.push(manageAppInfo); + } + + if (bundleName) { + GlobalContext.store('applicationInfo', manageAppList[0]); + windowStage.loadContent('pages/application-secondary'); + } else { + this.initPermissionWithApplication(manageAppList); + GlobalContext.store('manageAppList', manageAppList); + windowStage.loadContent('pages/authority-management'); + } + } + + /** + * 刷新页面信息 + * return + */ + public refresh(want: Want, windowStage: window.WindowStage): void { + if (!want.parameters) { + return; + } + let bundleName = want.parameters.bundleName ? want.parameters.bundleName : 'all'; + if (globalThis.currentApp === 'all') { + if (globalThis.currentApp !== bundleName) { + Log.info('MainAbility onNewWant. all -> app'); + windowStage.loadContent(''); + globalThis.currentApp = bundleName; + // this.getSperifiedApplication(bundleName); + } else { + if (globalThis.refresh === true) { + windowStage.loadContent(''); + // this.getAllApplications(); + globalThis.refresh = false; + } + } + } else { + if (bundleName === 'all') { + Log.info('MainAbility onNewWant. app -> all'); + windowStage.loadContent(''); + globalThis.currentApp = 'all'; + // this.getAllApplications(); + } else { + if (globalThis.currentApp !== bundleName) { + Log.info('MainAbility onNewWant. app -> app'); + windowStage.loadContent(''); + globalThis.currentApp = bundleName; + // this.getSperifiedApplication(bundleName); + } + } + } + } + + /** + * 获取当前用户id + * return 用户id + */ + private async getUserId(): Promise { + let userId: number = 0; + try { + const accountManager: osAccount.AccountManager = osAccount.getAccountManager(); + userId = await accountManager.getForegroundOsAccountLocalId(); + } catch (error) { + Log.error(`getForegroundOsAccountLocalId faild, code: ${error.code}, message: ${error.message}.`); + } + return userId; + } + + /** + * 获取单个应用信息 + * return + */ + getApplicationInfo(userId: number, bundleName: string): bundleManager.BundleInfo[] { + const flag = + bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | + bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; + let appList: bundleManager.BundleInfo[] = []; + try { + let bundleInfo = bundleManager.getBundleInfoSync(bundleName, flag, userId); + appList.push(bundleInfo); + } catch (error) { + Log.error(`getApplicationInfo failed, code: ${error.code}, message: ${error.message}.`); + } + return appList; + } + + /** + * 获取所有待展示应用信息 + * return + */ + async getAllApplicationInfo(userId: number): Promise { + const flag = + bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | + bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; + let appList: bundleManager.BundleInfo[] = []; + try { + let bundleInfos = await bundleManager.getAllBundleInfo(flag, userId); + for (let index = 0; index < bundleInfos.length; index++) { + let bundleInfo = bundleInfos[index]; + let want: Want = { + bundleName: bundleInfo.name, + action: 'action.system.home', + entities: ['entity.system.home'] + }; + try { + // Filter blank icon icon and text label resources + bundleManager.queryAbilityInfoSync(want, bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION); + } catch (error) { + Log.error(`queryAbilityByWant failed, app: ${bundleInfo.name}, code: ${error.code}, message: ${error.message}.`); + continue; + } + appList.push(bundleInfo); + } + } catch (error) { + Log.error(`getAllApplicationInfo failed, code: ${error.code}, message: ${error.message}.`); + } + return appList; + } + + /** + * 初始化应用信息 + * return + */ + private initApplicationInfo(info: bundleManager.BundleInfo): ManageAppInfo { + let reqUserPerms: Permission[] = []; + for (let index = 0; index < info.reqPermissionDetails.length; index++) { + let permission = info.reqPermissionDetails[index].name as Permission; + let supportPermissions = supportPermission(); + if (supportPermissions.indexOf(permission) != -1) { + reqUserPerms.push(permission); + } + } + let appResource = this.getAppResource(info.name); + let manageAppInfo: ManageAppInfo = { + bundleName: info.name, + versionName: info.versionName, + tokenId: info.appInfo.accessTokenId, + reqUserPerms, + label: appResource.appName, + icon: appResource.icon, + zhTag: '', + indexTag: '', + language: '', + groupWithPermission: this.getGroupWithPermission(reqUserPerms) + } + addLocalTag(manageAppInfo); + return manageAppInfo; + } + + /** + * 初始化权限组信息 + * return + */ + private initPermissionWithApplication(manageAppList: ManageAppInfo[]): void { + let allUserPermissions: Permission[] = []; + let allGroups: PermissionGroup[] = []; + let allGroupWithPermissions: GroupInfo[] = []; + let allPermissionApplications: PermissionApplications [] = []; + for (let i = 0; i < manageAppList.length; i++) { + manageAppList[i].reqUserPerms.forEach(item => { + if (allUserPermissions.indexOf(item) == -1) { + allUserPermissions.push(item); + } + }) + } + groups.forEach((item) => { + if (item.isShow) { + allGroups.push(item.name); + } + }) + allUserPermissions.forEach((userPermission: Permission) => { + let groupId = getGroupIdByPermission(userPermission); + if (allGroups.indexOf(groups[groupId].name) == -1) { + allGroups.push(groups[groupId].name); + } + }) + for (let i = 0; i < allGroups.length; i++) { + let group = getPermissionGroupByName(allGroups[i]); + allGroupWithPermissions.push(group); + } + for (let i = 0; i < allUserPermissions.length; i++) { + let permission: Permission = allUserPermissions[i]; + let permissionGroup: GroupInfo = getPermissionGroup(permission); + let icon: ResourceStr = permissionGroup.icon; + let bundleNames: string[] = []; + for (let j = 0; j < manageAppList.length; j++) { + if (manageAppList[j].reqUserPerms.indexOf(permission) != -1) { + bundleNames.push(manageAppList[j].bundleName); + } + } + let pa: PermissionApplications = new PermissionApplications(permission, permissionGroup.name, bundleNames, icon); + allPermissionApplications.push(pa); + } + GlobalContext.store('allGroupWithPermissions', allGroupWithPermissions); + GlobalContext.store('allPermissionApplications', allPermissionApplications); + } + + /** + * 获取应用资源 + * @param bundleName 包名 + * return 应用名 + */ + private getAppResource(bundleName: string): AppResource { + let resourceFlag: bundleResourceManager.ResourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; + let appResource: AppResource = { + appName: '', + icon: $r('app.media.icon') + } + try { + let resourceInfo: bundleResourceManager.BundleResourceInfo = + bundleResourceManager.getBundleResourceInfo(bundleName, resourceFlag); + appResource.appName = resourceInfo?.label || ''; + appResource.icon = resourceInfo?.drawableDescriptor?.getPixelMap() || resourceInfo?.icon || $r('app.media.icon'); + } catch (error) { + Log.error(`getBundleResourceInfo faild, code: ${error.code}, message: ${error.message}.`); + appResource.appName = 'Application'; + appResource.icon = $r('app.media.icon'); + } + Log.info(`appName: ${appResource.appName}.`); + return appResource; + } + + /** + * 获取待授权权限及其所属权限组 + * @param reqUserPerms 权限 + * return key:权限组,value:待授权权限 + */ + private getGroupWithPermission(reqUserPerms: Permission[]): Map> { + let groupWithPermission: Map> = new Map(); + for (let index = 0; index < reqUserPerms.length; index++) { + let perm = reqUserPerms[index]; + let groupName = getPermissionGroup(perm).name; + if (!groupName) { + continue; + } + if (!groupWithPermission.has(groupName)) { + groupWithPermission.set(groupName, new Set([perm])); + } else { + groupWithPermission.get(groupName)?.add(perm); + } + } + return groupWithPermission; + } + + /** + * 注册监听应用变化事件 + * return + */ + public register(context: common.UIAbilityContext, bundleName: string, windowStage: window.WindowStage): void { + try { + bundleMonitor.on('add', (bundleChangeInfo) => { + Log.info(`bundleMonitor add.`); + this.init(context, bundleName, windowStage); + }); + bundleMonitor.on('remove', (bundleChangeInfo) => { + Log.info(`bundleMonitor remove.`); + this.init(context, bundleName, windowStage); + }); + bundleMonitor.on('update', (bundleChangeInfo) => { + Log.info(`bundleMonitor update.`); + this.init(context, bundleName, windowStage); + }); + } catch (error) { + Log.error(`register bundleMonitor failed, code: ${error.code}, message: ${error.message}.`); + } + } + + /** + * 注销监听 + * return + */ + public unregister(): void { + try { + bundleMonitor.off('add'); + bundleMonitor.off('remove'); + bundleMonitor.off('update'); + } catch (error) { + Log.error(`unregister bundleMonitor failed, code: ${error.code}, message: ${error.message}.`); + } + } + +} \ No newline at end of file diff --git a/permissionmanager/src/main/ets/PermissionSheet/GlobalSwitchSheetDialog.ets b/permissionmanager/src/main/ets/PermissionSheet/GlobalSwitchSheetDialog.ets index e63cb2d..cda5363 100644 --- a/permissionmanager/src/main/ets/PermissionSheet/GlobalSwitchSheetDialog.ets +++ b/permissionmanager/src/main/ets/PermissionSheet/GlobalSwitchSheetDialog.ets @@ -218,10 +218,10 @@ struct applicationItem { Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Column() { Text(this.currentGroup == 'CAMERA' ? $r('app.string.close_camera') : $r('app.string.close_microphone')) - .fontSize(Constants.TEXT_BIG_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_20) .fontColor($r('sys.color.font_primary')) .fontWeight(FontWeight.Medium) - .lineHeight(Constants.TEXT_BIG_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_28) .width(Constants.FULL_WIDTH) .padding({ top: Constants.PADDING_14, bottom: Constants.PADDING_14 }) Text( @@ -231,7 +231,7 @@ struct applicationItem { ) .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) .fontColor($r('sys.color.font_primary')) - .lineHeight(Constants.TEXT_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_22) } .clip(true) } @@ -310,7 +310,7 @@ struct applicationItem { .fontColor($r('sys.color.font_primary')) .maxLines(Constants.MAXIMUM_HEADER_LINES) .textOverflow({ overflow: TextOverflow.Ellipsis }) - .fontSize(Constants.TEXT_BIG_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_20) .flexGrow(Constants.FLEX_GROW) .fontWeight(FontWeight.Bold) .padding({left: Constants.PADDING_10, top: Constants.PADDING_20}) @@ -354,14 +354,17 @@ struct applicationItem { .width(Constants.DEFAULT_SLIDER_WIDTH).height(Constants.DEFAULT_SLIDER_HEIGHT) .position({ x: this.globalIsOn ? 0 : Constants.OFFSET, y: 0 }) }.clip(true) - }.height(Constants.LISTITEM_ROW_HEIGHT) + } + .height(Constants.HEIGHT_48) .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) - }.padding({ top: Constants.LIST_PADDING_TOP, bottom: Constants.LIST_PADDING_BOTTOM }) + } + .padding({ top: Constants.PADDING_4, bottom: Constants.PADDING_4 }) .backgroundColor($r('sys.color.comp_background_list_card')) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) .margin({ top: Constants.MARGIN_16 }) } - }.padding({ left: Constants.AUTHORITY_LISTITEM_PADDING_LEFT }) + } + .padding({ left: Constants.DEFAULT_PADDING_START }) }.flexGrow(Constants.FLEX_GROW) } } diff --git a/permissionmanager/src/main/ets/PermissionSheet/PermissionStateSheetDialog.ets b/permissionmanager/src/main/ets/PermissionSheet/PermissionStateSheetDialog.ets index 1d8cd4a..d543d80 100644 --- a/permissionmanager/src/main/ets/PermissionSheet/PermissionStateSheetDialog.ets +++ b/permissionmanager/src/main/ets/PermissionSheet/PermissionStateSheetDialog.ets @@ -348,11 +348,11 @@ struct PermissionStateSheetDialog { @CustomDialog struct mediaDocumentItem { private context = this.getUIContext().getHostContext() as common.UIAbilityContext; - private backTitle: ResourceStr = ''; - private bundleName: string = ''; - private permissions: Permission[] = []; - private status: number = 0; - private tokenId: number = 0; + @State backTitle: ResourceStr = ''; + @State bundleName: string = ''; + @State permissions: Permission[] = []; + @State status: number = 0; + @State tokenId: number = 0; private controller: CustomDialogController; @State hidden: boolean = false; @State currentGroup: PermissionGroup = PermissionGroup.OTHER; @@ -681,7 +681,7 @@ struct mediaDocumentItem { .fontColor($r('sys.color.font_primary')) .maxLines(Constants.MAXIMUM_HEADER_LINES) .textOverflow({ overflow: TextOverflow.Ellipsis }) - .fontSize(Constants.TEXT_BIG_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_20) .flexGrow(Constants.FLEX_GROW) .fontWeight(FontWeight.Bold) .padding({ left: Constants.PADDING_24, top: Constants.PADDING_20, bottom: Constants.PADDING_20 }) @@ -694,9 +694,9 @@ struct mediaDocumentItem { Row() { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Image(this.applicationInfo.icon) - .width(Constants.TERTIARY_IMAGE_WIDTH) - .height(Constants.TERTIARY_IMAGE_HEIGHT) - .margin({ left: Constants.TERTIARY_IMAGE_MARGIN_LEFT, right: Constants.TERTIARY_IMAGE_MARGIN_RIGHT }) + .width(Constants.IMAGE_LENGTH_64) + .height(Constants.IMAGE_LENGTH_64) + .margin({ left: Constants.DEFAULT_MARGIN_START, right: Constants.DEFAULT_MARGIN_END }) Column() { Row() { Text(this.label) @@ -707,22 +707,22 @@ struct mediaDocumentItem { .fontWeight(FontWeight.Bold) .textAlign(TextAlign.Start) } - .width(Constants.TERTIARY_HALF_WIDTH) - .margin({ bottom: Constants.TERTIARY_LABEL_MARGIN_BOTTOM }) + .width(Constants.HALF_LENGTH) + .margin({ bottom: Constants.MARGIN_2 }) Row() { Text($r('app.string.version')) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) .textAlign(TextAlign.Start) Text(this.version) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) .textAlign(TextAlign.Start) } - .width(Constants.TERTIARY_HALF_WIDTH) + .width(Constants.HALF_LENGTH) } - }.margin({ left: Constants.TERTIARY_MARGIN_LEFT }) + }.margin({ left: Constants.DEFAULT_MARGIN_START }) } if (this.isRisk) { Row() { @@ -730,9 +730,9 @@ struct mediaDocumentItem { Row() { Image($r('app.media.ic_public_fail')) .fillColor($r('sys.color.icon_secondary')) - .width(Constants.TERTIARY_RADIO_IMAGE_WIDTH) - .height(Constants.TERTIARY_RADIO_IMAGE_HEIGHT) - .margin({ right: Constants.TERTIARY_IMAGE_MARGIN_RIGHT }) + .width(Constants.IMAGE_LENGTH_24) + .height(Constants.IMAGE_LENGTH_24) + .margin({ right: Constants.DEFAULT_MARGIN_END }) Text($r('app.string.risk_warning')) .fontColor($r('sys.color.font_primary')) .fontSize($r('sys.float.ohos_id_text_size_body1')) @@ -749,15 +749,19 @@ struct mediaDocumentItem { Span(this.backTitle) Span($r('app.string.access_permission')) } - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.icon_secondary')) .fontWeight(FontWeight.Medium) .textAlign(TextAlign.Start) - .lineHeight(Constants.SUBTITLE_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_24) }.width(Constants.FULL_WIDTH) - .constraintSize({ minHeight: Constants.SUBTITLE_MIN_HEIGHT }) - .padding({ top: Constants.SUBTITLE_PADDING_TOP, bottom: Constants.SUBTITLE_PADDING_BOTTOM, - left: Constants.TERTIARY_TEXT_MARGIN_LEFT, right: Constants.TERTIARY_IMAGE_MARGIN_RIGHT }) + .constraintSize({ minHeight: Constants.HEIGHT_48 }) + .padding({ + top: Constants.PADDING_16, + bottom: Constants.PADDING_8, + left: Constants.PADDING_24, + right: Constants.DEFAULT_PADDING_END + }) Column() { List() { @@ -776,7 +780,7 @@ struct mediaDocumentItem { .hitTestBehavior(HitTestMode.None) } .width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_ROW_HEIGHT) + .height(Constants.HEIGHT_48) .onClick(async () => { await this.grantFolderPermission(permission) }) @@ -787,7 +791,7 @@ struct mediaDocumentItem { right: $r('sys.float.ohos_id_card_margin_end') }) .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) - .margin({ top: Constants.TERTIARY_LISTITEM_MARGIN_TOP }) + .margin({ top: Constants.MARGIN_1 }) .linearGradient((this.isCheck === permission) ? { angle: 90, direction: GradientDirection.Right, @@ -828,7 +832,7 @@ struct mediaDocumentItem { .width(Constants.SHAPE_DIA) } .width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_ROW_HEIGHT) + .height(Constants.HEIGHT_48) .onClick(async () => { await this.grantOtherPermissions(item); }) @@ -861,13 +865,13 @@ struct mediaDocumentItem { this.isTouch = -1; } }) - .margin({ top: Constants.TERTIARY_LISTITEM_MARGIN_TOP }) + .margin({ top: Constants.MARGIN_1 }) }, (item: MediaDocObj) => JSON.stringify(item)) } } .borderRadius($r('sys.float.ohos_id_corner_radius_card')) .backgroundColor($r('sys.color.comp_background_list_card')) - .padding(Constants.LIST_PADDING_TOP) + .padding(Constants.PADDING_4) .divider({ strokeWidth: Constants.DIVIDER, color: $r('sys.color.comp_divider'), @@ -903,22 +907,23 @@ struct mediaDocumentItem { .padding({ right: 0 }) .enabled(this.selected !== Constants.PERMISSION_BAN) }.width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_ROW_HEIGHT) - }.margin({ top: Constants.LOCATION_MARGIN_TOP, bottom: Constants.LOCATION_MARGIN_BOTTOM }) + .height(Constants.HEIGHT_48) + } + .margin({ top: Constants.DEFAULT_MARGIN_TOP, bottom: Constants.MARGIN_8 }) .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END, - top: Constants.TERTIARY_LIST_PADDING_TOP, - bottom: Constants.TERTIARY_LIST_PADDING_BOTTOM + top: Constants.PADDING_4, + bottom: Constants.PADDING_4 }) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) .backgroundColor($r('sys.color.comp_background_list_card')) Row() { Text($r('app.string.get_the_exact_position')) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .lineHeight(Constants.TEXT_SMALL_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_19) }.width(Constants.FULL_WIDTH) .padding({ left: Constants.DEFAULT_PADDING_START, @@ -927,8 +932,8 @@ struct mediaDocumentItem { } } .padding({ - left: Constants.LIST_PADDING_LEFT, - right: Constants.LIST_PADDING_LEFT + left: Constants.DEFAULT_PADDING_START, + right: Constants.DEFAULT_PADDING_END }) .width(Constants.FULL_WIDTH) .enabled(!this.isRisk && !this.noForeground) diff --git a/permissionmanager/src/main/ets/common/components/alphabeticalIndex.ets b/permissionmanager/src/main/ets/common/components/alphabeticalIndex.ets index d4b7eee..0c16b13 100644 --- a/permissionmanager/src/main/ets/common/components/alphabeticalIndex.ets +++ b/permissionmanager/src/main/ets/common/components/alphabeticalIndex.ets @@ -52,7 +52,7 @@ export struct alphabetIndexerComponent { } }) .height(Constants.FULL_HEIGHT) - .constraintSize({ maxHeight: Constants.ALPHABETINDEXER_HEIGHT }) - .width(Constants.APPLICATION_ALPHABETINDEX_WIDTH) + .constraintSize({ maxHeight: Constants.HEIGHT_448 }) + .width(Constants.WIDTH_24) } } \ No newline at end of file diff --git a/permissionmanager/src/main/ets/common/components/backBar.ets b/permissionmanager/src/main/ets/common/components/backBar.ets index c8991e5..8cb0223 100644 --- a/permissionmanager/src/main/ets/common/components/backBar.ets +++ b/permissionmanager/src/main/ets/common/components/backBar.ets @@ -32,8 +32,8 @@ export struct backBar { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Row() { SymbolGlyph($r('sys.symbol.arrow_left')) - .width(Constants.BACKBAR_IMAGE_WIDTH) - .height(Constants.BACKBAR_IMAGE_HEIGHT) + .width(Constants.IMAGE_LENGTH_24) + .height(Constants.IMAGE_LENGTH_24) .fontSize(Constants.FONT_SIZE_24_vp) .fontColor([$r('sys.color.icon_primary')]) .fontWeight(FontWeight.Medium) @@ -65,7 +65,7 @@ export struct backBar { .fontColor($r('sys.color.font_primary')) .maxLines(Constants.MAXIMUM_HEADER_LINES) .textOverflow({ overflow: TextOverflow.Ellipsis }) - .fontSize(Constants.TEXT_BIG_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_20) .flexGrow(Constants.FLEX_GROW) .fontWeight(FontWeight.Bold) .margin({ left: Constants.MARGIN_4, right: Constants.MARGIN_4 }) @@ -74,8 +74,8 @@ export struct backBar { Image($r('sys.media.ohos_ic_public_more')) .fillColor($r('sys.color.icon_primary')) .objectFit(ImageFit.Contain) - .height(Constants.BACKBAR_IMAGE_WIDTH) - .width(Constants.BACKBAR_IMAGE_HEIGHT) + .height(Constants.IMAGE_LENGTH_24) + .width(Constants.IMAGE_LENGTH_24) .draggable(false) }.width(Constants.CLICK_SHADOW_LENGTH) .height(Constants.CLICK_SHADOW_LENGTH) @@ -100,8 +100,8 @@ export struct backBar { } .margin({ left: Constants.DEFAULT_MARGIN_START, right: Constants.DEFAULT_MARGIN_END }) } - .height(Constants.BACKBAR_HEIGHT) - .constraintSize({ minHeight: Constants.BACKBAR_MINHEIGHT }) + .height(Constants.HEIGHT_56) + .constraintSize({ minHeight: Constants.HEIGHT_56 }) .alignItems(HorizontalAlign.Start) .justifyContent(FlexAlign.Center) .backgroundColor($r('sys.color.background_secondary')) @@ -115,7 +115,7 @@ export struct backBar { .fontWeight(FontWeight.Medium) .fontColor($r('sys.color.font_primary')) }.constraintSize({ minWidth: Constants.MAXIMUM_HEADER_WIDTH }) - .height(Constants.LISTITEM_ROW_HEIGHT) + .height(Constants.HEIGHT_48) .padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') }) .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) .linearGradient((this.isTouch === 'true') ? { diff --git a/permissionmanager/src/main/ets/common/components/location.ets b/permissionmanager/src/main/ets/common/components/location.ets index 257aa17..7773838 100644 --- a/permissionmanager/src/main/ets/common/components/location.ets +++ b/permissionmanager/src/main/ets/common/components/location.ets @@ -21,7 +21,7 @@ import { GrantDialogViewState } from '../../ServiceExtAbility/GrantDialogViewSta .fontWeight(FontWeight.Medium) .fontSize(Constants.TEXT_SMALLER_FONT_SIZE) .height(Constants.LOCATION_BUTTON_HEIGHT) - .borderRadius(Constants.LOCATION_BUTTON_RADIUS) + .borderRadius(Constants.RADIUS_16) } @Component @@ -53,7 +53,7 @@ export struct LocationCanvas { }) Image($r('app.media.ic_public_gps_filled')) .fillColor($r('sys.color.brand')) - .width(Constants.LOCATION_ICON_WIDTH) + .width(Constants.IMAGE_LENGTH_24) .height(Constants.LOCATION_ICON_HEIGHT) .position({ x: Constants.LOCATION_ICON_POSITION_X, y: Constants.LOCATION_ICON_POSITION_Y }) .opacity( @@ -117,10 +117,10 @@ export struct LocationCanvas { .height(Constants.FULL_HEIGHT) .alignItems(VerticalAlign.Top) .justifyContent(FlexAlign.Center) - .padding({ top: Constants.LOCATION_BUTTON_POSITION_Y }) + .padding({ top: Constants.PADDING_16 }) }.width(Constants.FULL_WIDTH) .height(Constants.LOCATION_CANVAS_HEIGHT) - .margin({ top: Constants.LOCATION_CANVAS_MARGIN_TOP, bottom: Constants.LOCATION_CANVAS_MARGIN_BOTTOM }) + .margin({ top: Constants.MARGIN_4, bottom: Constants.MARGIN_8 }) .clip(true) } } diff --git a/permissionmanager/src/main/ets/common/components/search.ets b/permissionmanager/src/main/ets/common/components/search.ets index bb940e9..97f7481 100644 --- a/permissionmanager/src/main/ets/common/components/search.ets +++ b/permissionmanager/src/main/ets/common/components/search.ets @@ -31,10 +31,10 @@ export struct textInput { Flex({ alignContent: FlexAlign.Start }) { TextInput({ placeholder: $r('app.string.textInput_placeholder') }) .backgroundColor($r('sys.color.comp_background_list_card')) - .padding({ left: Constants.TEXTINPUT_PADDING_LEFT }) + .padding({ left: Constants.PADDING_36 }) .type(InputType.Normal) .border({ - width: Constants.TEXTINPUT_BORDER_WIDTH, color: $r('app.color.label_color_20'), radius: Constants.TEXTINPUT_BORDER_RADIUS + width: Constants.BORDER_WIDTH_1_5, color: $r('app.color.label_color_20'), radius: Constants.RADIUS_20 }) .placeholderColor(Color.Grey) .placeholderFont({ @@ -44,7 +44,7 @@ export struct textInput { style: FontStyle.Normal }) .caretColor($r('sys.color.font_secondary')) - .height(Constants.TEXTINPUT_HEIGHT) + .height(Constants.HEIGHT_40) .onChange((value: string) => { if (value === '' || value === null) { this.applicationItem = this.oldApplicationItem; @@ -62,9 +62,9 @@ export struct textInput { Button().defaultFocus(true).opacity(0).position({ x: '-100%' }) Image($r('app.media.ic_public_search_filled')) .objectFit(ImageFit.Contain) - .width(Constants.TEXTINPUT_IMAGE_WIDTH) - .height(Constants.TEXTINPUT_IMAGE_HEIGHT) - .position({ x: Constants.TEXTINPUT_IMAGE_MARGIN_LEFT, y: Constants.TEXTINPUT_IMAGE_MARGIN_TOP }) + .width(Constants.IMAGE_LENGTH_16) + .height(Constants.IMAGE_LENGTH_16) + .position({ x: Constants.DEFAULT_MARGIN_START, y: Constants.DEFAULT_MARGIN_TOP }) } } } diff --git a/permissionmanager/src/main/ets/common/model/typedef.ets b/permissionmanager/src/main/ets/common/model/typedef.ets index a89c375..90a8d57 100644 --- a/permissionmanager/src/main/ets/common/model/typedef.ets +++ b/permissionmanager/src/main/ets/common/model/typedef.ets @@ -82,28 +82,6 @@ export class PermissionApplications { } }; -export class GroupPermission { - public group: PermissionGroup - public permissions: string[] - public groupName: ResourceStr - public icon: ResourceStr - public isShow: boolean - - constructor( - group: PermissionGroup, - permissions: string[], - groupName: ResourceStr, - icon: ResourceStr, - isShow: boolean - ) { - this.group = group - this.permissions = permissions - this.groupName = groupName - this.icon = icon - this.isShow = isShow - } -}; - export class ApplicationObj { public label: string public icon: ResourceStr | PixelMap @@ -164,18 +142,6 @@ export class MediaDocObj { } } -export class PermissionObj { - public groupName: ResourceStr; - public permission: string[]; - public group: string; - - constructor(groupName: ResourceStr, permission: string[], group: string) { - this.groupName = groupName; - this.permission = permission; - this.group = group - } -} - export class StringObj { public morning: string public afternoon: string @@ -233,16 +199,6 @@ export class DialogInfo { public appIndex: number = 0; } -export class OtherPermission { - public permissionLabel: ResourceStr - public permission: string - - constructor(permissionLabel: ResourceStr, permission: string) { - this.permissionLabel = permissionLabel - this.permission = permission - } -} - export class PermissionInfo { public permissionName: Permission public groupName: PermissionGroup @@ -431,22 +387,6 @@ export class RouterParams2 { } } -export class RouterParams3 { - public bundleName: string - public backTitle: ResourceStr - public permission: Permission[] - public status: number - public tokenId: number - - constructor(bundleName: string, backTitle: ResourceStr, permission: Permission[], status: number, tokenId: number) { - this.bundleName = bundleName - this.backTitle = backTitle - this.permission = permission - this.status = status - this.tokenId = tokenId - } -} - export class WantInfo { public parameters: Object[] @@ -531,4 +471,30 @@ export interface PermissionWithOption { export interface optionAndState { operationResult: number; permissionState: abilityAccessCtrl.GrantStatus; +} + +export interface ManageAppInfo { + readonly bundleName: string; + readonly versionName: string; + readonly tokenId: number; + readonly reqUserPerms: Permission[]; + label: string; + icon: ResourceStr | PixelMap; + zhTag: string; + indexTag: string; + language: string; + groupWithPermission: Map>; +} + +export interface AppResource { + appName: string; + icon: ResourceStr | PixelMap; +} + +export interface CurrentGroupStatus { + name: PermissionGroup; + label: ResourceStr; + permissions: Permission[]; + status: number; + folderStatus: boolean[]; } \ No newline at end of file diff --git a/permissionmanager/src/main/ets/common/utils/constant.ets b/permissionmanager/src/main/ets/common/utils/constant.ets index 12592fd..eb713f8 100644 --- a/permissionmanager/src/main/ets/common/utils/constant.ets +++ b/permissionmanager/src/main/ets/common/utils/constant.ets @@ -14,26 +14,6 @@ */ export default class Constants { - // alphabetIndexer - public static ALPHABETINDEXER_HEIGHT = 448; - - // backBar - public static BACKBAR_HEIGHT = 56; - public static BACKBAR_MINHEIGHT = 56; - public static BACKBAR_IMAGE_HEIGHT = 24; - public static BACKBAR_IMAGE_WIDTH = 24; - public static BACKBAR_MARGIN_RIGHT = 4; - - // search textInput - public static TEXTINPUT_PADDING_LEFT = 36; - public static TEXTINPUT_BORDER_RADIUS = 20; - public static TEXTINPUT_BORDER_WIDTH = 1.5; - public static TEXTINPUT_HEIGHT = 40; - public static TEXTINPUT_IMAGE_WIDTH = 16; - public static TEXTINPUT_IMAGE_HEIGHT = 16; - public static TEXTINPUT_IMAGE_MARGIN_LEFT = 12; - public static TEXTINPUT_IMAGE_MARGIN_TOP = 12; - // grid useSizeType public static GUTTER = 0; public static XS_COLUMNS = 2; @@ -56,65 +36,38 @@ export default class Constants { public static DIALOG_LG_SPAN = 4; public static DIALOG_LG_OFFSET = 4; - // 100% width,height + // width,height,padding,margin public static FULL_WIDTH = '100%'; public static FULL_HEIGHT = '100%'; public static HALF_LENGTH = '50%'; - - // public property style - public static PERMISSION = 1; - public static APPLICATION = 0; - public static LAYOUT_WEIGHT = 1; - public static FLEX_GROW = 1; - public static HEADLINE_HEIGHT = 56; - public static TEXT_BIG_FONT_SIZE = 20; - public static TEXT_MIDDLE_FONT_SIZE = 16; - public static TEXT_SMALL_FONT_SIZE = 14; - public static TEXT_SMALLER_FONT_SIZE = 12; - public static FONT_SIZE_12 = '12vp'; - public static FONT_SIZE_18_vp = '18vp'; - public static FONT_SIZE_24_vp = '24vp'; - public static FONT_SIZE_28 = '28vp'; - public static TEXT_LINE_HEIGHT = 22; - public static TEXT_LINE_HEIGHT_24 = 24; - public static TEXT_LINE_HEIGHT_27 = 27; - public static TEXT_BIG_LINE_HEIGHT = 28; - public static TEXT_SMALL_LINE_HEIGHT = 19; - public static CONSTRAINTSIZE_MINHEIGHT = 48; - public static LISTITEM_ROW_HEIGHT = 48; - public static LISTITEM_PADDING_LEFT = 24; - public static LIST_PADDING_LEFT = 12 - public static LISTITEM_PADDING_RIGHT = 24; - public static LISTITEM_PADDING_RIGHT_RECORD = 50; - public static LISTITEM_MARGIN_BOTTOM = 12; - public static LISTITEM_HEIGHT_PERMISSION = 64; - public static LISTITEM_HEIGHT_APPLICATION = 72; - public static IMAGE_LENGTH_20 = 20; - public static IMAGE_HEIGHT = 24; - public static IMAGE_WIDTH = 12; - public static IMAGE_HEIGHT_RECORD = 12; - public static IMAGE_WIDTH_RECORD = 24; - public static IMAGE_HEIGHT_RECORD_APPLICATION = 16; - public static IMAGE_WIDTH_RECORD_APPLICATION = 16; - public static IMAGE_POSITION_28 = 28; - public static BORDER_WIDTH_1 = '1px'; - public static TITLE_MARGIN_BOTTOM = 16; - public static SUBTITLE_MIN_HEIGHT = 48; - public static SUBTITLE_LINE_HEIGHT = 24; - public static SUBTITLE_PADDING_TOP = 16; - public static SUBTITLE_PADDING_BOTTOM = 8; - public static TAB_HEIGHT = 56; - public static TAB_LINE_HEIGHT = 100; - public static TAB_INNER_PADDING = 8; - public static TAB_DECORATION_HEIGHT = 2; - public static TAB_DECORATION_POSITION_Y = 6; - public static RADIUS_5 = 5; + public static RECORD_PADDING_BOTTOM = '20%'; + public static WIDTH_24 = 24; + public static WIDTH_36 = 36; + public static WIDTH_100 = 100; + public static WIDTH_250 = 250; + public static HEIGHT_2 = 2; + public static HEIGHT_20 = 20; + public static HEIGHT_40 = 40; + public static HEIGHT_48 = 48; + public static HEIGHT_56 = 56; + public static HEIGHT_64 = 64; + public static HEIGHT_72 = 72; + public static HEIGHT_448 = 448; + public static MARGIN_1 = 1; + public static MARGIN_2 = 2; public static MARGIN_4 = 4; public static MARGIN_8 = 8; + public static MARGIN_9 = 9; public static MARGIN_12 = 12; public static MARGIN_16 = 16; public static MARGIN_24 = 24; public static MARGIN_26 = 26; + public static MARGIN_40 = 40; + public static MARGIN_50 = 50; + public static MARGIN_52 = 52; + public static MARGIN_68 = 68; + public static MARGIN_96 = 96; + public static MARGIN_176 = 176; public static PADDING_4 = 4; public static PADDING_8 = 8; public static PADDING_10 = 10; @@ -122,6 +75,8 @@ export default class Constants { public static PADDING_16 = 16; public static PADDING_20 = 20; public static PADDING_24 = 24; + public static PADDING_36 = 36; + public static PADDING_50 = 50; public static DEFAULT_PADDING_START = 12; public static DEFAULT_PADDING_END = 12; public static DEFAULT_PADDING_TOP = 12; @@ -130,98 +85,59 @@ export default class Constants { public static DEFAULT_MARGIN_END = 12; public static DEFAULT_MARGIN_TOP = 12; public static DEFAULT_MARGIN_BOTTOM = 12; + + // public property style + public static PERMISSION = 1; + public static APPLICATION = 0; + public static LAYOUT_WEIGHT = 1; + public static FLEX_GROW = 1; + public static HEADLINE_HEIGHT = 56; + public static TEXT_MIDDLE_FONT_SIZE = 16; + public static TEXT_SMALLER_FONT_SIZE = 12; + public static FONT_SIZE_10 = 10; + public static FONT_SIZE_12 = '12vp'; + public static FONT_SIZE_14 = 14; + public static FONT_SIZE_18_vp = '18vp'; + public static FONT_SIZE_20 = 20; + public static FONT_SIZE_24_vp = '24vp'; + public static FONT_SIZE_28 = '28vp'; + public static LINE_HEIGHT_14 = 14; + public static LINE_HEIGHT_19 = 19; + public static LINE_HEIGHT_22 = 22; + public static LINE_HEIGHT_24 = 24; + public static LINE_HEIGHT_28 = 28; + public static LINE_HEIGHT_100 = 100; + public static IMAGE_LENGTH_12 = 12; + public static IMAGE_LENGTH_16 = 16; + public static IMAGE_LENGTH_20 = 20; + public static IMAGE_LENGTH_24 = 24; + public static IMAGE_LENGTH_40 = 40; + public static IMAGE_LENGTH_64 = 64; + public static IMAGE_LENGTH_120 = 120; + public static IMAGE_LENGTH_200 = 200; + public static IMAGE_POSITION_28 = 28; + public static BORDER_WIDTH_1 = '1px'; + public static BORDER_WIDTH_1_5 = 1.5; + public static TAB_DECORATION_POSITION_Y = 6; + public static RADIUS_5 = 5; + public static RADIUS_16 = 16; + public static RADIUS_20 = 20; public static DEFAULT_SLIDER_WIDTH = 60; public static DEFAULT_SLIDER_HEIGHT = 40; public static OFFSET = 100; + public static SHAPE_DIA = 20; public static CLICK_SHADOW_LENGTH = 48; public static SCROLL_BAR_WIDTH_DEFAULT = 4; public static SCROLL_BAR_WIDTH_ACTIVE = 8; public static DIVIDER = '1px'; public static DIALOG_DIVIDER = '2px'; public static DIVIDER_HEIGHT = 24; - public static DIVIDER_MARGIN_RIGHT_PERMISSION = 52; - public static DIVIDER_MARGIN_RIGHT_APPLICATION = 68; public static DIALOG_TITLE_MAX_SCALE = 2; public static DIALOG_TEXT_MAX_SCALE = 3.2; public static DIALOG_BUTTON_MAX_WIDTH = 135; - - // application-secondary, authority-secondary - public static FLEX_MARGIN_TOP = 8; - public static FLEX_MARGIN_BOTTOM = 8; - public static LIST_PADDING_TOP = 4; - public static LIST_PADDING_BOTTOM = 4; - public static LIST_MARGIN_BOTTOM = 12; - public static ROW_MARGIN_TOP = 9; - public static SECONDARY_TEXT_MARGIN_LEFT = 24; - public static SECONDARY_LIST_PADDING_LEFT = 12; - public static SECONDARY_LIST_PADDING_RIGHT = 12; - - // application-tertiary - public static TERTIARY_IMAGE_WIDTH = 64; - public static TERTIARY_IMAGE_HEIGHT = 64; - public static TERTIARY_IMAGE_MARGIN_LEFT = 12; - public static TERTIARY_IMAGE_MARGIN_RIGHT = 12; - public static TERTIARY_LABEL_MARGIN_BOTTOM = 2; - public static TERTIARY_MARGIN_LEFT = 12; - public static TERTIARY_TEXT_MARGIN_LEFT = 24; - public static TERTIARY_HALF_WIDTH = '50%'; - public static TERTIARY_ROW_MARGIN_TOP = 24; - public static TERTIARY_RADIO_IMAGE_WIDTH = 24; - public static TERTIARY_RADIO_IMAGE_HEIGHT = 24; - public static TERTIARY_LISTITEM_MARGIN_TOP = 1; - public static TERTIARY_LIST_PADDING_TOP = 4; - public static TERTIARY_LIST_PADDING_BOTTOM = 4; - public static LOCATION_MARGIN_TOP = 12; - public static LOCATION_MARGIN_BOTTOM = 8; - - // authority-tertiary - public static AUTHORITY_IMAGE_WIDTH = 40; - public static AUTHORITY_IMAGE_HEIGHT = 40; - public static AUTHORITY_IMAGE_MARGIN_RIGHT = 16; - public static AUTHORITY_TOGGLE_WIDTH = 36; - public static AUTHORITY_TOGGLE_HEIGHT = 20; - public static AUTHORITY_ROW_HEIGHT = 72; - public static AUTHORITY_CONSTRAINTSIZE_MINHEIGHT = 72; - public static AUTHORITY_LISTITEM_PADDING_LEFT = 12; - public static AUTHORITY_LISTITEM_PADDING_RIGHT = 12; - public static AUTHORITY_TEXTINPUT_PADDING_LEFT = 12; - public static AUTHORITY_TEXTINPUT_PADDING_RIGHT = 24; - public static AUTHORITY_TEXT_MARGIN_TOP = 24; - public static AUTHORITY_ROW_MARGIN_BOTTOM = 24; - public static AUTHORITY_LIST_MARGIN_BOTTOM = 96; - public static AUTHORITY_LIST_MARGIN_BOTTOM_GLOBAL = 176; - public static NORECORD_IMAGE_WIDTH = 120; - public static NORECORD_IMAGE_HEIGHT = 120; - public static NORECORD_IMAGE_MARGIN_LEFT = 40; - public static SEARCHNORESULT_IMAGE_WIDTH = 200; - public static SEARCHNORESULT_IMAGE_HEIGHT = 200; - public static AUTHORITY_ALPHABETINDEX_WIDTH = 24; - public static AUTHORITY_ALPHABETINDEX_PADDING_TOP = 16; - - // authority-management - public static MANAGEMENT_IMAGE_WIDTH = 24; - public static MANAGEMENT_IMAGE_HEIGHT = 24; - public static MANAGEMENT_IMAGE_MARGIN_RIGHT = 16; - public static MANAGEMENT_IMAGE_MARGIN_RIGHT_RECORD = 24; - public static MANAGEMENT_IMAGE_MARGIN_LEFT = 8; - public static MANAGEMENT_ROW_HEIGHT = 56; - public static MANAGEMENT_ROW_PADDING_LEFT = 12; - public static MANAGEMENT_ROW_PADDING_RIGHT = 12; - public static MANAGEMENT_ROW_PADDING_TOP = 8; - public static MANAGEMENT_ROW_PADDING_BOTTOM = 50; - public static MANAGEMENT_ROW_MARGIN_TOP = 12; - public static APPLICATION_IMAGE_WIDTH = 40; - public static APPLICATION_IMAGE_HEIGHT = 40; - public static APPLICATION_IMAGE_MARGIN_RIGHT = 16; - public static APPLICATION_TEXT_MARGIN_RIGHT = 4; - public static APPLICATION_LIST_MARGIN_BOTTOM = 40; - public static APPLICATION_TEXTINPUT_PADDING_LEFT = 12; - public static APPLICATION_TEXTINPUT_PADDING_TOP = 8; - public static APPLICATION_TEXTINPUT_PADDING_RIGHT = 24; - public static APPLICATION_ALPHABETINDEX_MARGIN_TOP = 12; - public static APPLICATION_ALPHABETINDEX_WIDTH = 24; - public static LOADING_WIDTH = 100; - public static BAR_WIDTH = 250; + public static SECURITY_ICON_WIDTH = 48; + public static SECURITY_ICON_HEIGHT = 48; + public static SECURITY_HEADER_MAX_LINES = 2; //group number public static FIXED_GROUP = 1; @@ -235,12 +151,6 @@ export default class Constants { public static PERMISSION_ONLY_THIS_TIME = 2; public static PERMISSION_ALLOWED_ONLY_DURING_USE = 3; - //shape - public static SHAPE_DIA = 20; - - public static PERMISSION_INDEX = 0; - public static PERMISSION_NUM = 0; - // permission flag public static PERMISSION_DEFAULT = 0; public static PERMISSION_FLAG = 2; @@ -256,34 +166,6 @@ export default class Constants { public static MAXIMUM_HEADER_HEIGHT = 500 public static MAXIMUM_HEADER_LENGTH = 1000 - public static RECORD_PADDING_BOTTOM = '20%' - - //////////////security_dialog/////////////// - - // icon - public static SECURITY_ICON_WIDTH = 48; - public static SECURITY_ICON_HEIGHT = 48; - public static PADDING_TWICE = 2; - - // header - public static SECURITY_HEADER_MAX_LINES = 2; - public static SECURITY_HEADER_MAX_SCALE = 2; - - //////////////////////////////////////////// - - // icon of dialog - public static DIALOG_ICON_WIDTH = 24; - public static DIALOG_ICON_HEIGHT = 24; - public static DIALOG_ICON_MARGIN_TOP = 23; - - // label text of dialog - public static DIALOG_LABEL_FONT_SIZE = 10; - public static DIALOG_LABEL_MARGIN_TOP = 2; - public static DIALOG_LABEL_LINE_HEIGHT = 14; - - // request text of dialog - public static DIALOG_REQ_MARGIN_TOP = 16; - public static RESULT_SUCCESS = 1 public static RESULT_FAILURE = 0 public static RESULT_CODE = 0 @@ -298,18 +180,13 @@ export default class Constants { //location canvas public static LOCATION_CANVAS_HEIGHT = 172; - public static LOCATION_CANVAS_MARGIN_TOP = 4; - public static LOCATION_CANVAS_MARGIN_BOTTOM = 8; public static LOCATION_CANVAS_INITIAL_SCALE = 1; public static LOCATION_CANVAS_ZOOM_SCALE = 1.3; public static LOCATION_BUTTON_HEIGHT = 32; - public static LOCATION_BUTTON_RADIUS = 16; - public static LOCATION_BUTTON_POSITION_Y = 16; public static LOCATION_ICON_POSITION_X = 228; public static LOCATION_ICON_POSITION_Y = 86.5; public static LOCATION_CIRCLE_POSITION_X = 194; public static LOCATION_CIRCLE_POSITION_Y = 62.5; - public static LOCATION_ICON_WIDTH = 24; public static LOCATION_ICON_HEIGHT = 29; public static LOCATION_CIRCLE_DIA = 94; public static LOCATION_CIRCLE_OPACITY = 0.3; @@ -321,9 +198,6 @@ export default class Constants { public static DYNAMIC_OPER = 1 public static INVALID_OPER = 2 - //global dialog - public static ROW_HEIGHT = 56 - public static ACCESS_TOKEN = 'ohos.security.accesstoken.tokencallback' public static SEC_COMP_DIALOG_CALLBACK = 'ohos.security.ISecCompDialogCallback' diff --git a/permissionmanager/src/main/ets/common/utils/utils.ets b/permissionmanager/src/main/ets/common/utils/utils.ets index b046b89..d2cbe71 100644 --- a/permissionmanager/src/main/ets/common/utils/utils.ets +++ b/permissionmanager/src/main/ets/common/utils/utils.ets @@ -26,7 +26,7 @@ import { Permission, PermissionGroup } from '../model/definition'; import Constants from '../utils/constant'; import { BundleInfoUtils } from './bundleInfoUtils'; import { CommonUtils } from './commonUtils'; -import { GroupInfo, AppInfo, ApplicationObj } from '../model/typedef'; +import { GroupInfo, AppInfo, ApplicationObj, ManageAppInfo } from '../model/typedef'; import systemParameterEnhance from '@ohos.systemParameterEnhance'; import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; import uiExtensionHost from '@ohos.uiExtensionHost'; @@ -109,7 +109,7 @@ export const indexValue: string[] = [ 'Z' ]; // Array of alphabetically indexed names -export function addLocalTag(info: AppInfo) { +export function addLocalTag(info: AppInfo | ManageAppInfo) { let isZh = i18n.System.getSystemLanguage().indexOf('zh') >= 0; let appName: string = info.label; let upperCase = CommonUtils.isEmpty(appName) ? '' : appName[0].toLocaleUpperCase(); @@ -146,8 +146,8 @@ export function addLocalTag(info: AppInfo) { let enComparator = new Intl.Collator('en'); let zhComparator = new Intl.Collator('zh-Hans-CN'); -export function sortByName(appArray: Array): Array { - return appArray.sort((item1: AppInfo | ApplicationObj, item2: AppInfo | ApplicationObj) => { +export function sortByName(appArray: Array): Array { + return appArray.sort((item1: AppInfo | ApplicationObj | ManageAppInfo, item2: AppInfo | ApplicationObj | ManageAppInfo) => { if (item1.indexTag !== item2.indexTag) { return enComparator.compare(item1.indexTag, item2.indexTag); } diff --git a/permissionmanager/src/main/ets/pages/application-secondary.ets b/permissionmanager/src/main/ets/pages/application-secondary.ets index a3250b1..7d22fe8 100644 --- a/permissionmanager/src/main/ets/pages/application-secondary.ets +++ b/permissionmanager/src/main/ets/pages/application-secondary.ets @@ -13,70 +13,54 @@ * limitations under the License. */ -import { backBar } from '../common/components/backBar'; -import common from '@ohos.app.ability.common'; -import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; -import bundleManager from '@ohos.bundle.bundleManager'; -import { BusinessError } from '@ohos.base'; -import { groups } from '../common/model/permissionGroup'; import Constants from '../common/utils/constant'; -import { Log, verifyAccessToken, getGroupIdByPermission, supportPermission } from '../common/utils/utils'; -import { PermissionObj, AppInfo } from '../common/model/typedef'; -import { GlobalContext } from '../common/utils/globalContext'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import { backBar } from '../common/components/backBar'; import { Permission } from '../common/model/definition'; +import { GlobalContext } from '../common/utils/globalContext'; +import { ManageAppInfo, CurrentGroupStatus } from '../common/model/typedef'; +import { Log, verifyAccessToken, getPermissionGroupByName } from '../common/utils/utils'; @Entry @Component struct appNamePlusPage { - private context = this.getUIContext().getHostContext() as common.UIAbilityContext; - @State allowedListItem: PermissionObj[] = []; // Array of allowed permissions - @State bannedListItem: PermissionObj[] = []; // array of forbidden permissions - @State applicationInfo: AppInfo = GlobalContext.load('applicationInfo'); // Routing jump data - @State bundleName: string = GlobalContext.load('bundleName'); - @State label: string = ''; + @State applicationInfo: ManageAppInfo = GlobalContext.load('applicationInfo'); + @State allowedListItem: CurrentGroupStatus[] = []; + @State bannedListItem: CurrentGroupStatus[] = []; @State isTouch: string = ''; @State isGranted: number = Constants.PERMISSION_ALLOW; @State folderStatus: boolean[] = [false, false, false]; - @State reqUserPermissions: Permission[] = []; - @Builder ListItemLayout(item: PermissionObj, status: number) { + @Builder ListItemLayout(item: CurrentGroupStatus) { ListItem() { Row() { Column() { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Row() { - Text(item.groupName) + Text(item.label) .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) .fontColor($r('sys.color.font_primary')) .fontWeight(FontWeight.Medium) .flexGrow(Constants.FLEX_GROW) SymbolGlyph($r('sys.symbol.chevron_forward')) - .width(Constants.IMAGE_WIDTH) - .height(Constants.IMAGE_HEIGHT) + .width(Constants.IMAGE_LENGTH_12) + .height(Constants.IMAGE_LENGTH_24) .fontSize(Constants.FONT_SIZE_18_vp) .fontColor([$r('sys.color.icon_tertiary')]) .fontWeight(FontWeight.Medium) } .width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_ROW_HEIGHT) + .height(Constants.HEIGHT_48) } }.onClick(() => { - GlobalContext.store('currentPermissionGroup', item.group); - this.getUIContext().getRouter().pushUrl({ - url: 'pages/application-tertiary', - params: { - bundleName: this.applicationInfo.bundleName, - backTitle: item.groupName, - permission: item.permission, - status, - tokenId: this.applicationInfo.tokenId - } - }); + GlobalContext.store('currentGroupStatus', item); + this.getUIContext().getRouter().pushUrl({ url: 'pages/application-tertiary' }); }) } - }.padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') }) + } + .padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') }) .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) - .linearGradient((this.isTouch === item.group) ? { + .linearGradient((this.isTouch === item.name) ? { angle: 90, direction: GradientDirection.Right, colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]] @@ -90,7 +74,7 @@ struct appNamePlusPage { return; } if (event.type === TouchType.Down) { - this.isTouch = item.group; + this.isTouch = item.name; } if (event.type === TouchType.Up) { this.isTouch = ''; @@ -98,112 +82,39 @@ struct appNamePlusPage { }) } - async getReqUserPermissions(info: AppInfo) { - let acManager = abilityAccessCtrl.createAtManager(); - if (info.permissions.length > 0) { - for (let j = 0; j < info.permissions.length; j++) { - let permission = info.permissions[j] as Permission; - let supportPermissions = supportPermission(); - if (supportPermissions.indexOf(permission) == -1) { - continue; - } - try { - let flag = await acManager.getPermissionFlags(info.tokenId, permission); - if (flag == Constants.PERMISSION_SYSTEM_FIXED) { - continue; - } - } catch (err) { - Log.error('getPermissionFlags error: ' + JSON.stringify(err)); - } - this.reqUserPermissions.push(permission); - } - } - } - - async initApplicationInfo(info: AppInfo) { - Log.info(`labelResource: ` + JSON.stringify(info.labelResource)); - let resourceManager = this.context.createBundleContext(info.bundleName).resourceManager; - - if (info.labelResource.id !== 0) { - info.label = await this.context.resourceManager.getStringValue(info.labelResource); - } else { - info.label = await resourceManager.getStringValue(info.labelId); - } - - try { - if (info.iconResource.id !== 0) { - let iconDescriptor = this.context.resourceManager.getDrawableDescriptor(info.iconResource); - info.icon = iconDescriptor?.getPixelMap(); - } else { - let iconDescriptor = resourceManager.getDrawableDescriptor(info.iconId); - info.icon = iconDescriptor?.getPixelMap(); - } - } catch (error) { - Log.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); - } - - if (!info.icon) { - info.icon = $r('app.media.icon'); - } - - this.reqUserPermissions = []; - await this.getReqUserPermissions(info); - let groupIds: number[] = []; - for (let i = 0; i < this.reqUserPermissions.length; i++) { - let groupId = getGroupIdByPermission(this.reqUserPermissions[i]) - if (groupIds.indexOf(groupId) == -1) { - groupIds.push(groupId); - } - } - info.permissions = this.reqUserPermissions; - info.groupId = groupIds; - } - - /** - * Initialize permission status information and group permission information - */ async initialPermissions() { - if (this.bundleName && !this.applicationInfo.groupId.length) { - await this.initApplicationInfo(this.applicationInfo); - } - let reqPermissions = this.applicationInfo.permissions; - let reqGroupIds = this.applicationInfo.groupId; - this.allowedListItem = []; this.bannedListItem = []; - for (let i = 0; i < reqGroupIds.length; i++) { - let id = reqGroupIds[i]; - let groupName = groups[id].groupName; - let group = groups[id].name; - let groupReqPermissions: Permissions[] = []; - for (let j = 0; j < reqPermissions.length; j++) { - let permission = reqPermissions[j]; - if (groups[id].permissions.indexOf(permission) != -1) { - groupReqPermissions.push(permission); - } - } - this.isGranted = group === 'LOCATION' ? Constants.PERMISSION_BAN : Constants.PERMISSION_ALLOW; + this.applicationInfo.groupWithPermission.forEach(async (permissions, permissionGroup) => { + let groupName = getPermissionGroupByName(permissionGroup).groupName; + let groupReqPermissions: Permission[] = Array.from(permissions); + this.isGranted = permissionGroup === 'LOCATION' ? Constants.PERMISSION_BAN : Constants.PERMISSION_ALLOW; this.folderStatus = [false, false, false]; - await this.getStatus(groupReqPermissions, group); + await this.getStatus(groupReqPermissions, permissionGroup); + let currentGroupStatus: CurrentGroupStatus = { + name: permissionGroup, + label: groupName, + permissions: groupReqPermissions, + status: this.isGranted, + folderStatus: this.folderStatus + } if ( this.isGranted === Constants.PERMISSION_ALLOW || this.isGranted === Constants.PERMISSION_ALLOWED_ONLY_DURING_USE ) { - this.allowedListItem.push(new PermissionObj(groupName, groupReqPermissions, group)); + this.allowedListItem.push(currentGroupStatus); } else { - if (group === 'FOLDER' && this.folderStatus.includes(true)) { - this.allowedListItem.push(new PermissionObj(groupName, groupReqPermissions, group)); + if (permissionGroup === 'FOLDER' && this.folderStatus.includes(true)) { + this.allowedListItem.push(currentGroupStatus); } else { - this.bannedListItem.push(new PermissionObj(groupName, groupReqPermissions, group)); + this.bannedListItem.push(currentGroupStatus); } } - - GlobalContext.store('folderStatus', this.folderStatus); - } + }) } - async getStatus(groupReqPermissions: Permissions[], group: string) { + async getStatus(groupReqPermissions: Permission[], group: string) { if (group === 'LOCATION') { try { let acManager = abilityAccessCtrl.createAtManager(); @@ -224,7 +135,6 @@ struct appNamePlusPage { } catch (err) { Log.error('change location status error: ' + JSON.stringify(err)); } - GlobalContext.store('locationStatus', this.isGranted); return true; } for (let i = 0; i < groupReqPermissions.length; i++) { @@ -250,25 +160,8 @@ struct appNamePlusPage { return true; } - /** - * Lifecycle function, triggered once when this page is displayed - */ onPageShow() { this.initialPermissions(); - bundleManager.getApplicationInfo( - this.applicationInfo.bundleName, bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT - ).then(appInfo => { - let bundleContext = this.context.createBundleContext(this.applicationInfo.bundleName); - bundleContext.resourceManager.getStringValue(appInfo.labelId, (error, value) => { - if (value) { - this.applicationInfo.label = value; - GlobalContext.store('applicationInfo', this.applicationInfo); - this.label = value - } - }) - }).catch((error: BusinessError) => { - Log.error('getApplicationInfo error: ' + JSON.stringify(error)); - }) } build() { @@ -282,7 +175,7 @@ struct appNamePlusPage { Row() { Column() { Row() { - backBar({ title: JSON.stringify(this.label || this.applicationInfo.label), recordable: false }) + backBar({ title: JSON.stringify(this.applicationInfo.label), recordable: false }) } Row() { Column() { @@ -291,35 +184,22 @@ struct appNamePlusPage { List() { ListItem() { Row() { - Column() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Row() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Text($r('app.string.no_permission')) - .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) - .fontColor($r('sys.color.font_primary')) - }.margin({ top: Constants.FLEX_MARGIN_TOP, bottom: Constants.FLEX_MARGIN_BOTTOM }) - }.height(Constants.FULL_HEIGHT) - }.flexGrow(Constants.FLEX_GROW) - .constraintSize({minHeight: Constants.CONSTRAINTSIZE_MINHEIGHT }) - } - .width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_ROW_HEIGHT) - } - } + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { + Text($r('app.string.no_permission')) + .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) + .fontColor($r('sys.color.font_primary')) + }.margin({ top: Constants.MARGIN_8, bottom: Constants.MARGIN_8 }) } - }.padding({ left: Constants.LISTITEM_PADDING_LEFT, right: Constants.LISTITEM_PADDING_RIGHT }) + .width(Constants.FULL_WIDTH) + .height(Constants.HEIGHT_48) + }.padding({ left: Constants.PADDING_24, right: Constants.PADDING_24 }) } .backgroundColor($r('sys.color.comp_background_list_card')) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding({ top: Constants.LIST_PADDING_TOP, bottom: Constants.LIST_PADDING_BOTTOM }) - }.margin({ top: Constants.ROW_MARGIN_TOP }) - .padding({ - left: Constants.SECONDARY_LIST_PADDING_LEFT, - right: Constants.SECONDARY_LIST_PADDING_RIGHT - }) + .padding({ top: Constants.PADDING_4, bottom: Constants.PADDING_4 }) + } + .margin({ top: Constants.MARGIN_9 }) + .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) } else { Scroll() { List() { @@ -327,74 +207,78 @@ struct appNamePlusPage { ListItem() { Row() { Text($r('app.string.allowed')) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) .fontWeight(FontWeight.Medium) - .lineHeight(Constants.SUBTITLE_LINE_HEIGHT) - }.constraintSize({ minHeight: Constants.SUBTITLE_MIN_HEIGHT }) + .lineHeight(Constants.LINE_HEIGHT_24) + } + .constraintSize({ minHeight: Constants.HEIGHT_48 }) .width(Constants.FULL_WIDTH) - .padding({ top: Constants.SUBTITLE_PADDING_TOP, bottom: Constants.SUBTITLE_PADDING_BOTTOM, - left: Constants.SECONDARY_TEXT_MARGIN_LEFT}) + .padding({ + top: Constants.PADDING_16, + bottom: Constants.PADDING_8, + left: Constants.MARGIN_24 + }) } ListItem() { Row() { List() { - ForEach(this.allowedListItem, (item: PermissionObj) => { - this.ListItemLayout(item, Constants.PERMISSION_ALLOW) - }, (item: PermissionObj) => JSON.stringify(item)) + ForEach(this.allowedListItem, (item: CurrentGroupStatus) => { + this.ListItemLayout(item) + }, (item: CurrentGroupStatus) => JSON.stringify(item)) } .backgroundColor($r('sys.color.comp_background_list_card')) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding(Constants.LIST_PADDING_TOP) + .padding(Constants.PADDING_4) .divider({ strokeWidth: Constants.DIVIDER, color: $r('sys.color.comp_divider'), startMargin: Constants.DEFAULT_MARGIN_START, endMargin: Constants.DEFAULT_MARGIN_END }) - }.margin({ top: Constants.ROW_MARGIN_TOP }) - .padding({ - left: Constants.SECONDARY_LIST_PADDING_LEFT, - right: Constants.SECONDARY_LIST_PADDING_RIGHT - }) + } + .margin({ top: Constants.MARGIN_9 }) + .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) } } if (this.bannedListItem.length) { ListItem() { Row() { Text($r('app.string.banned')) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) .fontWeight(FontWeight.Medium) - .lineHeight(Constants.SUBTITLE_LINE_HEIGHT) - }.constraintSize({ minHeight: Constants.SUBTITLE_MIN_HEIGHT }) + .lineHeight(Constants.LINE_HEIGHT_24) + } + .constraintSize({ minHeight: Constants.HEIGHT_48 }) .width(Constants.FULL_WIDTH) - .padding({ top: Constants.SUBTITLE_PADDING_TOP, bottom: Constants.SUBTITLE_PADDING_BOTTOM, - left: Constants.SECONDARY_TEXT_MARGIN_LEFT}) + .padding({ + top: Constants.PADDING_16, + bottom: Constants.PADDING_8, + left: Constants.MARGIN_24 + }) } ListItem() { Row() { List() { - ForEach(this.bannedListItem, (item: PermissionObj) => { - this.ListItemLayout(item, Constants.PERMISSION_BAN) - }, (item: PermissionObj) => JSON.stringify(item)) + ForEach(this.bannedListItem, (item: CurrentGroupStatus) => { + this.ListItemLayout(item) + }, (item: CurrentGroupStatus) => JSON.stringify(item)) } .backgroundColor($r('sys.color.comp_background_list_card')) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding(Constants.LIST_PADDING_TOP) + .padding(Constants.PADDING_4) .divider({ strokeWidth: Constants.DIVIDER, color: $r('sys.color.comp_divider'), startMargin: Constants.DEFAULT_MARGIN_START, endMargin: Constants.DEFAULT_MARGIN_END }) - }.margin({ top: Constants.ROW_MARGIN_TOP }) - .padding({ - left: Constants.SECONDARY_LIST_PADDING_LEFT, - right: Constants.SECONDARY_LIST_PADDING_RIGHT - }) + } + .margin({ top: Constants.MARGIN_9 }) + .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) } } } diff --git a/permissionmanager/src/main/ets/pages/application-tertiary.ets b/permissionmanager/src/main/ets/pages/application-tertiary.ets index efaa2e3..7bf5ca5 100644 --- a/permissionmanager/src/main/ets/pages/application-tertiary.ets +++ b/permissionmanager/src/main/ets/pages/application-tertiary.ets @@ -17,31 +17,20 @@ import { backBar } from '../common/components/backBar'; import common from '@ohos.app.ability.common'; import bundleManager from '@ohos.bundle.bundleManager'; import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; -import { BusinessError } from '@ohos.base'; import { showSubPermissionsGroup } from '../common/model/permissionGroup'; import { Log, getPermissionLabel } from '../common/utils/utils'; import Constants from '../common/utils/constant'; -import { MediaDocObj, RouterParams3, AppInfo, CheckboxInfo } from '../common/model/typedef'; +import { MediaDocObj, CheckboxInfo, ManageAppInfo, CurrentGroupStatus } from '../common/model/typedef'; import { GlobalContext } from '../common/utils/globalContext'; -import { Permission, PermissionGroup } from '../common/model/definition'; +import { Permission } from '../common/model/definition'; import { PermissionUtils } from '../common/utils/permissionUtils'; const showPrecise: number[] = [Constants.PERMISSION_ALLOW, Constants.PERMISSION_ALLOWED_ONLY_DURING_USE]; -let accessTokenId: number = 0; -let reqPermissionInfo: bundleManager.ReqPermissionDetail; @Entry @Component struct mediaDocumentPage { - private backTitle: ResourceStr = (this.getUIContext().getRouter().getParams() as RouterParams3).backTitle; - private permissions: Permission[] = (this.getUIContext().getRouter().getParams() as RouterParams3).permission; - private tokenId: number = (this.getUIContext().getRouter().getParams() as RouterParams3).tokenId; - @State currentGroup: string = GlobalContext.load('currentPermissionGroup'); - @State folderStatus: boolean[] = GlobalContext.load('folderStatus'); - @State refresh: boolean = false; - @State selected: number = 0; // Permission status array - @State accurateIsOn: boolean = false; - @State isRefreshReason: number = 0; + @State currentGroupStatus: CurrentGroupStatus = GlobalContext.load('currentGroupStatus'); build() { Column() { @@ -54,19 +43,14 @@ struct mediaDocumentPage { Row() { Column() { Row() { - backBar({ title: JSON.stringify(this.backTitle), recordable: false }) + backBar({ title: JSON.stringify(this.currentGroupStatus.label), recordable: false }) } Row() { Column() { - mediaDocumentItem({ - selected: $selected, - accurateIsOn: $accurateIsOn, - isRefreshReason: $isRefreshReason, - folderStatus: $folderStatus - }) + mediaDocumentItem() }.width(Constants.FULL_WIDTH) } - .margin({ top: Constants.TITLE_MARGIN_BOTTOM }) + .margin({ top: Constants.MARGIN_16 }) .layoutWeight(Constants.LAYOUT_WEIGHT) } } @@ -77,132 +61,21 @@ struct mediaDocumentPage { }.backgroundColor($r('sys.color.background_secondary')) } } - - onPageShow() { - if (this.refresh) { - this.refreshStatus(); - } - this.refresh = true; - } - - refreshStatus() { - if (reqPermissionInfo) { - this.isRefreshReason ++; - } - Log.info('Refresh permission status'); - let isGranted = this.currentGroup === 'LOCATION' ? Constants.PERMISSION_BAN : Constants.PERMISSION_ALLOW; - let folderStatus = [false, false, false]; - let atManager = abilityAccessCtrl.createAtManager(); - for (let i = 0; i < this.permissions.length; i++) { - let permission = this.permissions[i]; - if (this.currentGroup === 'LOCATION') { - continue; - } - let res = atManager.verifyAccessTokenSync(this.tokenId, permission); - if (res != abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { - isGranted = Constants.PERMISSION_BAN; - } - if (this.currentGroup === 'FOLDER' && res === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { - switch (permission) { - case Permission.READ_WRITE_DOWNLOAD_DIRECTORY: - folderStatus[0] = true; - break; - case Permission.READ_WRITE_DESKTOP_DIRECTORY: - folderStatus[1] = true; - break; - case Permission.READ_WRITE_DOCUMENTS_DIRECTORY: - folderStatus[2] = true; - break; - } - } - } - Log.info('isGranted: ' + JSON.stringify(isGranted)); - this.folderStatus = folderStatus; - - this.refreshSelected(isGranted); - } - - refreshSelected(isGranted: number) { - this.selected = isGranted; - if (this.currentGroup === 'PASTEBOARD') { - try { - let acManager = abilityAccessCtrl.createAtManager(); - acManager.getPermissionFlags(this.tokenId, Permission.READ_PASTEBOARD).then(flag => { - flag === Constants.PERMISSION_ALLOW_THIS_TIME ? this.selected = Constants.PERMISSION_ONLY_THIS_TIME : null; - }) - } catch (err) { - Log.error('getPermissionFlags error: ' + JSON.stringify(err)); - } - } - if (this.currentGroup === 'LOCATION') { - try { - let acManager = abilityAccessCtrl.createAtManager(); - let fuzzyState = acManager.verifyAccessTokenSync(this.tokenId, Permission.APPROXIMATELY_LOCATION); - fuzzyState === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED ? - this.selected = Constants.PERMISSION_ALLOWED_ONLY_DURING_USE : null; - let accurateStatus = acManager.verifyAccessTokenSync(this.tokenId, Permission.LOCATION); - this.accurateIsOn = (accurateStatus == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) ? true : false; - let backgroundState = acManager.verifyAccessTokenSync(this.tokenId, Permission.LOCATION_IN_BACKGROUND); - backgroundState === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED ? - this.selected = Constants.PERMISSION_ALLOW : null; - acManager.getPermissionFlags(this.tokenId, Permission.APPROXIMATELY_LOCATION ).then(flag => { - flag === Constants.PERMISSION_ALLOW_THIS_TIME ? this.selected = Constants.PERMISSION_ONLY_THIS_TIME : null; - }) - } catch (err) { - Log.error('change location status error: ' + JSON.stringify(err)); - } - } - } } @Component struct mediaDocumentItem { private context = this.getUIContext().getHostContext() as common.UIAbilityContext; - private backTitle: ResourceStr = (this.getUIContext().getRouter().getParams() as RouterParams3).backTitle; - private bundleName: string = (this.getUIContext().getRouter().getParams() as RouterParams3).bundleName; - private permissions: Permission[] = (this.getUIContext().getRouter().getParams() as RouterParams3).permission; - private status: number = (this.getUIContext().getRouter().getParams() as RouterParams3).status; - @State currentGroup: PermissionGroup = GlobalContext.load('currentPermissionGroup'); - @State applicationInfo: AppInfo = GlobalContext.load('applicationInfo'); - @Link folderStatus: boolean[]; - @State mediaDocListItem: MediaDocObj[] = []; // Permission information array - @Link selected: number; - @Link accurateIsOn: boolean; - @State isRisk: boolean = false; // Whether it is a risky application + @State applicationInfo: ManageAppInfo = GlobalContext.load('applicationInfo'); + @State currentGroupStatus: CurrentGroupStatus = GlobalContext.load('currentGroupStatus'); + @State mediaDocListItem: MediaDocObj[] = []; + @State accurateIsOn: boolean = false; + @State isRisk: boolean = false; @State noForeground: boolean = false; @State isTouch: number = -1; @State isCheck: string = ''; @State reason: string = ''; - @State label: string = ''; - @State version: string = ''; @State permissionLabels: Array = []; - @Link @Watch('updateReason') isRefreshReason: number; - - /** - * Update reason - */ - updateReason() { - bundleManager.getApplicationInfo( - this.applicationInfo.bundleName, bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT - ).then(appInfo => { - let bundleContext = this.context.createBundleContext(this.bundleName) - bundleContext.resourceManager.getStringValue(appInfo.labelId, (error, value) => { - if (value) { - this.applicationInfo.label = value; - GlobalContext.store('applicationInfo', this.applicationInfo); - this.label = value - } - }) - }).catch((error: BusinessError) => { - Log.error('getApplicationInfo error: ' + JSON.stringify(error)); - }) - let context = this.context.createModuleContext(this.bundleName, reqPermissionInfo.moduleName); - context.resourceManager.getStringValue(reqPermissionInfo.reasonId).then(value => { - if (value !== undefined) { - this.reason = value.slice(Constants.START_SUBSCRIPT, Constants.END_SUBSCRIPT); - } - }) - } getCheckboxInfo(permission: Permission): CheckboxInfo { switch (permission) { @@ -218,24 +91,23 @@ struct mediaDocumentItem { } getMediaDocList() { - if (this.currentGroup == 'PASTEBOARD') { + if (this.currentGroupStatus.name == 'PASTEBOARD') { this.mediaDocListItem.push( - new MediaDocObj($r('app.string.per_use_query'), this.permissions, Constants.PERMISSION_ONLY_THIS_TIME) + new MediaDocObj($r('app.string.per_use_query'), this.currentGroupStatus.permissions, Constants.PERMISSION_ONLY_THIS_TIME) ); this.mediaDocListItem.push( - new MediaDocObj($r('app.string.always_allow'), this.permissions, Constants.PERMISSION_ALLOW) + new MediaDocObj($r('app.string.always_allow'), this.currentGroupStatus.permissions, Constants.PERMISSION_ALLOW) ); - } else if (this.currentGroup == 'LOCATION') { - this.selected = GlobalContext.load('locationStatus'); + } else if (this.currentGroupStatus.name == 'LOCATION') { this.mediaDocListItem.push( - new MediaDocObj($r('app.string.per_inquiry'), this.permissions, Constants.PERMISSION_ONLY_THIS_TIME) + new MediaDocObj($r('app.string.per_inquiry'), this.currentGroupStatus.permissions, Constants.PERMISSION_ONLY_THIS_TIME) ); - if (this.permissions.includes(Permission.LOCATION_IN_BACKGROUND)) { + if (this.currentGroupStatus.permissions.includes(Permission.LOCATION_IN_BACKGROUND)) { this.mediaDocListItem.push( - new MediaDocObj($r('app.string.always_allow'), this.permissions, Constants.PERMISSION_ALLOW) + new MediaDocObj($r('app.string.always_allow'), this.currentGroupStatus.permissions, Constants.PERMISSION_ALLOW) ); } - if (this.permissions.includes(Permission.APPROXIMATELY_LOCATION)) { + if (this.currentGroupStatus.permissions.includes(Permission.APPROXIMATELY_LOCATION)) { this.mediaDocListItem.push( new MediaDocObj( $r('app.string.allowed_only_during_use'), @@ -248,18 +120,17 @@ struct mediaDocumentItem { } } else { this.mediaDocListItem.push( - new MediaDocObj($r('app.string.allow'), this.permissions, Constants.PERMISSION_ALLOW) + new MediaDocObj($r('app.string.allow'), this.currentGroupStatus.permissions, Constants.PERMISSION_ALLOW) ); } this.mediaDocListItem.push( - new MediaDocObj($r('app.string.ban'), this.permissions, Constants.PERMISSION_BAN) + new MediaDocObj($r('app.string.ban'), this.currentGroupStatus.permissions, Constants.PERMISSION_BAN) ); } getReason() { - this.label = this.applicationInfo.label; - if (showSubPermissionsGroup.indexOf(this.currentGroup) != -1) { - this.permissions.forEach((permission, idx) => { + if (showSubPermissionsGroup.indexOf(this.currentGroupStatus.name) != -1) { + this.currentGroupStatus.permissions.forEach((permission, idx) => { if (idx > 0) { this.permissionLabels.push($r('app.string.and')) } @@ -268,17 +139,16 @@ struct mediaDocumentItem { }) } let hasReason = false; - bundleManager.getBundleInfo(this.bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION) + bundleManager.getBundleInfo(this.applicationInfo.bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION) .then(info => { - this.permissions.forEach(permission => { + this.currentGroupStatus.permissions.forEach(permission => { info.reqPermissionDetails.forEach(reqPermissionDetail => { if (reqPermissionDetail.name == permission) { Log.info('reqPermissionDetail: ' + JSON.stringify(reqPermissionDetail)); - let context = this.context.createModuleContext(this.bundleName, reqPermissionDetail.moduleName); + let context = this.context.createModuleContext(this.applicationInfo.bundleName, reqPermissionDetail.moduleName); context.resourceManager.getStringValue(reqPermissionDetail.reasonId).then(value => { if (value !== undefined && !hasReason) { this.reason = value.slice(Constants.START_SUBSCRIPT, Constants.END_SUBSCRIPT); - reqPermissionInfo = reqPermissionDetail; hasReason = true; } }) @@ -288,32 +158,21 @@ struct mediaDocumentItem { }) } - /** - * Lifecycle function, executed when the page is initialized - */ aboutToAppear() { - this.selected = this.status; this.getMediaDocList(); this.getReason(); try { - bundleManager.getBundleInfo(this.bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION) - .then(res => { - this.version = res.versionName; - accessTokenId = res.appInfo.accessTokenId; - let acManager = abilityAccessCtrl.createAtManager(); - let accurateStatus = acManager.verifyAccessTokenSync(res.appInfo.accessTokenId, Permission.LOCATION); - this.accurateIsOn = (accurateStatus == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) ? true : false; - let getFlagPermission = - this.currentGroup === 'LOCATION' ? Permission.APPROXIMATELY_LOCATION : this.permissions[0]; - acManager.getPermissionFlags(res.appInfo.accessTokenId, getFlagPermission).then((flag) => { - Log.info(`getPermissionFlags success, data->${JSON.stringify(flag)}`); - this.isRisk = (flag == Constants.PERMISSION_POLICY_FIXED) ? true : false; - flag === Constants.PERMISSION_ALLOW_THIS_TIME ? this.selected = Constants.PERMISSION_ONLY_THIS_TIME : null; - }) - }).catch((error: BusinessError) => { - Log.error('bundle.getBundleInfo failed. Cause: ' + JSON.stringify(error)); - }) + let acManager = abilityAccessCtrl.createAtManager(); + let accurateStatus = acManager.verifyAccessTokenSync(this.applicationInfo.tokenId, Permission.LOCATION); + this.accurateIsOn = (accurateStatus == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) ? true : false; + let getFlagPermission = + this.currentGroupStatus.name === 'LOCATION' ? Permission.APPROXIMATELY_LOCATION : this.currentGroupStatus.permissions[0]; + acManager.getPermissionFlags(this.applicationInfo.tokenId, getFlagPermission).then((flag) => { + Log.info(`getPermissionFlags success, data->${JSON.stringify(flag)}`); + this.isRisk = (flag == Constants.PERMISSION_POLICY_FIXED) ? true : false; + flag === Constants.PERMISSION_ALLOW_THIS_TIME ? this.currentGroupStatus.status = Constants.PERMISSION_ONLY_THIS_TIME : null; + }) } catch (err) { Log.error('bundle.getBundleInfo failed. Cause: ' + JSON.stringify(err)); } @@ -324,12 +183,12 @@ struct mediaDocumentItem { Row() { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Image(this.applicationInfo.icon) - .width(Constants.TERTIARY_IMAGE_WIDTH) - .height(Constants.TERTIARY_IMAGE_HEIGHT) - .margin({ left: Constants.TERTIARY_IMAGE_MARGIN_LEFT, right: Constants.TERTIARY_IMAGE_MARGIN_RIGHT }) + .width(Constants.IMAGE_LENGTH_64) + .height(Constants.IMAGE_LENGTH_64) + .margin({ left: Constants.DEFAULT_MARGIN_START, right: Constants.DEFAULT_MARGIN_END }) Column() { Row() { - Text(this.label) + Text(this.applicationInfo.label) .maxLines(Constants.MAXIMUM_HEADER_LINES) .textOverflow({ overflow: TextOverflow.Ellipsis }) .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) @@ -337,21 +196,21 @@ struct mediaDocumentItem { .fontWeight(FontWeight.Bold) .textAlign(TextAlign.Start) } - .width(Constants.TERTIARY_HALF_WIDTH) - .margin({ bottom: Constants.TERTIARY_LABEL_MARGIN_BOTTOM }) + .width(Constants.HALF_LENGTH) + .margin({ bottom: Constants.MARGIN_2 }) Row() { Text($r('app.string.version')) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) .textAlign(TextAlign.Start) - Text(this.version) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + Text(this.applicationInfo.versionName) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) .textAlign(TextAlign.Start) } - .width(Constants.TERTIARY_HALF_WIDTH) + .width(Constants.HALF_LENGTH) } - }.margin({ left: Constants.TERTIARY_MARGIN_LEFT }) + }.margin({ left: Constants.DEFAULT_MARGIN_START }) } if (this.reason || this.permissionLabels.length > 0) { Row() { @@ -366,14 +225,14 @@ struct mediaDocumentItem { } Span(this.reason) } - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.icon_secondary')) .textAlign(TextAlign.Start) - }.margin({ left: Constants.TERTIARY_IMAGE_MARGIN_LEFT, right: Constants.TERTIARY_IMAGE_MARGIN_RIGHT }) + }.margin({ left: Constants.DEFAULT_MARGIN_START, right: Constants.DEFAULT_MARGIN_END }) } } .margin({ - top: Constants.TERTIARY_ROW_MARGIN_TOP, + top: Constants.MARGIN_24, left: Constants.DEFAULT_MARGIN_START, bottom: Constants.DEFAULT_MARGIN_BOTTOM }) @@ -384,9 +243,9 @@ struct mediaDocumentItem { Row() { Image($r('app.media.ic_public_fail')) .fillColor($r('sys.color.icon_secondary')) - .width(Constants.TERTIARY_RADIO_IMAGE_WIDTH) - .height(Constants.TERTIARY_RADIO_IMAGE_HEIGHT) - .margin({ right: Constants.TERTIARY_IMAGE_MARGIN_RIGHT }) + .width(Constants.IMAGE_LENGTH_24) + .height(Constants.IMAGE_LENGTH_24) + .margin({ right: Constants.DEFAULT_MARGIN_END }) Text($r('app.string.risk_warning')) .fontColor($r('sys.color.font_primary')) .fontSize($r('sys.float.ohos_id_text_size_body1')) @@ -400,22 +259,26 @@ struct mediaDocumentItem { } Row() { Text() { - Span(this.backTitle) + Span(this.currentGroupStatus.label) Span($r('app.string.access_permission')) } - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.icon_secondary')) .fontWeight(FontWeight.Medium) .textAlign(TextAlign.Start) - .lineHeight(Constants.SUBTITLE_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_24) }.width(Constants.FULL_WIDTH) - .constraintSize({ minHeight: Constants.SUBTITLE_MIN_HEIGHT }) - .padding({ top: Constants.SUBTITLE_PADDING_TOP, bottom: Constants.SUBTITLE_PADDING_BOTTOM, - left: Constants.TERTIARY_TEXT_MARGIN_LEFT, right: Constants.TERTIARY_IMAGE_MARGIN_RIGHT}) + .constraintSize({ minHeight: Constants.HEIGHT_48 }) + .padding({ + top: Constants.PADDING_16, + bottom: Constants.PADDING_8, + left: Constants.PADDING_24, + right: Constants.DEFAULT_PADDING_END + }) Column() { List() { - if (this.currentGroup === 'FOLDER') { - ForEach(this.permissions, (permission: Permission) => { + if (this.currentGroupStatus.name === 'FOLDER') { + ForEach(this.currentGroupStatus.permissions, (permission: Permission) => { ListItem() { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Row() { @@ -425,18 +288,18 @@ struct mediaDocumentItem { .fontWeight(FontWeight.Medium) .flexGrow(Constants.FLEX_GROW) Checkbox() - .select(this.folderStatus[this.getCheckboxInfo(permission).index]) + .select(this.currentGroupStatus.folderStatus[this.getCheckboxInfo(permission).index]) .hitTestBehavior(HitTestMode.None) } .width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_ROW_HEIGHT) + .height(Constants.HEIGHT_48) .onClick(() => { - if (this.folderStatus[this.getCheckboxInfo(permission).index]) { - PermissionUtils.revokePermissionWithResult(permission, Constants.PERMISSION_FLAG, accessTokenId); - this.folderStatus[this.getCheckboxInfo(permission).index] = false; + if (this.currentGroupStatus.folderStatus[this.getCheckboxInfo(permission).index]) { + PermissionUtils.revokePermissionWithResult(permission, Constants.PERMISSION_FLAG, this.applicationInfo.tokenId) + this.currentGroupStatus.folderStatus[this.getCheckboxInfo(permission).index] = false; } else { - PermissionUtils.grantPermissionWithResult(permission, Constants.PERMISSION_FLAG, accessTokenId); - this.folderStatus[this.getCheckboxInfo(permission).index] = true; + PermissionUtils.grantPermissionWithResult(permission, Constants.PERMISSION_FLAG, this.applicationInfo.tokenId); + this.currentGroupStatus.folderStatus[this.getCheckboxInfo(permission).index] = true; } }) } @@ -446,7 +309,7 @@ struct mediaDocumentItem { right: $r('sys.float.ohos_id_card_margin_end') }) .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) - .margin({ top: Constants.TERTIARY_LISTITEM_MARGIN_TOP }) + .margin({ top: Constants.MARGIN_1 }) .linearGradient((this.isCheck === permission) ? { angle: 90, direction: GradientDirection.Right, @@ -471,64 +334,60 @@ struct mediaDocumentItem { } else { ForEach(this.mediaDocListItem, (item: MediaDocObj) => { ListItem() { - Column() { + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Row() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Row() { - Text(item.name) - .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) - .fontColor($r('sys.color.font_primary')) - .fontWeight(FontWeight.Medium) - .flexGrow(Constants.FLEX_GROW) - Radio({ value: 'Radio', group: 'radioGroup' }) - .checked(item.index === this.selected) - .hitTestBehavior(HitTestMode.None) - .height(Constants.SHAPE_DIA) - .width(Constants.SHAPE_DIA) - } - .width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_ROW_HEIGHT) - .onClick(() => { - this.selected = item.index; - item.permissions.forEach((permission): boolean => { - if (item.index === Constants.PERMISSION_ALLOW) { - if (permission === Permission.LOCATION) { - return false; - } - PermissionUtils.grantPermissionWithResult( - permission, Constants.PERMISSION_FLAG, accessTokenId - ); - } else if (item.index === Constants.PERMISSION_BAN) { - if (permission == Permission.LOCATION && this.accurateIsOn) { - PermissionUtils.revokePermissionWithResult( - permission, Constants.PERMISSION_FLAG, accessTokenId - ); - this.accurateIsOn = false; - } else { - PermissionUtils.revokePermissionWithResult( - permission, Constants.PERMISSION_FLAG, accessTokenId - ); - } - } else if (item.index === Constants.PERMISSION_ONLY_THIS_TIME) { - if (permission === Permission.LOCATION) { - return false; - } - PermissionUtils.revokePermissionWithResult( - permission, Constants.PERMISSION_ALLOW_THIS_TIME, accessTokenId - ); - } else if (item.index === Constants.PERMISSION_ALLOWED_ONLY_DURING_USE) { - PermissionUtils.grantPermissionWithResult( - permission, Constants.PERMISSION_FLAG, accessTokenId - ); - PermissionUtils.revokePermissionWithResult( - Permission.LOCATION_IN_BACKGROUND, Constants.PERMISSION_FLAG, accessTokenId - ); - } - return true; - }) - }) - } + Text(item.name) + .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) + .fontColor($r('sys.color.font_primary')) + .fontWeight(FontWeight.Medium) + .flexGrow(Constants.FLEX_GROW) + Radio({ value: 'Radio', group: 'radioGroup' }) + .checked(item.index === this.currentGroupStatus.status) + .hitTestBehavior(HitTestMode.None) + .height(Constants.SHAPE_DIA) + .width(Constants.SHAPE_DIA) } + .width(Constants.FULL_WIDTH) + .height(Constants.HEIGHT_48) + .onClick(() => { + this.currentGroupStatus.status = item.index; + item.permissions.forEach((permission: Permission): boolean => { + if (item.index === Constants.PERMISSION_ALLOW) { + if (permission === Permission.LOCATION) { + return false; + } + PermissionUtils.grantPermissionWithResult( + permission, Constants.PERMISSION_FLAG, this.applicationInfo.tokenId + ); + } else if (item.index === Constants.PERMISSION_BAN) { + if (permission == Permission.LOCATION && this.accurateIsOn) { + PermissionUtils.revokePermissionWithResult( + permission, Constants.PERMISSION_FLAG, this.applicationInfo.tokenId + ); + this.accurateIsOn = false; + } else { + PermissionUtils.revokePermissionWithResult( + permission, Constants.PERMISSION_FLAG, this.applicationInfo.tokenId + ); + } + } else if (item.index === Constants.PERMISSION_ONLY_THIS_TIME) { + if (permission === Permission.LOCATION) { + return false; + } + PermissionUtils.revokePermissionWithResult( + permission, Constants.PERMISSION_ALLOW_THIS_TIME, this.applicationInfo.tokenId + ); + } else if (item.index === Constants.PERMISSION_ALLOWED_ONLY_DURING_USE) { + PermissionUtils.grantPermissionWithResult( + permission, Constants.PERMISSION_FLAG, this.applicationInfo.tokenId + ); + PermissionUtils.revokePermissionWithResult( + Permission.LOCATION_IN_BACKGROUND, Constants.PERMISSION_FLAG, this.applicationInfo.tokenId + ); + } + return true; + }) + }) } } .padding({ @@ -556,13 +415,13 @@ struct mediaDocumentItem { this.isTouch = -1; } }) - .margin({ top: Constants.TERTIARY_LISTITEM_MARGIN_TOP }) + .margin({ top: Constants.MARGIN_1 }) }, (item: MediaDocObj) => JSON.stringify(item)) } } .borderRadius($r('sys.float.ohos_id_corner_radius_card')) .backgroundColor($r('sys.color.comp_background_list_card')) - .padding(Constants.LIST_PADDING_TOP) + .padding(Constants.PADDING_4) .divider({ strokeWidth: Constants.DIVIDER, color: $r('sys.color.comp_divider'), @@ -570,7 +429,7 @@ struct mediaDocumentItem { endMargin: Constants.DEFAULT_MARGIN_END }) - if (this.permissions.includes(Permission.LOCATION) && showPrecise.includes(this.selected)) { + if (this.currentGroupStatus.permissions.includes(Permission.LOCATION) && showPrecise.includes(this.currentGroupStatus.status)) { Column() { Row() { Text($r('app.string.precise_location')) @@ -584,34 +443,35 @@ struct mediaDocumentItem { .onChange((isOn: boolean) => { if (isOn) { PermissionUtils.grantPermissionWithResult( - Permission.LOCATION, Constants.PERMISSION_FLAG, accessTokenId + Permission.LOCATION, Constants.PERMISSION_FLAG, this.applicationInfo.tokenId ); this.accurateIsOn = true; } else { PermissionUtils.revokePermissionWithResult( - Permission.LOCATION, Constants.PERMISSION_FLAG, accessTokenId + Permission.LOCATION, Constants.PERMISSION_FLAG, this.applicationInfo.tokenId ); this.accurateIsOn = false; } }) .padding({ right: 0 }) }.width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_ROW_HEIGHT) - }.margin({ top: Constants.LOCATION_MARGIN_TOP, bottom: Constants.LOCATION_MARGIN_BOTTOM }) + .height(Constants.HEIGHT_48) + } + .margin({ top: Constants.DEFAULT_MARGIN_TOP, bottom: Constants.MARGIN_8 }) .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END, - top: Constants.TERTIARY_LIST_PADDING_TOP, - bottom: Constants.TERTIARY_LIST_PADDING_BOTTOM + top: Constants.PADDING_4, + bottom: Constants.PADDING_4 }) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) .backgroundColor($r('sys.color.comp_background_list_card')) Row() { Text($r('app.string.get_the_exact_position')) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .lineHeight(Constants.TEXT_SMALL_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_19) }.width(Constants.FULL_WIDTH) .padding({ left: Constants.DEFAULT_PADDING_START, @@ -620,8 +480,8 @@ struct mediaDocumentItem { } } .padding({ - left: Constants.LIST_PADDING_LEFT, - right: Constants.LIST_PADDING_LEFT + left: Constants.DEFAULT_PADDING_START, + right: Constants.DEFAULT_PADDING_END }) .width(Constants.FULL_WIDTH) .height(Constants.FULL_HEIGHT) diff --git a/permissionmanager/src/main/ets/pages/authority-management.ets b/permissionmanager/src/main/ets/pages/authority-management.ets index 4210d14..e422db5 100644 --- a/permissionmanager/src/main/ets/pages/authority-management.ets +++ b/permissionmanager/src/main/ets/pages/authority-management.ets @@ -14,28 +14,15 @@ */ import { backBar } from '../common/components/backBar'; -import { alphabetIndexerComponent } from '../common/components/alphabeticalIndex'; import { textInput } from '../common/components/search'; -import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; -import display from '@ohos.display'; -import common from '@ohos.app.ability.common'; -import { groups, globalGroup, showSubPermissionsGroup } from '../common/model/permissionGroup'; -import { - Log, - indexValue, - addLocalTag, - sortByName, - supportPermission, - getPermissionGroup, - getGroupIdByPermission, - getPermissionGroupByName -} from '../common/utils/utils'; -import { AppInfo, PermissionApplications, GroupPermission, GroupInfo } from '../common/model/typedef'; import { GlobalContext } from '../common/utils/globalContext'; -import { Permission, PermissionGroup } from '../common/model/definition'; +import { Log, indexValue, sortByName, } from '../common/utils/utils'; import { GlobalDialogModel } from '../GlobalExtAbility/GlobalDialogModel'; +import { alphabetIndexerComponent } from '../common/components/alphabeticalIndex'; +import { globalGroup, showSubPermissionsGroup } from '../common/model/permissionGroup'; +import { PermissionApplications, GroupInfo, ManageAppInfo } from '../common/model/typedef'; +import display from '@ohos.display'; import Constants from '../common/utils/constant'; -import bundleManager from '@ohos.bundle.bundleManager'; @Extend(Image)function customizeImage(width: number, height: number) { .objectFit(ImageFit.Contain) @@ -47,7 +34,7 @@ import bundleManager from '@ohos.bundle.bundleManager'; @Entry({ useSharedStorage: true }) @Component struct authorityManagementPage { - @Builder ListItemLayout(item: GroupPermission) { + @Builder ListItemLayout(item: GroupInfo) { ListItem() { Row() { Column() { @@ -55,43 +42,43 @@ struct authorityManagementPage { Row() { Image(item.icon) .fillColor($r('sys.color.icon_secondary')) - .customizeImage(Constants.MANAGEMENT_IMAGE_WIDTH, Constants.MANAGEMENT_IMAGE_HEIGHT) - .margin({ right: Constants.MANAGEMENT_IMAGE_MARGIN_RIGHT }) + .customizeImage(Constants.IMAGE_LENGTH_24, Constants.IMAGE_LENGTH_24) + .margin({ right: Constants.MARGIN_16 }) Text(item.groupName) .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) .fontWeight(FontWeight.Medium) .fontColor($r('sys.color.font_primary')) .flexGrow(Constants.FLEX_GROW) SymbolGlyph($r('sys.symbol.chevron_forward')) - .width(Constants.IMAGE_WIDTH) - .height(Constants.IMAGE_HEIGHT) + .width(Constants.IMAGE_LENGTH_12) + .height(Constants.IMAGE_LENGTH_24) .fontSize(Constants.FONT_SIZE_18_vp) .fontColor([$r('sys.color.icon_tertiary')]) .fontWeight(FontWeight.Medium) } .width(Constants.FULL_WIDTH) - .height(Constants.MANAGEMENT_ROW_HEIGHT) + .height(Constants.HEIGHT_56) } }.onClick(() => { - if (item.group === 'OTHER' || showSubPermissionsGroup.indexOf(item.group) !== -1) { + if (item.name === 'OTHER' || showSubPermissionsGroup.indexOf(item.name) !== -1) { this.getUIContext().getRouter().pushUrl({ url: 'pages/authority-secondary', - params: { list: this.allPermissionApplications, backTitle: item.groupName, group: item.group } + params: { list: this.allPermissionApplications, backTitle: item.groupName, group: item.name } }) } else { let dataList = this.allPermissionApplications.filter((ele) => { - return ele.groupName === item.group; + return ele.groupName === item.name; }) - GlobalContext.store('currentPermissionGroup', item.group); - if (globalGroup.indexOf(item.group) == -1) { + GlobalContext.store('currentPermissionGroup', item.name); + if (globalGroup.indexOf(item.name) == -1) { this.getUIContext().getRouter().pushUrl({ url: 'pages/authority-tertiary-groups', params: { list: dataList, backTitle: item.groupName } }) } else { GlobalDialogModel.getInstance().getMuteStateAndGoto( - this.getUIContext(), item.group, item.groupName, dataList + this.getUIContext(), item.name, item.groupName, dataList ); } } @@ -99,7 +86,7 @@ struct authorityManagementPage { } }.padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') }) .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) - .linearGradient((this.isTouch === item.group) ? { + .linearGradient((this.isTouch === item.name) ? { angle: 90, direction: GradientDirection.Right, colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]] @@ -113,7 +100,7 @@ struct authorityManagementPage { return; } if (event.type === TouchType.Down) { - this.isTouch = item.group; + this.isTouch = item.name; } if (event.type === TouchType.Up) { this.isTouch = ''; @@ -121,13 +108,9 @@ struct authorityManagementPage { }) } - private context = this.getUIContext().getHostContext() as common.UIAbilityContext; - @LocalStorageLink('initialGroups') initialGroups: bundleManager.BundleInfo[] = []; - @State allPermissionApplications: PermissionApplications [] = []; // All app permissions - @State allGroupPermission: GroupPermission[] = []; // All group permissions - @State allUserPermissions: Permission[] = []; - @State allBundleInfo: AppInfo[] = []; - @State allGroups: PermissionGroup[] = []; + @State manageAppList: ManageAppInfo[] = GlobalContext.load('manageAppList'); + @State allGroupWithPermissions: GroupInfo[] = GlobalContext.load('allGroupWithPermissions'); + @State allPermissionApplications: PermissionApplications [] = GlobalContext.load('allPermissionApplications'); @State currentIndex: number = 0; @State isTouch: string = ''; @State isVertical: boolean = true; @@ -144,219 +127,27 @@ struct authorityManagementPage { $r('sys.color.icon_secondary') ) .fontWeight(this.currentIndex == index ? FontWeight.Bold : FontWeight.Regular) - .lineHeight(Constants.TEXT_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_22) .baselineOffset(Constants.TAB_DECORATION_POSITION_Y) if (this.currentIndex == index) { Text(index ? $r('app.string.application') : $r('app.string.permission')) .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) .fontWeight(FontWeight.Bold) - .lineHeight(Constants.TAB_LINE_HEIGHT) - .height(Constants.TAB_DECORATION_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_100) + .height(Constants.HEIGHT_2) .fontColor($r('sys.color.ohos_id_color_subtab_text_on')) .backgroundColor($r('sys.color.ohos_id_color_subtab_text_on')) } - }.height(Constants.TAB_HEIGHT) - .width(Constants.FULL_WIDTH) - .padding({ left: this.isVertical ? Constants.TAB_INNER_PADDING : Constants.DEFAULT_PADDING_START, - right: this.isVertical ? Constants.TAB_INNER_PADDING : Constants.DEFAULT_PADDING_END }) - } - - /** - * Get all app permission information - */ - async getAllBundlePermissions() { - for (let i = 0; i < this.initialGroups.length; i++) { - await this.deduplicationPermissions(this.initialGroups[i]); } - this.getAllGroupPermission(); - this.getAllPermissionApplications(); - this.getLabelAndIcon(); - GlobalContext.store('allBundleInfo', this.allBundleInfo); - } - - /** - * Get all permission label - */ - getLabelAndIcon() { - this.allBundleInfo.forEach((bundleInfo: AppInfo) => { - this.updateAppLabel(bundleInfo); - this.updateAppIcon(bundleInfo); - }) - } - - /** - * Get all app permission information - */ - getAllPermissionApplications() { - for (let i = 0; i < this.allUserPermissions.length; i++) { - let permission: Permission = this.allUserPermissions[i]; - let permissionGroup: GroupInfo = getPermissionGroup(permission); - let icon: ResourceStr = permissionGroup.icon; - let bundleNames: string[] = []; - for (let j = 0; j < this.allBundleInfo.length; j++) { - if (this.allBundleInfo[j].permissions.indexOf(permission) != -1) { - bundleNames.push(this.allBundleInfo[j].bundleName); - } - } - let pa: PermissionApplications = new PermissionApplications(permission, permissionGroup.name, bundleNames, icon); - this.allPermissionApplications.push(pa); - } - } - - /** - * Get permission group information - */ - getAllGroupPermission() { - groups.forEach((item) => { - if (item.isShow) { - this.allGroups.push(item.name); - } - }) - this.allUserPermissions.forEach((userPermission: Permission) => { - let groupId = getGroupIdByPermission(userPermission); - if (this.allGroups.indexOf(groups[groupId].name) == -1) { - this.allGroups.push(groups[groupId].name); - } - }) - // Permission layout - for (let i = 0; i < this.allGroups.length; i++) { - let group = getPermissionGroupByName(this.allGroups[i]); - let gp: GroupPermission = new GroupPermission( - this.allGroups[i], group.permissions, group.groupName, group.icon, group.isShow - ); - this.allGroupPermission.push(gp); - } - } - - /** - * Deduplicate permission information and permission group information - * @param {Object} info bundleInfos Application Information - */ - async deduplicationPermissions(info: bundleManager.BundleInfo) { - Log.info('allBundleInfo start: ' + info.name); - let reqPermissions: Permission[] = []; - info.reqPermissionDetails.forEach(item => { - reqPermissions.push(item.name as Permission); + .height(Constants.HEIGHT_56) + .width(Constants.FULL_WIDTH) + .padding({ + left: this.isVertical ? Constants.PADDING_8 : Constants.DEFAULT_PADDING_START, + right: this.isVertical ? Constants.PADDING_8 : Constants.DEFAULT_PADDING_END }) - let reqPermissionsLen = reqPermissions.length; - let reqUserPermissions: Permission[] = []; - let acManager = abilityAccessCtrl.createAtManager() - if (reqPermissionsLen > 0) { - for (let j = 0; j < reqPermissions.length; j++) { - let permission = reqPermissions[j]; - if ((permission == Permission.LOCATION) && !reqPermissions.includes(Permission.APPROXIMATELY_LOCATION)) { - continue; - } - try { - let flag = await acManager.getPermissionFlags(info.appInfo.accessTokenId, permission); - if (flag == Constants.PERMISSION_SYSTEM_FIXED) { - continue; - } - } catch (err) { - Log.error('getPermissionFlags error: ' + JSON.stringify(err)); - } - let supportPermissions = supportPermission(); - if (supportPermissions.indexOf(permission) != -1) { - reqUserPermissions.push(permission); - if (this.allUserPermissions.indexOf(permission) == -1) { - this.allUserPermissions.push(permission); - } - } - } - } - this.getAllBundleInfo(info, reqUserPermissions); - } - - getAllBundleInfo(info: bundleManager.BundleInfo, reqUserPermissions: Permission[]) { - let groupIds: number[] = []; - for (let i = 0; i < reqUserPermissions.length; i++) { - let groupId = getGroupIdByPermission(reqUserPermissions[i]) - if (groupIds.indexOf(groupId) == -1) { - groupIds.push(groupId); - } - } - - let ap: AppInfo = new AppInfo( - info.name, - info.targetVersion, - info.appInfo.accessTokenId, - '', - info.appInfo.iconId, - info.appInfo.iconResource, - info.appInfo.label, - info.appInfo.labelId, - info.appInfo.labelResource, - reqUserPermissions, - groupIds, - '', - '', - '' - ); - Log.info('allBundleInfo.push: ' + info.name); - this.allBundleInfo.push(ap); } - /** - * Get app name resource - * @param {Number} index index of all app permissions array - * @param {String} bundleName Package names - * @param {String} labelName Application Name - */ - async updateAppLabel(info: AppInfo) { - Log.info( - 'bundleName: ' + info.bundleName + - ` labelResource: ` + JSON.stringify(info.labelResource) + - ' labelId: ' + info.labelId - ); - - try { - if (info.labelResource.id !== 0) { - info.label = await this.context.resourceManager.getStringValue(info.labelResource); - } else { - let resourceManager = this.context.createBundleContext(info.bundleName).resourceManager; - info.label = await resourceManager.getStringValue(info.labelId); - } - } catch (error) { - Log.error('getStringValue promise error is ' + error); - } - addLocalTag(info); - } - - /** - * Get app icon resources - * @param {Number} index index of all app permissions array - * @param {String} bundleName Package names - */ - async updateAppIcon(info: AppInfo) { - Log.info( - 'bundleName: ' + info.bundleName + - ` iconResource: ` + JSON.stringify(info.iconResource) + - ' iconId: ' + info.iconId - ); - - try { - if (info.iconResource.id !== 0) { - let iconDescriptor = this.context.resourceManager.getDrawableDescriptor(info.iconResource); - info.icon = iconDescriptor?.getPixelMap(); - } else { - let resourceManager = this.context.createBundleContext(info.bundleName).resourceManager; - let iconDescriptor = resourceManager.getDrawableDescriptor(info.iconId); - info.icon = iconDescriptor?.getPixelMap(); - } - } catch (error) { - Log.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`); - } - - if (!info.icon) { - info.icon = $r('app.media.icon'); - } - } - - /** - * Lifecycle function, executed when the page is initialized - */ aboutToAppear() { - this.getAllBundlePermissions(); try { let dis = display.getDefaultDisplaySync(); this.isVertical = dis.height > dis.width ? true : false; @@ -366,20 +157,20 @@ struct authorityManagementPage { } } - getPermissionGroup(allGroup: GroupPermission[], order: number): GroupPermission[] { + getPermissionGroup(allGroup: GroupInfo[], order: number): GroupInfo[] { let fixedName: string[] = ['LOCATION', 'CAMERA', 'MICROPHONE']; let extraName: string[] = ['ADS']; - let fixedGroup: GroupPermission[] = []; - let extraGroup: GroupPermission[] = []; - let changeGroup: GroupPermission[] = []; - let otherGroup: GroupPermission[] = []; + let fixedGroup: GroupInfo[] = []; + let extraGroup: GroupInfo[] = []; + let changeGroup: GroupInfo[] = []; + let otherGroup: GroupInfo[] = []; allGroup.forEach(group => { - if (fixedName.indexOf(group.group) !== -1) { + if (fixedName.indexOf(group.name) !== -1) { fixedGroup.push(group); - } else if (extraName.includes(group.group)) { + } else if (extraName.includes(group.name)) { extraGroup.push(group); - } else if (group.group == 'OTHER') { + } else if (group.name == 'OTHER') { otherGroup.push(group); } else { changeGroup.push(group); @@ -405,131 +196,121 @@ struct authorityManagementPage { span: { xs: Constants.XS_SPAN, sm: Constants.SM_SPAN, md: Constants.MD_SPAN, lg: Constants.LG_SPAN }, offset: { xs: Constants.XS_OFFSET, sm: Constants.SM_OFFSET, md: Constants.MD_OFFSET, lg: Constants.LG_OFFSET } }) { - Row() { - Column() { - Row() { - backBar( { title: JSON.stringify($r('app.string.permission_manager')), recordable: true }) - } - Row() { - Column() { - Column() { - Stack() { - if (this.allGroupPermission.length) { - Tabs() { - TabContent() { - Row() { - Column() { - Scroll() { - Column() { - List() { - ListItem() { - List() { - ForEach( - this.getPermissionGroup(this.allGroupPermission, Constants.FIXED_GROUP), - (item: GroupPermission) => { this.ListItemLayout(item) }, - (item: GroupPermission) => JSON.stringify(item) - ) - }.backgroundColor($r('sys.color.comp_background_list_card')) - .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding(Constants.LIST_PADDING_TOP) - .margin({ bottom: Constants.LIST_MARGIN_BOTTOM }) - .divider({ - strokeWidth: Constants.DIVIDER, - color: $r('sys.color.comp_divider'), - startMargin: Constants.DIVIDER_MARGIN_RIGHT_PERMISSION, - endMargin: Constants.DEFAULT_MARGIN_END - }) - } - - ListItem() { - List() { - ForEach( - this.getPermissionGroup(this.allGroupPermission, Constants.CHANGE_GROUP), - (item: GroupPermission) => { this.ListItemLayout(item) }, - (item: GroupPermission) => JSON.stringify(item) - ) - }.backgroundColor($r('sys.color.comp_background_list_card')) - .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding(Constants.LIST_PADDING_TOP) - .margin({ bottom: Constants.LIST_MARGIN_BOTTOM }) - .divider({ - strokeWidth: Constants.DIVIDER, - color: $r('sys.color.comp_divider'), - startMargin: Constants.DIVIDER_MARGIN_RIGHT_PERMISSION, - endMargin: Constants.DEFAULT_MARGIN_END - }) - } + Column() { + Row() { + backBar( { title: JSON.stringify($r('app.string.permission_manager')), recordable: true }) + } + Row() { + if (this.allGroupWithPermissions.length) { + Tabs() { + TabContent() { + Column() { + Scroll() { + Column() { + List() { + ListItem() { + List() { + ForEach( + this.getPermissionGroup(this.allGroupWithPermissions, Constants.FIXED_GROUP), + (item: GroupInfo) => { this.ListItemLayout(item) }, + (item: GroupInfo) => JSON.stringify(item) + ) + }.backgroundColor($r('sys.color.comp_background_list_card')) + .borderRadius($r('sys.float.ohos_id_corner_radius_card')) + .padding(Constants.PADDING_4) + .margin({ bottom: Constants.DEFAULT_MARGIN_BOTTOM }) + .divider({ + strokeWidth: Constants.DIVIDER, + color: $r('sys.color.comp_divider'), + startMargin: Constants.MARGIN_52, + endMargin: Constants.DEFAULT_MARGIN_END + }) + } - if ( - this.getPermissionGroup(this.allGroupPermission, Constants.EXTRA_GROUP).length - ) { - ListItem() { - List() { - ForEach( - this.getPermissionGroup(this.allGroupPermission, Constants.EXTRA_GROUP), - (item: GroupPermission) => { this.ListItemLayout(item) }, - (item: GroupPermission) => JSON.stringify(item) - ) - }.backgroundColor($r('sys.color.comp_background_list_card')) - .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding(Constants.LIST_PADDING_TOP) - .margin({ bottom: Constants.LIST_MARGIN_BOTTOM }) - .divider({ - strokeWidth: Constants.DIVIDER, - color: $r('sys.color.comp_divider'), - startMargin: Constants.DIVIDER_MARGIN_RIGHT_PERMISSION, - endMargin: Constants.DEFAULT_MARGIN_END - }) - } - } + ListItem() { + List() { + ForEach( + this.getPermissionGroup(this.allGroupWithPermissions, Constants.CHANGE_GROUP), + (item: GroupInfo) => { this.ListItemLayout(item) }, + (item: GroupInfo) => JSON.stringify(item) + ) + }.backgroundColor($r('sys.color.comp_background_list_card')) + .borderRadius($r('sys.float.ohos_id_corner_radius_card')) + .padding(Constants.PADDING_4) + .margin({ bottom: Constants.DEFAULT_MARGIN_BOTTOM }) + .divider({ + strokeWidth: Constants.DIVIDER, + color: $r('sys.color.comp_divider'), + startMargin: Constants.MARGIN_52, + endMargin: Constants.DEFAULT_MARGIN_END + }) + } - ListItem() { - List() { - ForEach( - this.getPermissionGroup(this.allGroupPermission, Constants.OTHER_GROUP), - (item: GroupPermission) => { this.ListItemLayout(item) }, - (item: GroupPermission) => JSON.stringify(item) - ) - }.backgroundColor($r('sys.color.comp_background_list_card')) - .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding(Constants.LIST_PADDING_TOP) - .divider({ - strokeWidth: Constants.DIVIDER, - color: $r('sys.color.comp_divider'), - startMargin: Constants.DIVIDER_MARGIN_RIGHT_PERMISSION, - endMargin: Constants.DEFAULT_MARGIN_END - }) - }.margin({ bottom: Constants.AUTHORITY_ROW_MARGIN_BOTTOM }) - }.height(Constants.FULL_HEIGHT) - .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .clip(true) - }.padding({ - left: Constants.MANAGEMENT_ROW_PADDING_LEFT, - right: Constants.MANAGEMENT_ROW_PADDING_RIGHT, - }) - }.scrollBar(BarState.Off) - .margin({ top: Constants.MANAGEMENT_ROW_PADDING_TOP }) - }.width(Constants.FULL_WIDTH) + if (this.getPermissionGroup(this.allGroupWithPermissions, Constants.EXTRA_GROUP).length) { + ListItem() { + List() { + ForEach( + this.getPermissionGroup(this.allGroupWithPermissions, Constants.EXTRA_GROUP), + (item: GroupInfo) => { this.ListItemLayout(item) }, + (item: GroupInfo) => JSON.stringify(item) + ) + }.backgroundColor($r('sys.color.comp_background_list_card')) + .borderRadius($r('sys.float.ohos_id_corner_radius_card')) + .padding(Constants.PADDING_4) + .margin({ bottom: Constants.DEFAULT_MARGIN_BOTTOM }) + .divider({ + strokeWidth: Constants.DIVIDER, + color: $r('sys.color.comp_divider'), + startMargin: Constants.MARGIN_52, + endMargin: Constants.DEFAULT_MARGIN_END + }) + } } - }.tabBar(this.TabBuilder(0)) - TabContent() { - applicationItem() - }.tabBar(this.TabBuilder(1)) - } - .barMode(BarMode.Fixed) - .barWidth(Constants.BAR_WIDTH) - .onChange((index) => { - this.currentIndex = index + + ListItem() { + List() { + ForEach( + this.getPermissionGroup(this.allGroupWithPermissions, Constants.OTHER_GROUP), + (item: GroupInfo) => { this.ListItemLayout(item) }, + (item: GroupInfo) => JSON.stringify(item) + ) + }.backgroundColor($r('sys.color.comp_background_list_card')) + .borderRadius($r('sys.float.ohos_id_corner_radius_card')) + .padding(Constants.PADDING_4) + .divider({ + strokeWidth: Constants.DIVIDER, + color: $r('sys.color.comp_divider'), + startMargin: Constants.MARGIN_52, + endMargin: Constants.DEFAULT_MARGIN_END + }) + }.margin({ bottom: Constants.MARGIN_24 }) + }.height(Constants.FULL_HEIGHT) + .borderRadius($r('sys.float.ohos_id_corner_radius_card')) + .clip(true) + }.padding({ + left: Constants.DEFAULT_PADDING_START, + right: Constants.DEFAULT_PADDING_END, }) - } else { - LoadingProgress().width(Constants.LOADING_WIDTH) } - }.height(Constants.FULL_HEIGHT) - } + .scrollBar(BarState.Off) + .margin({ top: Constants.MARGIN_8 }) + }.width(Constants.FULL_WIDTH) + }.tabBar(this.TabBuilder(0)) + TabContent() { + applicationItem() + }.tabBar(this.TabBuilder(1)) } + .barMode(BarMode.Fixed) + .barWidth(Constants.WIDTH_250) + .onChange((index) => { + this.currentIndex = index + }) + } else { + LoadingProgress().width(Constants.WIDTH_100) } - .layoutWeight(Constants.LAYOUT_WEIGHT) } + .layoutWeight(Constants.LAYOUT_WEIGHT) + .height(Constants.FULL_HEIGHT) } .height(Constants.FULL_HEIGHT) .width(Constants.FULL_WIDTH) @@ -541,21 +322,21 @@ struct authorityManagementPage { @Component struct applicationItem { - @State applicationItem: AppInfo[] = GlobalContext.load('allBundleInfo'); // application info array - @State searchResult: boolean = true; // search results + @State applicationItem: ManageAppInfo[] = GlobalContext.load('manageAppList'); + @State searchResult: boolean = true; @State selectedIndex: number = 0; @State isTouch: string = ''; scroller: Scroller = new Scroller(); - @Builder ListItemLayout(item: AppInfo) { + @Builder ListItemLayout(item: ManageAppInfo) { ListItem() { Row() { Column() { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Row() { Image(item.icon) - .customizeImage(Constants.APPLICATION_IMAGE_WIDTH, Constants.APPLICATION_IMAGE_HEIGHT) - .margin({ right: Constants.APPLICATION_IMAGE_MARGIN_RIGHT }) + .customizeImage(Constants.IMAGE_LENGTH_40, Constants.IMAGE_LENGTH_40) + .margin({ right: Constants.MARGIN_16 }) Text(item.label) .width(Constants.OFFSET) .maxLines(Constants.MAXIMUM_HEADER_LINES) @@ -564,23 +345,23 @@ struct applicationItem { .fontWeight(FontWeight.Medium) .fontColor($r('sys.color.font_primary')) .flexGrow(Constants.FLEX_GROW) - Text(String(item.groupId.length)) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + Text(String(item.groupWithPermission.size)) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) Text($r('app.string.right')) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .margin({ right: Constants.APPLICATION_TEXT_MARGIN_RIGHT }) + .margin({ right: Constants.MARGIN_4 }) SymbolGlyph($r('sys.symbol.chevron_forward')) - .width(Constants.IMAGE_WIDTH) - .height(Constants.IMAGE_HEIGHT) + .width(Constants.IMAGE_LENGTH_12) + .height(Constants.IMAGE_LENGTH_24) .fontSize(Constants.FONT_SIZE_18_vp) .fontColor([$r('sys.color.icon_tertiary')]) .fontWeight(FontWeight.Medium) } .width(Constants.FULL_WIDTH) - .height(Constants.AUTHORITY_ROW_HEIGHT) - .constraintSize({ minHeight: Constants.AUTHORITY_CONSTRAINTSIZE_MINHEIGHT }) + .height(Constants.HEIGHT_72) + .constraintSize({ minHeight: Constants.HEIGHT_72 }) } }.onClick(() => { GlobalContext.store('applicationInfo', item); @@ -614,14 +395,12 @@ struct applicationItem { build() { Column() { Row() { - textInput({ - applicationItem: $applicationItem, - searchResult: $searchResult - }) - }.padding({ - left: Constants.APPLICATION_TEXTINPUT_PADDING_LEFT, - top: Constants.APPLICATION_TEXTINPUT_PADDING_TOP, - right: Constants.APPLICATION_TEXTINPUT_PADDING_RIGHT + textInput({ applicationItem: $applicationItem, searchResult: $searchResult }) + } + .padding({ + left: Constants.DEFAULT_PADDING_START, + top: Constants.PADDING_8, + right: Constants.PADDING_24 }) Row() { Flex({ alignItems: ItemAlign.Start }) { @@ -631,23 +410,24 @@ struct applicationItem { Row() { Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Image($r('app.media.searchnoresult')) - .customizeImage(Constants.SEARCHNORESULT_IMAGE_WIDTH, Constants.SEARCHNORESULT_IMAGE_HEIGHT) + .customizeImage(Constants.IMAGE_LENGTH_200, Constants.IMAGE_LENGTH_200) } - }.margin({ top: Constants.MANAGEMENT_ROW_MARGIN_TOP }) - .padding({ left: Constants.MANAGEMENT_ROW_PADDING_LEFT }) + } + .margin({ top: Constants.DEFAULT_MARGIN_TOP }) + .padding({ left: Constants.DEFAULT_PADDING_START }) } else { Row() { List({ scroller: this.scroller }) { - ForEach(sortByName(this.applicationItem), (item: AppInfo) => { + ForEach(sortByName(this.applicationItem), (item: ManageAppInfo) => { this.ListItemLayout(item) - }, (item: AppInfo) => JSON.stringify(item)) + }, (item: ManageAppInfo) => JSON.stringify(item)) }.backgroundColor($r('sys.color.comp_background_list_card')) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding(Constants.LIST_PADDING_TOP) + .padding(Constants.PADDING_4) .divider({ strokeWidth: Constants.DIVIDER, color: $r('sys.color.comp_divider'), - startMargin: Constants.DIVIDER_MARGIN_RIGHT_APPLICATION, + startMargin: Constants.MARGIN_68, endMargin: Constants.DEFAULT_MARGIN_END }) .onScrollIndex((start, end) => { @@ -658,20 +438,20 @@ struct applicationItem { this.selectedIndex = index >= 0 ? index : 0; } }) - }.margin({ left: Constants.MANAGEMENT_ROW_PADDING_LEFT }) + } + .margin({ left: Constants.DEFAULT_MARGIN_START }) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) .clip(true) } }.height(Constants.FULL_HEIGHT) - }.margin({ top: Constants.MANAGEMENT_ROW_MARGIN_TOP, bottom: Constants.APPLICATION_LIST_MARGIN_BOTTOM }) + } + .margin({ top: Constants.DEFAULT_MARGIN_TOP, bottom: Constants.MARGIN_40 }) + Column() { alphabetIndexerComponent({ applicationItem: $applicationItem, index: $selectedIndex }) } - .margin({ - top: Constants.APPLICATION_ALPHABETINDEX_MARGIN_TOP, - bottom: Constants.APPLICATION_LIST_MARGIN_BOTTOM - }) - .width(Constants.APPLICATION_ALPHABETINDEX_WIDTH) + .width(Constants.WIDTH_24) + .margin({ top: Constants.DEFAULT_MARGIN_TOP, bottom: Constants.MARGIN_40 }) } } } diff --git a/permissionmanager/src/main/ets/pages/authority-secondary.ets b/permissionmanager/src/main/ets/pages/authority-secondary.ets index 280f0fc..c382a1f 100644 --- a/permissionmanager/src/main/ets/pages/authority-secondary.ets +++ b/permissionmanager/src/main/ets/pages/authority-secondary.ets @@ -71,14 +71,14 @@ struct appNameItem { .fontWeight(FontWeight.Medium) .flexGrow(Constants.FLEX_GROW) SymbolGlyph($r('sys.symbol.chevron_forward')) - .width(Constants.IMAGE_WIDTH) - .height(Constants.IMAGE_HEIGHT) + .width(Constants.IMAGE_LENGTH_12) + .height(Constants.IMAGE_LENGTH_24) .fontSize(Constants.FONT_SIZE_18_vp) .fontColor([$r('sys.color.icon_tertiary')]) .fontWeight(FontWeight.Medium) } .width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_ROW_HEIGHT) + .height(Constants.HEIGHT_48) } }.onClick(() => { let dataList = this.list.filter((ele) => { @@ -153,20 +153,21 @@ struct appNameItem { } } .width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_ROW_HEIGHT) + .height(Constants.HEIGHT_48) .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) } }.backgroundColor($r('sys.color.comp_background_list_card')) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding(Constants.LIST_PADDING_TOP) + .padding(Constants.PADDING_4) .divider({ strokeWidth: Constants.DIVIDER, color: $r('sys.color.comp_divider'), startMargin: Constants.DEFAULT_MARGIN_START, endMargin: Constants.DEFAULT_MARGIN_END }) - }.margin({ top: Constants.ROW_MARGIN_TOP }) - .padding({ left: Constants.LIST_PADDING_LEFT, right: Constants.DEFAULT_PADDING_END }) + } + .margin({ top: Constants.MARGIN_9 }) + .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) } .width(Constants.FULL_WIDTH) .height(Constants.FULL_HEIGHT) diff --git a/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets b/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets index 4e1a465..d7ec412 100644 --- a/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets +++ b/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets @@ -163,7 +163,7 @@ struct applicationItem { private isMuteSupported: boolean | undefined = (this.getUIContext().getRouter().getParams() as RouterParams1).isMuteSupported; @State globalIsOn: boolean = (this.getUIContext().getRouter().getParams() as RouterParams1).globalIsOn ?? true; - @State permissionNum: number = Constants.PERMISSION_NUM; // permission num + @State permissionNum: number = 0; @State toggleIsOn: boolean[] = []; // toggle switch state array @State isRisk: boolean[] = []; @State isFirst: boolean[] = []; @@ -209,10 +209,10 @@ struct applicationItem { Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Column() { Text(this.currentGroup == 'CAMERA' ? $r('app.string.close_camera') : $r('app.string.close_microphone')) - .fontSize(Constants.TEXT_BIG_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_20) .fontColor($r('sys.color.font_primary')) .fontWeight(FontWeight.Medium) - .lineHeight(Constants.TEXT_BIG_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_28) .width(Constants.FULL_WIDTH) .padding({ top: Constants.PADDING_14, bottom: Constants.PADDING_14 }) Text( @@ -222,7 +222,7 @@ struct applicationItem { ) .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) .fontColor($r('sys.color.font_primary')) - .lineHeight(Constants.TEXT_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_22) } .clip(true) } @@ -236,10 +236,10 @@ struct applicationItem { Row() { Image(item.icon) .objectFit(ImageFit.Contain) - .width(Constants.AUTHORITY_IMAGE_WIDTH) - .height(Constants.AUTHORITY_IMAGE_HEIGHT) + .width(Constants.IMAGE_LENGTH_40) + .height(Constants.IMAGE_LENGTH_40) .draggable(false) - .margin({ right: Constants.AUTHORITY_IMAGE_MARGIN_RIGHT }) + .margin({ right: Constants.MARGIN_16 }) Column() { Text(item.label) .width(Constants.MAXIMUM_HEADER_WIDTH) @@ -250,7 +250,7 @@ struct applicationItem { .fontColor($r('sys.color.font_primary')) if (this.isRisk[item.index]) { Text($r('app.string.risk_warning')) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) } }.flexGrow(Constants.FLEX_GROW) @@ -260,8 +260,8 @@ struct applicationItem { .selectedColor($r('sys.color.icon_emphasize')) .switchPointColor($r('sys.color.comp_background_primary_contrary')) .padding({ right: 0 }) - .width(Constants.AUTHORITY_TOGGLE_WIDTH) - .height(Constants.AUTHORITY_TOGGLE_HEIGHT) + .width(Constants.WIDTH_36) + .height(Constants.HEIGHT_20) .onChange((isOn: boolean) => { if (item.permission === undefined) { return; @@ -308,26 +308,26 @@ struct applicationItem { Span($r('app.string.ban')) } } - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) - .fontColor($r('sys.color.font_secondary')) - .margin({ right: Constants.AUTHORITY_IMAGE_MARGIN_RIGHT }) + .fontSize(Constants.FONT_SIZE_14) + .fontColor($r('sys.color.font_secondary')) + .margin({ right: Constants.MARGIN_16 }) } else { Text(locationStatus[this.polymorphismIsOn[item.index]]) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .margin({ right: Constants.AUTHORITY_IMAGE_MARGIN_RIGHT }) + .margin({ right: Constants.MARGIN_16 }) } SymbolGlyph($r('sys.symbol.chevron_forward')) - .width(Constants.IMAGE_WIDTH) - .height(Constants.IMAGE_HEIGHT) + .width(Constants.IMAGE_LENGTH_12) + .height(Constants.IMAGE_LENGTH_24) .fontSize(Constants.FONT_SIZE_18_vp) .fontColor([$r('sys.color.icon_tertiary')]) .fontWeight(FontWeight.Medium) } } .width(Constants.FULL_WIDTH) - .height(Constants.AUTHORITY_ROW_HEIGHT) - .constraintSize({ minHeight: Constants.AUTHORITY_CONSTRAINTSIZE_MINHEIGHT }) + .height(Constants.HEIGHT_72) + .constraintSize({ minHeight: Constants.HEIGHT_72 }) } }.onClick(() => { if (polymorphismGroup.indexOf(this.currentGroup) !== -1) { @@ -506,7 +506,7 @@ struct applicationItem { continue; } verifyAccessToken(bundleInfo.tokenId, this.list[j].permission).then((access) => { - if (Number(access) === Constants.PERMISSION_INDEX) { + if (Number(access) === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { if (boole) { this.toggleIsOn[i] = true; this.isFirst[i] = true; @@ -554,9 +554,10 @@ struct applicationItem { applicationItem: $applicationList, searchResult: $searchResult }) - }.padding({ - left: Constants.AUTHORITY_TEXTINPUT_PADDING_LEFT, - right: Constants.AUTHORITY_TEXTINPUT_PADDING_RIGHT + } + .padding({ + left: Constants.DEFAULT_PADDING_START, + right: Constants.PADDING_24 }) Flex({ alignItems:ItemAlign.Start, justifyContent: FlexAlign.Start }) { Column() { @@ -582,12 +583,14 @@ struct applicationItem { .width(Constants.DEFAULT_SLIDER_WIDTH).height(Constants.DEFAULT_SLIDER_HEIGHT) .position({ x: this.globalIsOn ? 0 : Constants.OFFSET, y: 0 }) }.clip(true) - }.height(Constants.LISTITEM_ROW_HEIGHT) + } + .height(Constants.HEIGHT_48) .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) - }.padding({ top: Constants.LIST_PADDING_TOP, bottom: Constants.LIST_PADDING_BOTTOM }) + } + .padding({ top: Constants.PADDING_4, bottom: Constants.PADDING_4 }) .backgroundColor($r('sys.color.comp_background_list_card')) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .margin({ top: Constants.TERTIARY_ROW_MARGIN_TOP }) + .margin({ top: Constants.MARGIN_24 }) } Flex({ justifyContent: FlexAlign.Start }) { if (this.globalIsOn) { @@ -597,14 +600,14 @@ struct applicationItem { $r(this.groupInfo.enableDescription, String(this.getGrantApplicationNumber())) : '' ) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .margin({ top: Constants.AUTHORITY_TEXT_MARGIN_TOP }) + .margin({ top: Constants.MARGIN_24 }) } else { Text(this.groupInfo.forbiddenDescription) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .margin({ top: Constants.AUTHORITY_TEXT_MARGIN_TOP }) + .margin({ top: Constants.MARGIN_24 }) } } else { Text( @@ -612,12 +615,12 @@ struct applicationItem { $r('app.string.camera_is_off') : $r('app.string.microphone_is_off') ) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .margin({ top: Constants.AUTHORITY_TEXT_MARGIN_TOP }) + .margin({ top: Constants.MARGIN_24 }) } }.padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) - .margin({ bottom: Constants.AUTHORITY_ROW_MARGIN_BOTTOM }) + .margin({ bottom: Constants.MARGIN_24 }) Row() { Column() { if (!this.applicationList.length) { @@ -628,8 +631,8 @@ struct applicationItem { Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Image($r('app.media.searchnoresult')) .objectFit(ImageFit.Contain) - .width(Constants.SEARCHNORESULT_IMAGE_WIDTH) - .height(Constants.SEARCHNORESULT_IMAGE_HEIGHT) + .width(Constants.IMAGE_LENGTH_200) + .height(Constants.IMAGE_LENGTH_200) .draggable(false) } } @@ -643,11 +646,11 @@ struct applicationItem { } .backgroundColor($r('sys.color.comp_background_list_card')) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding(Constants.LIST_PADDING_TOP) + .padding(Constants.PADDING_4) .divider({ strokeWidth: Constants.DIVIDER, color: $r('sys.color.comp_divider'), - startMargin: Constants.DIVIDER_MARGIN_RIGHT_APPLICATION, + startMargin: Constants.MARGIN_68, endMargin: Constants.DEFAULT_MARGIN_END }) .onScrollIndex((start, end) => { @@ -663,16 +666,18 @@ struct applicationItem { }.width(Constants.FULL_WIDTH) .margin({ bottom: globalGroup.includes(this.currentGroup) && this.isMuteSupported === true ? - Constants.AUTHORITY_LIST_MARGIN_BOTTOM_GLOBAL : - Constants.AUTHORITY_LIST_MARGIN_BOTTOM + Constants.MARGIN_176 : Constants.MARGIN_96 }) } - }.padding({ left: Constants.AUTHORITY_LISTITEM_PADDING_LEFT }) + } + .padding({ left: Constants.DEFAULT_PADDING_START }) + Column() { alphabetIndexerComponent({ applicationItem: $applicationList, index: $selectedIndex }) - }.width(Constants.AUTHORITY_ALPHABETINDEX_WIDTH) - .padding({ top: Constants.AUTHORITY_ALPHABETINDEX_PADDING_TOP }) - .margin({ bottom: Constants.APPLICATION_LIST_MARGIN_BOTTOM }) + } + .width(Constants.WIDTH_24) + .padding({ top: Constants.PADDING_16 }) + .margin({ bottom: Constants.MARGIN_40 }) }.flexGrow(Constants.FLEX_GROW) }.height(Constants.FULL_HEIGHT) } diff --git a/permissionmanager/src/main/ets/pages/authority-tertiary.ets b/permissionmanager/src/main/ets/pages/authority-tertiary.ets index 3f17017..8992ef9 100644 --- a/permissionmanager/src/main/ets/pages/authority-tertiary.ets +++ b/permissionmanager/src/main/ets/pages/authority-tertiary.ets @@ -75,7 +75,7 @@ struct locationInfoPage { struct applicationItem { private list: PermissionApplications[] = (this.getUIContext().getRouter().getParams() as RouterParams2).list; private permissionName: Permission = (this.getUIContext().getRouter().getParams() as RouterParams2).permissionName; - @State permissionNum: number = Constants.PERMISSION_NUM; // permission num + @State permissionNum: number = 0; @State toggleIsOn: boolean[] = []; // toggle switch state array @State isRisk: boolean[] = []; @State isFirst: boolean[] = []; @@ -93,8 +93,8 @@ struct applicationItem { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Row() { Image(item.icon) - .customizeImage(Constants.AUTHORITY_IMAGE_WIDTH, Constants.AUTHORITY_IMAGE_HEIGHT) - .margin({ right: Constants.AUTHORITY_IMAGE_MARGIN_RIGHT }) + .customizeImage(Constants.IMAGE_LENGTH_40, Constants.IMAGE_LENGTH_40) + .margin({ right: Constants.MARGIN_16 }) Column() { Text(item.label) .width(Constants.MAXIMUM_HEADER_WIDTH) @@ -105,7 +105,7 @@ struct applicationItem { .fontColor($r('sys.color.font_primary')) if (this.isRisk[item.index]) { Text($r('app.string.risk_warning')) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) } }.flexGrow(Constants.FLEX_GROW) @@ -114,8 +114,8 @@ struct applicationItem { .selectedColor($r('sys.color.icon_emphasize')) .switchPointColor($r('sys.color.comp_background_primary_contrary')) .padding({ right: 0 }) - .width(Constants.AUTHORITY_TOGGLE_WIDTH) - .height(Constants.AUTHORITY_TOGGLE_HEIGHT) + .width(Constants.WIDTH_36) + .height(Constants.HEIGHT_20) .onChange((isOn: boolean) => { if (item.permission === undefined) { return; @@ -133,8 +133,8 @@ struct applicationItem { }) } .width(Constants.FULL_WIDTH) - .height(Constants.AUTHORITY_ROW_HEIGHT) - .constraintSize({ minHeight: Constants.AUTHORITY_CONSTRAINTSIZE_MINHEIGHT }) + .height(Constants.HEIGHT_72) + .constraintSize({ minHeight: Constants.HEIGHT_72 }) } }.onClick(() => { }) @@ -206,7 +206,7 @@ struct applicationItem { ); verifyAccessToken(bundleInfo.tokenId, this.list[0].permission).then(data => { // 0: have permission; -1: no permission - if (data === Constants.PERMISSION_INDEX) { + if (data === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { this.toggleIsOn[i] = true; this.isFirst[i] = true; this.permissionNum++; @@ -237,9 +237,10 @@ struct applicationItem { applicationItem: $applicationList, searchResult: $searchResult }) - }.padding({ - left: Constants.AUTHORITY_TEXTINPUT_PADDING_LEFT, - right: Constants.AUTHORITY_TEXTINPUT_PADDING_RIGHT + } + .padding({ + left: Constants.DEFAULT_PADDING_START, + right: Constants.PADDING_24 }) Flex({ alignItems:ItemAlign.Start, justifyContent: FlexAlign.Start }) { Column() { @@ -250,17 +251,17 @@ struct applicationItem { $r(this.permissionInfo.enableDescription, String(this.permissionNum)) : '' ) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .margin({ top: Constants.AUTHORITY_TEXT_MARGIN_TOP }) + .margin({ top: Constants.MARGIN_24 }) } else { Text(this.permissionInfo?.forbiddenDescription) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .margin({ top: Constants.AUTHORITY_TEXT_MARGIN_TOP }) + .margin({ top: Constants.MARGIN_24 }) } }.padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) - .margin({ bottom: Constants.AUTHORITY_ROW_MARGIN_BOTTOM }) + .margin({ bottom: Constants.MARGIN_24 }) Row() { Column() { if (!this.applicationList.length) { @@ -270,7 +271,7 @@ struct applicationItem { Row() { Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Image($r('app.media.searchnoresult')) - .customizeImage(Constants.SEARCHNORESULT_IMAGE_WIDTH, Constants.SEARCHNORESULT_IMAGE_HEIGHT) + .customizeImage(Constants.IMAGE_LENGTH_200, Constants.IMAGE_LENGTH_200) } } } @@ -283,11 +284,11 @@ struct applicationItem { } .backgroundColor($r('sys.color.comp_background_list_card')) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding({ top: Constants.LIST_PADDING_TOP, bottom: Constants.LIST_PADDING_BOTTOM }) + .padding({ top: Constants.PADDING_4, bottom: Constants.PADDING_4 }) .divider({ strokeWidth: Constants.DIVIDER, color: $r('sys.color.comp_divider'), - startMargin: Constants.DIVIDER_MARGIN_RIGHT_APPLICATION, + startMargin: Constants.MARGIN_68, endMargin: Constants.DEFAULT_MARGIN_END }) .onScrollIndex((start, end) => { @@ -301,14 +302,17 @@ struct applicationItem { } } }.width(Constants.FULL_WIDTH) - .margin({ bottom: Constants.AUTHORITY_LIST_MARGIN_BOTTOM }) + .margin({ bottom: Constants.MARGIN_96 }) } - }.padding({ left: Constants.AUTHORITY_LISTITEM_PADDING_LEFT }) + } + .padding({ left: Constants.DEFAULT_PADDING_START }) + Column() { alphabetIndexerComponent({ applicationItem: $applicationList, index: $selectedIndex }) - }.width(Constants.AUTHORITY_ALPHABETINDEX_WIDTH) - .padding({ top: Constants.AUTHORITY_ALPHABETINDEX_PADDING_TOP }) - .margin({ bottom: Constants.APPLICATION_LIST_MARGIN_BOTTOM }) + } + .width(Constants.WIDTH_24) + .padding({ top: Constants.PADDING_16 }) + .margin({ bottom: Constants.MARGIN_40 }) }.flexGrow(Constants.FLEX_GROW) }.height(Constants.FULL_HEIGHT) } diff --git a/permissionmanager/src/main/ets/pages/dialogPlus.ets b/permissionmanager/src/main/ets/pages/dialogPlus.ets index 16b0697..1269c00 100644 --- a/permissionmanager/src/main/ets/pages/dialogPlus.ets +++ b/permissionmanager/src/main/ets/pages/dialogPlus.ets @@ -108,16 +108,16 @@ struct dialogPlusPage { Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Column() { Image(this.viewState.grantGroups[this.viewState.curIndex].icon) - .width(Constants.DIALOG_ICON_WIDTH) - .height(Constants.DIALOG_ICON_HEIGHT) + .width(Constants.IMAGE_LENGTH_24) + .height(Constants.IMAGE_LENGTH_24) .fillColor($r('sys.color.font_primary')) - .margin({ top: Constants.DIALOG_ICON_MARGIN_TOP }) + .margin({ top: Constants.MARGIN_24 }) if (this.viewState.grantGroups.length > 1) { Text(`${this.viewState.curIndex + 1} / ${this.viewState.grantGroups.length}`) - .fontSize(Constants.DIALOG_LABEL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_10) .fontColor($r('sys.color.font_secondary')) - .lineHeight(Constants.DIALOG_LABEL_LINE_HEIGHT) - .margin({ top: Constants.DIALOG_LABEL_MARGIN_TOP }) + .lineHeight(Constants.LINE_HEIGHT_14) + .margin({ top: Constants.MARGIN_2 }) } Scroll() { Column() { diff --git a/permissionmanager/src/main/ets/pages/globalSwitch.ets b/permissionmanager/src/main/ets/pages/globalSwitch.ets index 923aab1..781ad46 100644 --- a/permissionmanager/src/main/ets/pages/globalSwitch.ets +++ b/permissionmanager/src/main/ets/pages/globalSwitch.ets @@ -62,16 +62,16 @@ struct globalSwitch { Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { Column() { Text(this.viewState.title) - .fontSize(Constants.TEXT_BIG_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_20) .fontColor($r('sys.color.font_primary')) .fontWeight(FontWeight.Medium) - .lineHeight(Constants.TEXT_BIG_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_28) .width(Constants.FULL_WIDTH) .padding({ top: Constants.PADDING_14, bottom: Constants.PADDING_14 }) Text(this.viewState.text) .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) .fontColor($r('sys.color.font_primary')) - .lineHeight(Constants.TEXT_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_22) } .clip(true) } diff --git a/permissionmanager/src/main/ets/pages/permission-access-record.ets b/permissionmanager/src/main/ets/pages/permission-access-record.ets index 6e7a04b..b19f2ff 100644 --- a/permissionmanager/src/main/ets/pages/permission-access-record.ets +++ b/permissionmanager/src/main/ets/pages/permission-access-record.ets @@ -72,20 +72,23 @@ struct permissionRecordPage { $r('sys.color.icon_secondary') ) .fontWeight(this.currentIndex == index ? FontWeight.Bold : FontWeight.Regular) - .lineHeight(Constants.TEXT_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_22) .baselineOffset(Constants.TAB_DECORATION_POSITION_Y) if (this.currentIndex == index) { Text(index ? $r('app.string.application') : $r('app.string.permission')) .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) .fontWeight(FontWeight.Bold) - .lineHeight(Constants.TAB_LINE_HEIGHT) - .height(Constants.TAB_DECORATION_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_100) + .height(Constants.HEIGHT_2) .backgroundColor($r('sys.color.comp_background_emphasize')) } - }.height(Constants.TAB_HEIGHT) + } + .height(Constants.HEIGHT_56) .width(Constants.FULL_WIDTH) - .padding({ left: this.isVertical ? Constants.TAB_INNER_PADDING : Constants.DEFAULT_PADDING_START, - right: this.isVertical ? Constants.TAB_INNER_PADDING : Constants.DEFAULT_PADDING_END }) + .padding({ + left: this.isVertical ? Constants.PADDING_8 : Constants.DEFAULT_PADDING_START, + right: this.isVertical ? Constants.PADDING_8 : Constants.DEFAULT_PADDING_END + }) } @Builder PermissionListItemLayout(item: GroupRecordInfo, index: number) { @@ -96,10 +99,10 @@ struct permissionRecordPage { Row() { Image(item.icon) .fillColor($r('sys.color.icon_secondary')) - .customizeImage(Constants.MANAGEMENT_IMAGE_WIDTH, Constants.MANAGEMENT_IMAGE_HEIGHT) + .customizeImage(Constants.IMAGE_LENGTH_24, Constants.IMAGE_LENGTH_24) .margin({ - right: Constants.MANAGEMENT_IMAGE_MARGIN_RIGHT_RECORD, - left: Constants.MANAGEMENT_IMAGE_MARGIN_LEFT + right: Constants.MARGIN_24, + left: Constants.MARGIN_8 }) Column() { Text(item.groupName) @@ -109,20 +112,20 @@ struct permissionRecordPage { .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) .fontWeight(FontWeight.Medium) .fontColor($r('sys.color.font_primary')) - .lineHeight(Constants.TEXT_LINE_HEIGHT) - .margin({ bottom: Constants.TERTIARY_LABEL_MARGIN_BOTTOM }) + .lineHeight(Constants.LINE_HEIGHT_22) + .margin({ bottom: Constants.MARGIN_2 }) Text($r('app.string.visits', String(item.sum))) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .lineHeight(Constants.TEXT_SMALL_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_19) }.flexGrow(Constants.FLEX_GROW) .alignItems(HorizontalAlign.Start) Image(index == this.permissionIndex ? $r('app.media.xiangshangjiantou') : $r('app.media.xiangxiajiantou')) .fillColor($r('sys.color.icon_secondary')) - .customizeImage(Constants.IMAGE_WIDTH_RECORD, Constants.IMAGE_HEIGHT_RECORD) + .customizeImage(Constants.IMAGE_LENGTH_24, Constants.IMAGE_LENGTH_12) } .width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_HEIGHT_PERMISSION) + .height(Constants.HEIGHT_64) } }.onClick(() => { this.permissionIndex = this.permissionIndex == index ? -1 : index @@ -137,8 +140,8 @@ struct permissionRecordPage { ListItem() { Row() { Image(permissionApplication.icon) - .customizeImage(Constants.APPLICATION_IMAGE_WIDTH, Constants.APPLICATION_IMAGE_HEIGHT) - .margin({ right: Constants.MANAGEMENT_IMAGE_MARGIN_RIGHT }) + .customizeImage(Constants.IMAGE_LENGTH_40, Constants.IMAGE_LENGTH_40) + .margin({ right: Constants.MARGIN_16 }) Column() { Row().width(Constants.FULL_WIDTH).height(Constants.DIVIDER) .backgroundColor($r('sys.color.comp_divider')) @@ -150,23 +153,23 @@ struct permissionRecordPage { .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) .fontWeight(FontWeight.Medium) .fontColor($r('sys.color.font_primary')) - .lineHeight(Constants.TEXT_LINE_HEIGHT) - .margin({ bottom: Constants.TERTIARY_LABEL_MARGIN_BOTTOM }) + .lineHeight(Constants.LINE_HEIGHT_22) + .margin({ bottom: Constants.MARGIN_2 }) Text( $r('app.string.recent_visit', String(this.getAppRecords(permissionApplication, item.groupName, true)), this.getTime(this.getAppRecords(permissionApplication, item.groupName, false))) ) - .padding({ right: Constants.LISTITEM_PADDING_RIGHT_RECORD }) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .padding({ right: Constants.PADDING_50 }) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .lineHeight(Constants.TEXT_SMALL_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_19) }.alignItems(HorizontalAlign.Start) .height(Constants.FULL_HEIGHT) .width(Constants.FULL_WIDTH) .justifyContent(FlexAlign.Center) } - }.height(Constants.LISTITEM_HEIGHT_APPLICATION) + }.height(Constants.HEIGHT_72) .onClick(() => { let info: AppInfoSimple = new AppInfoSimple( permissionApplication.name, @@ -212,8 +215,9 @@ struct permissionRecordPage { } } } - }.padding(Constants.LIST_PADDING_TOP) - .margin({ bottom: Constants.LISTITEM_MARGIN_BOTTOM }) + } + .padding(Constants.PADDING_4) + .margin({ bottom: Constants.DEFAULT_MARGIN_BOTTOM }) .backgroundColor($r('sys.color.comp_background_list_card')) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) } @@ -225,8 +229,8 @@ struct permissionRecordPage { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Row() { Image(item.icon) - .customizeImage(Constants.APPLICATION_IMAGE_WIDTH, Constants.APPLICATION_IMAGE_HEIGHT) - .margin({ right: Constants.MANAGEMENT_IMAGE_MARGIN_RIGHT }) + .customizeImage(Constants.IMAGE_LENGTH_40, Constants.IMAGE_LENGTH_40) + .margin({ right: Constants.MARGIN_16 }) Column() { Text(item.groupName) .width(Constants.MAXIMUM_HEADER_WIDTH) @@ -235,17 +239,17 @@ struct permissionRecordPage { .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) .fontWeight(FontWeight.Medium) .fontColor($r('sys.color.font_primary')) - .lineHeight(Constants.TEXT_LINE_HEIGHT) - .margin({ bottom: Constants.TERTIARY_LABEL_MARGIN_BOTTOM }) + .lineHeight(Constants.LINE_HEIGHT_22) + .margin({ bottom: Constants.MARGIN_2 }) Row() { ForEach(item.permissions, (permission: AppGroupRecordInfo) => { Image(permission.icon) .fillColor($r('sys.color.icon_secondary')) .customizeImage( - Constants.IMAGE_WIDTH_RECORD_APPLICATION, - Constants.IMAGE_HEIGHT_RECORD_APPLICATION + Constants.IMAGE_LENGTH_16, + Constants.IMAGE_LENGTH_16 ) - .margin({ right: Constants.APPLICATION_TEXT_MARGIN_RIGHT }) + .margin({ right: Constants.MARGIN_4 }) }, (item: AppGroupRecordInfo) => JSON.stringify(item)) } }.flexGrow(Constants.FLEX_GROW) @@ -254,10 +258,10 @@ struct permissionRecordPage { index == this.applicationIndex ? $r('app.media.xiangshangjiantou') : $r('app.media.xiangxiajiantou') ) .fillColor($r('sys.color.icon_secondary')) - .customizeImage(Constants.IMAGE_WIDTH_RECORD, Constants.IMAGE_HEIGHT_RECORD) + .customizeImage(Constants.IMAGE_LENGTH_24, Constants.IMAGE_LENGTH_12) } .width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_HEIGHT_APPLICATION) + .height(Constants.HEIGHT_72) } }.onClick(() => { this.applicationIndex = this.applicationIndex == index ? -1 : index @@ -270,10 +274,10 @@ struct permissionRecordPage { Row() { Image(permission.icon) .fillColor($r('sys.color.icon_secondary')) - .customizeImage(Constants.MANAGEMENT_IMAGE_WIDTH, Constants.MANAGEMENT_IMAGE_HEIGHT) + .customizeImage(Constants.IMAGE_LENGTH_24, Constants.IMAGE_LENGTH_24) .margin({ - right: Constants.MANAGEMENT_IMAGE_MARGIN_RIGHT_RECORD, - left: Constants.MANAGEMENT_IMAGE_MARGIN_LEFT + right: Constants.MARGIN_24, + left: Constants.MARGIN_8 }) Column() { Row().width(Constants.FULL_WIDTH).height(Constants.DIVIDER) @@ -283,19 +287,19 @@ struct permissionRecordPage { .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) .fontWeight(FontWeight.Medium) .fontColor($r('sys.color.font_primary')) - .lineHeight(Constants.TEXT_LINE_HEIGHT) - .margin({ bottom: Constants.TERTIARY_LABEL_MARGIN_BOTTOM }) + .lineHeight(Constants.LINE_HEIGHT_22) + .margin({ bottom: Constants.MARGIN_2 }) Text($r('app.string.recent_visit', String(permission.count), this.getTime(permission.lastTime))) - .padding({ right: Constants.LISTITEM_PADDING_RIGHT_RECORD }) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .padding({ right: Constants.PADDING_50 }) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .lineHeight(Constants.TEXT_SMALL_LINE_HEIGHT) + .lineHeight(Constants.LINE_HEIGHT_19) }.alignItems(HorizontalAlign.Start) .height(Constants.FULL_HEIGHT) .width(Constants.FULL_WIDTH) .justifyContent(FlexAlign.Center) } - }.height(Constants.LISTITEM_HEIGHT_PERMISSION) + }.height(Constants.HEIGHT_64) .onClick(() => { let info: AppInfoSimple = new AppInfoSimple( item.name, @@ -341,8 +345,9 @@ struct permissionRecordPage { } } } - }.padding(Constants.LIST_PADDING_TOP) - .margin({ bottom: Constants.LISTITEM_MARGIN_BOTTOM }) + } + .padding(Constants.PADDING_4) + .margin({ bottom: Constants.DEFAULT_MARGIN_BOTTOM }) .backgroundColor($r('sys.color.comp_background_list_card')) .borderRadius($r('sys.float.ohos_id_corner_radius_card')) } @@ -365,11 +370,12 @@ struct permissionRecordPage { Flex({ justifyContent: FlexAlign.Start }) { Text($r('app.string.record_time_limit')) .margin({ left: Constants.DEFAULT_MARGIN_START }) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) - .lineHeight(Constants.SUBTITLE_LINE_HEIGHT) - }.constraintSize({ minHeight: Constants.SUBTITLE_MIN_HEIGHT }) - .padding({ top: Constants.SUBTITLE_PADDING_TOP, bottom: Constants.SUBTITLE_PADDING_BOTTOM }) + .lineHeight(Constants.LINE_HEIGHT_24) + } + .constraintSize({ minHeight: Constants.HEIGHT_48 }) + .padding({ top: Constants.PADDING_16, bottom: Constants.PADDING_8 }) if (this.groups.length) { Stack() { Tabs() { @@ -382,13 +388,15 @@ struct permissionRecordPage { ForEach(this.groups, (item: GroupRecordInfo, index) => { this.PermissionListItemLayout(item, index as number) }, (item: GroupRecordInfo) => JSON.stringify(item)) - }.padding({ top: Constants.LIST_PADDING_TOP, bottom: Constants.LIST_PADDING_BOTTOM }) + } + .padding({ top: Constants.PADDING_4, bottom: Constants.PADDING_4 }) .height(Constants.FULL_HEIGHT) - }.padding({ - left: Constants.MANAGEMENT_ROW_PADDING_LEFT, - right: Constants.MANAGEMENT_ROW_PADDING_RIGHT, - top: Constants.MANAGEMENT_ROW_PADDING_TOP, - bottom: Constants.MANAGEMENT_ROW_PADDING_BOTTOM + } + .padding({ + left: Constants.DEFAULT_PADDING_START, + right: Constants.DEFAULT_PADDING_END, + top: Constants.MARGIN_8, + bottom: Constants.MARGIN_50 }) }.scrollBar(BarState.Off) }.width(Constants.FULL_WIDTH) @@ -405,14 +413,15 @@ struct permissionRecordPage { this.ApplicationListItemLayout(item, index as number) }, (item: AppRecordInfo) => JSON.stringify(item)) } - .padding({ top: Constants.LIST_PADDING_TOP, bottom: Constants.LIST_PADDING_BOTTOM }) + .padding({ top: Constants.PADDING_4, bottom: Constants.PADDING_4 }) .height(Constants.FULL_HEIGHT) } - }.padding({ - left: Constants.MANAGEMENT_ROW_PADDING_LEFT, - right: Constants.MANAGEMENT_ROW_PADDING_RIGHT, - top: Constants.MANAGEMENT_ROW_PADDING_TOP, - bottom: Constants.MANAGEMENT_ROW_PADDING_BOTTOM + } + .padding({ + left: Constants.DEFAULT_PADDING_START, + right: Constants.DEFAULT_PADDING_END, + top: Constants.MARGIN_8, + bottom: Constants.MARGIN_50 }) }.scrollBar(BarState.Off) }.width(Constants.FULL_WIDTH) @@ -420,7 +429,7 @@ struct permissionRecordPage { }.tabBar(this.TabBuilder(1)) } .barMode(BarMode.Fixed) - .barWidth(Constants.BAR_WIDTH) + .barWidth(Constants.WIDTH_250) .onChange((index) => { this.currentIndex = index; if (!this.show) { @@ -433,10 +442,11 @@ struct permissionRecordPage { justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, direction: FlexDirection.Column }) { Image($r('app.media.noRecord')) - .customizeImage(Constants.NORECORD_IMAGE_WIDTH, Constants.NORECORD_IMAGE_HEIGHT) - .margin({ left: Constants.NORECORD_IMAGE_MARGIN_LEFT }) - Text($r('app.string.no_record')).margin({ top: Constants.DIALOG_REQ_MARGIN_TOP }) - .fontSize(Constants.TEXT_SMALL_FONT_SIZE) + .customizeImage(Constants.IMAGE_LENGTH_120, Constants.IMAGE_LENGTH_120) + .margin({ left: Constants.MARGIN_40 }) + Text($r('app.string.no_record')) + .margin({ top: Constants.MARGIN_16 }) + .fontSize(Constants.FONT_SIZE_14) .fontColor($r('sys.color.font_secondary')) }.width(Constants.FULL_WIDTH).height(Constants.FULL_HEIGHT) .padding({ bottom: Constants.RECORD_PADDING_BOTTOM }) diff --git a/permissionmanager/src/main/module.json b/permissionmanager/src/main/module.json index 2d19d18..8b30d96 100644 --- a/permissionmanager/src/main/module.json +++ b/permissionmanager/src/main/module.json @@ -30,7 +30,7 @@ "name": "com.ohos.permissionmanager.MainAbility", "startWindowBackground": "$color:default_background_color", "startWindowIcon": "$media:app_icon", - "srcEntry": "./ets/MainAbility/MainAbility.ts", + "srcEntry": "./ets/MainAbility/MainAbility.ets", "description": "manage the permissions of all applications from the permission and application dimensions", "icon": "$media:app_icon", "label": "$string:permission_manager", diff --git a/permissionmanager/src/main/module.json5 b/permissionmanager/src/main/module.json5 index 3f17053..7040cdb 100644 --- a/permissionmanager/src/main/module.json5 +++ b/permissionmanager/src/main/module.json5 @@ -42,7 +42,7 @@ "name": "com.ohos.permissionmanager.MainAbility", "startWindowBackground": "$color:default_background_color", "startWindowIcon": "$media:app_icon", - "srcEntry": "./ets/MainAbility/MainAbility.ts", + "srcEntry": "./ets/MainAbility/MainAbility.ets", "description": "manage the permissions of all applications from the permission and application dimensions", "icon": "$media:app_icon", "label": "$string:permission_manager", -- Gitee