From c3f79a51e400d9eebbaa3cd734a157a5cdc2893c Mon Sep 17 00:00:00 2001 From: fanchenxuan Date: Mon, 21 Mar 2022 20:05:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BD=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fanchenxuan --- .../GrantAbility/common/components/dialog.ets | 31 +++-- .../pages/application-secondary.ets | 46 ++++--- .../pages/authority-management.ets | 30 ++--- .../pages/authority-tertiary-groups.ets | 117 ++++++++++-------- 4 files changed, 128 insertions(+), 96 deletions(-) diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/components/dialog.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/components/dialog.ets index 8b816b481..08b2d9c30 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/components/dialog.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/GrantAbility/common/components/dialog.ets @@ -117,15 +117,7 @@ export struct privacyDialog { ret = Constants.RESULT_FAILURE } console.log(TAG + "code:" + ret + ", result=" + JSON.stringify(this.result)) - featureAbility.terminateSelfWithResult({ - resultCode: ret, - want: { - parameters: { - "ohos.user.grant.permission": this.reqPerms, - "ohos.user.grant.permission.result": this.result - } - } - }) + this.answer(ret, this.reqPerms) } verify() { @@ -183,6 +175,27 @@ export struct privacyDialog { this.initStatus = Constants.INIT_NEED_TO_VERIFY } + answer(ret, reqPerms) { + console.log(TAG + "code:" + ret + ", perms="+ JSON.stringify(reqPerms) +", result=" + JSON.stringify(this.result)) + var perms = [] + var results = [] + reqPerms.forEach(perm => { + perms.push(perm) + }) + this.result.forEach(result => { + results.push(result) + }) + featureAbility.terminateSelfWithResult({ + resultCode: ret, + want: { + parameters: { + "ohos.user.grant.permission": perms, + "ohos.user.grant.permission.result": results + } + } + }) + } + aboutToAppear() { this.count = 0; this.initStatus = Constants.INIT_NEED_TO_WAIT diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/application-secondary.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/application-secondary.ets index 4ec9944b5..baea56ee8 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/application-secondary.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/application-secondary.ets @@ -23,18 +23,19 @@ var TAG = 'PermissionManager_MainAbility:' const allowedStatus = 0; // Status: Allowed const bannedStatus = 1; // Status: Banned + class AllowedObj { groupName: string; - permission: string; - constructor(groupName: string, permission: string) { + permission: string[]; + constructor(groupName: string, permission: string[]) { this.groupName = groupName; this.permission = permission; } } // Class Allowed class BannedObj { groupName: string; - permission: string; - constructor(groupName: string, permission: string) { + permission: string[]; + constructor(groupName: string, permission: string[]) { this.groupName = groupName; this.permission = permission; } @@ -134,28 +135,39 @@ struct appNamePlusPage { * Initialize permission status information and group permission information */ async initialPermissions() { - var reqGroups = this.routerData.permissions; - if (!reqGroups.length) { + var reqPermissions = this.routerData.permissions; + var reqGroupIds = this.routerData.groupId; + + if (!reqGroupIds.length) { this.allowedListItem = []; this.bannedListItem = []; return; } - var ids = this.routerData.groupId; - for (var i = 0; i < reqGroups.length; i++) { - var isGranted = true; - var reqPermissions = groups[ids[i]].permissions; - for (var j = 0; j < reqPermissions.length; j++) { - var res = await abilityAccessCtrl.createAtManager().verifyAccessToken( - this.routerData.tokenId, reqPermissions[j]); + + for (let i = 0; i < reqGroupIds.length; i++) { + let id = reqGroupIds[i]; + let groupName = groups[id].groupName; + let groupReqPermissons = []; + for (let j = 0; j < reqPermissions.length; j++) { + let permission = reqPermissions[j]; + if (groups[id].permissions.indexOf(permission) != -1) { + groupReqPermissons.push(permission) + } + } + let isGranted = true; + for (let i = 0; i < groupReqPermissons.length; i++) { + let permission = groupReqPermissons[i] + let res = await abilityAccessCtrl.createAtManager().verifyAccessToken( + this.routerData.tokenId, permission); if (res != 0) { isGranted = false; - break; } } + if (isGranted) { - this.allowedListItem.push(new AllowedObj(groups[ids[i]].groupName, reqPermissions)); + this.allowedListItem.push(new AllowedObj(groupName, groupReqPermissons)); } else { - this.bannedListItem.push(new BannedObj(groups[ids[i]].groupName, reqPermissions)); + this.bannedListItem.push(new BannedObj(groupName, groupReqPermissons)); } } } @@ -164,6 +176,7 @@ struct appNamePlusPage { * Lifecycle function, triggered once when this page is displayed */ onPageShow() { + console.log(TAG + 'onPageShow') this.initialPermissions(); } @@ -171,6 +184,7 @@ struct appNamePlusPage { * Lifecycle function, triggered once when this page disappears */ onPageHide() { + console.log(TAG + 'onPageHide') setTimeout(()=> { this.allowedListItem = []; this.bannedListItem = []; diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-management.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-management.ets index 318e24e6a..e84ee6253 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-management.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-management.ets @@ -90,27 +90,21 @@ struct authorityManagementPage { } } }.onClick(() => { - if (item.groupName === '其他权限') { + if (item.groupName === '其他权限' || item.groupName === '电话' || item.groupName === '通讯录' || item.groupName === '信息' + || item.groupName === '通话记录' || item.groupName === '日历') { router.push({ uri: 'pages/authority-secondary', params: { routerData: this.allPermissionApplications, backTitle: item.groupName } }) - }else if((item.groupName === '电话' || item.groupName === '通讯录' || item.groupName === '信息' - || item.groupName === '通话记录' || item.groupName === '日历')){ - router.push({ - uri: 'pages/authority-secondary', - params: { routerData: this.allPermissionApplications, backTitle: item.groupName } + } else { + var dataList = this.allPermissionApplications.filter((ele) => { + return ele.groupName === item.group }) - }else { - var dataList = this.allPermissionApplications.filter((ele) => { - return ele.groupName === item.group - }) - - router.push({ - uri: 'pages/authority-tertiary-groups', - params: { routerData: dataList, backTitle: item.groupName } - }) + router.push({ + uri: 'pages/authority-tertiary-groups', + params: { routerData: dataList, backTitle: item.groupName } + }) } }) } @@ -183,6 +177,7 @@ struct authorityManagementPage { entities: ["entity.system.home"] }, bundle.BundleFlag.GET_ABILITY_INFO_WITH_APPLICATION, Constants.USERID); } catch(e) { + console.log(TAG + 'queryAbilityByWant catch error: ' + JSON.stringify(e)) continue; } this.deduplicationPermissions(info, allPermissions, allApplicationPermissions); @@ -241,7 +236,7 @@ struct authorityManagementPage { var icon: string = permissionGroup.icon; var bundleNames: string[] = []; for (let j = 0; j < this_.allApplicationPermissions.length; j++) { - if (this_.allApplicationPermissions[j].permissions.indexOf(permissionGroup.name) != -1) { + if (this_.allApplicationPermissions[j].permissions.indexOf(this_.allUserPermissions[i]) != -1) { bundleNames.push(this_.allApplicationPermissions[j].bundleName); } } @@ -363,7 +358,7 @@ struct authorityManagementPage { 'tokenId': info.appInfo.accessTokenId, 'iconId': info.appInfo.iconId, 'labelId': info.appInfo.labelId, - 'permissions': dePermissions, + 'permissions': reqUserPermissions, 'groupId': groupIds }; allApplicationPermissions.push(ap); @@ -416,6 +411,7 @@ struct authorityManagementPage { * Lifecycle function, executed when the page is initialized */ aboutToAppear() { + console.log(TAG + 'on aboutToAppear, version 1.01'); this.getAllBundlePermissions(this.allPermissions, this.allApplicationPermissions); } diff --git a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary-groups.ets b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary-groups.ets index b2dfa6ab7..4a1335120 100644 --- a/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary-groups.ets +++ b/frameworks/com.ohos.permissionmanager/permissionmanager/src/main/ets/MainAbility/pages/authority-tertiary-groups.ets @@ -254,62 +254,71 @@ struct applicationItem { * Lifecycle function, executed when the page is initialized */ aboutToAppear() { - for (let i = 0; i < routerData[0].bundleNames.length; i++) { + var bundleNames = [] + routerData.forEach(permissionmanager => { + permissionmanager.bundleNames.forEach( bundleName => { + if (bundleNames.indexOf(bundleName) == -1) { + bundleNames.push(bundleName) + } + }) + }) + for (let i = 0; i < bundleNames.length; i++) { // Get BundleInfo based on bundle name - bundle.getBundleInfo(routerData[0].bundleNames[i], Constants.PARMETER_BUNDLE_FLAG).then(res => { - Promise.all([getAppLabel(res.appInfo.labelId, res.name), - getAppIcon(res.appInfo.iconId, res.name), - verifyAccessToken(res.appInfo.accessTokenId, routerData[0].permission) - ]) - .then((values) => { - this.applicationList.push( - new ApplicationObj( - String(values[0]), - String(values[1]), - i, - res.appInfo.accessTokenId, - routerData[0].permission, - makePy(values[0])[0].slice(0, 1)) // Get the first letter in the returned initials array - ); - this.oldApplicationItem.push( - new ApplicationObj( - String(values[0]), - String(values[1]), - i, - res.appInfo.accessTokenId, - routerData[0].permission, - makePy(values[0])[0].slice(0, 1)) // Get the first letter in the returned initials array - ); - this.applicationList.sort((a,b) => a.index - b.index) - this.oldApplicationItem.sort((a,b) => a.index - b.index) - }); - // 0: have permission; -1: no permission - var boole = true; - this.permissionNum++; - for (let j = 0; j < routerData.length; j++) { - verifyAccessToken(res.appInfo.accessTokenId, routerData[j].permission).then((access) => { - if (Number(access) === Constants.PERMISSION_INDEX) { - if(boole){ - this.toggleIsOn[i] = true; - } - } else { - if(boole){ - this.permissionNum-- - } - boole = false; - this.toggleIsOn[i] = false; - } - }); + bundle.getBundleInfo(bundleNames[i], Constants.PARMETER_BUNDLE_FLAG).then(res => { + Promise.all([getAppLabel(res.appInfo.labelId, res.name), + getAppIcon(res.appInfo.iconId, res.name) + ]) + .then((values) => { + this.applicationList.push( + new ApplicationObj( + String(values[0]), + String(values[1]), + i, + res.appInfo.accessTokenId, + routerData[0].permission, + makePy(values[0])[0].slice(0, 1)) // Get the first letter in the returned initials array + ); + this.oldApplicationItem.push( + new ApplicationObj( + String(values[0]), + String(values[1]), + i, + res.appInfo.accessTokenId, + routerData[0].permission, + makePy(values[0])[0].slice(0, 1)) // Get the first letter in the returned initials array + ); + this.applicationList.sort((a,b) => a.index - b.index) + this.oldApplicationItem.sort((a,b) => a.index - b.index) + }); + // 0: have permission; -1: no permission + var boole = true; + this.permissionNum++; + for (let j = 0; j < routerData.length; j++) { + if (res.reqPermissions.indexOf(routerData[j].permission) == -1) { + continue } - }).catch(() => { - this.applicationList.push( - new ApplicationObj('', '', 0, '', '', '') - ); - this.oldApplicationItem.push( - new ApplicationObj('', '', 0, '', '', '') - ); - }) - + verifyAccessToken(res.appInfo.accessTokenId, routerData[j].permission).then((access) => { + if (Number(access) === Constants.PERMISSION_INDEX) { + if(boole){ + this.toggleIsOn[i] = true; + } + } else { + if(boole){ + this.permissionNum-- + } + boole = false; + this.toggleIsOn[i] = false; + } + }); + } + }).catch(() => { + this.applicationList.push( + new ApplicationObj('', '', 0, '', '', '') + ); + this.oldApplicationItem.push( + new ApplicationObj('', '', 0, '', '', '') + ); + }) } } -- Gitee