From 780416b4e5080b8bc1fbf87506cd8da244d56dd8 Mon Sep 17 00:00:00 2001 From: fanchenxuan Date: Thu, 29 Sep 2022 14:31:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E5=85=BC=E5=AE=B9API8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fanchenxuan --- .../main/ets/common/model/permissionGroup.ets | 13 +- .../src/main/ets/common/utils/constant.ets | 2 +- .../main/ets/pages/application-secondary.ets | 4 + .../main/ets/pages/application-tertiary.ets | 22 ++-- .../main/ets/pages/authority-management.ets | 9 +- .../ets/pages/authority-tertiary-groups.ets | 7 +- .../src/main/ets/pages/dialogPlus.ets | 111 +++++++++--------- 7 files changed, 89 insertions(+), 79 deletions(-) diff --git a/permissionmanager/src/main/ets/common/model/permissionGroup.ets b/permissionmanager/src/main/ets/common/model/permissionGroup.ets index 5a1f719..ed5ade7 100644 --- a/permissionmanager/src/main/ets/common/model/permissionGroup.ets +++ b/permissionmanager/src/main/ets/common/model/permissionGroup.ets @@ -21,13 +21,6 @@ export const permissionGroups: any[] = [ "description": "允许应用在后台运行时获取位置信息。", "groupId": 0 }, - { - "permissionName": "ohos.permission.APPROXIMATELY_LOCATION", - "groupName": "LOCATION", - "label": "模糊位置权限", - "description": "允许应用获取模糊位置信息。", - "groupId": 0 - }, { "permissionName": "ohos.permission.LOCATION", "groupName": "LOCATION", @@ -244,9 +237,8 @@ export const groups: any[] = [ "label": "访问位置信息?", "permissions": [ "ohos.permission.LOCATION_IN_BACKGROUND", - "ohos.permission.APPROXIMATELY_LOCATION" + "ohos.permission.LOCATION" ], - "specialPermission": 'ohos.permission.LOCATION', "isShow":true }, { @@ -421,7 +413,6 @@ export const groups: any[] = [ export const permissionGroupPermissions: object = { "LOCATION": [ "ohos.permission.LOCATION_IN_BACKGROUND", - "ohos.permission.APPROXIMATELY_LOCATION", "ohos.permission.LOCATION" ], "CAMERA": [ @@ -485,7 +476,6 @@ export const permissionGroupPermissions: object = { export const userGrantPermissions: string[] = [ "ohos.permission.LOCATION_IN_BACKGROUND", - "ohos.permission.APPROXIMATELY_LOCATION", "ohos.permission.LOCATION", "ohos.permission.CAMERA", "ohos.permission.MICROPHONE", @@ -519,7 +509,6 @@ export const userGrantPermissions: string[] = [ export const permissionGroupIds: object = { "ohos.permission.LOCATION_IN_BACKGROUND": "0", - "ohos.permission.APPROXIMATELY_LOCATION": "0", "ohos.permission.LOCATION": "0", "ohos.permission.CAMERA": "1", "ohos.permission.MICROPHONE": "2", diff --git a/permissionmanager/src/main/ets/common/utils/constant.ets b/permissionmanager/src/main/ets/common/utils/constant.ets index f40dab5..2ae88c2 100644 --- a/permissionmanager/src/main/ets/common/utils/constant.ets +++ b/permissionmanager/src/main/ets/common/utils/constant.ets @@ -273,7 +273,7 @@ export default class Constants { static PERMISSION_NUM = 0; static PERMISSION_FLAG = 2; - static API_VERSION_SUPPORT_STAGE = 9; + static API_VERSION_SUPPORT_STAGE = 10; static PRE_AUTHORIZATION_NOT_MODIFIED = 4; diff --git a/permissionmanager/src/main/ets/pages/application-secondary.ets b/permissionmanager/src/main/ets/pages/application-secondary.ets index 677adb3..eeb2f73 100644 --- a/permissionmanager/src/main/ets/pages/application-secondary.ets +++ b/permissionmanager/src/main/ets/pages/application-secondary.ets @@ -23,6 +23,7 @@ var TAG = 'PermissionManager_MainAbility:' const allowedStatus = 0; // Status: Allowed const bannedStatus = 1; // Status: Banned +const PRECISE_LOCATION_PERMISSION = 'ohos.permission.LOCATION' class permissionObj { groupName: string; permission: string[]; @@ -150,6 +151,9 @@ struct appNamePlusPage { let isGranted = true; for (let i = 0; i < groupReqPermissons.length; i++) { let permission = groupReqPermissons[i] + if(this.routerData.api >= Constants.API_VERSION_SUPPORT_STAGE && permission == PRECISE_LOCATION_PERMISSION) { + continue + } let res = await abilityAccessCtrl.createAtManager().verifyAccessToken( this.routerData.tokenId, permission); if (res != 0) { diff --git a/permissionmanager/src/main/ets/pages/application-tertiary.ets b/permissionmanager/src/main/ets/pages/application-tertiary.ets index edb9d9a..2e79799 100644 --- a/permissionmanager/src/main/ets/pages/application-tertiary.ets +++ b/permissionmanager/src/main/ets/pages/application-tertiary.ets @@ -130,7 +130,7 @@ struct mediaDocumentItem { }; // application info array @State isCheckList: boolean[] = []; // Permission status array @State accurateIsOn: boolean = true; - @State reqPermissions: any = [] + @State api: number = 0; authorizeDialogController: CustomDialogController = new CustomDialogController({ builder: authorizeDialog({ }), @@ -191,7 +191,7 @@ struct mediaDocumentItem { } let hasReason = false bundle.getBundleInfo(routerData, Constants.PARMETER_BUNDLE_FLAG).then(res => { - this.reqPermissions = res.reqPermissions + this.api = res.targetVersion bundleInfo = res permissions.forEach(permission => { res.reqPermissionDetails.forEach(reqPermissionDetail => { @@ -348,10 +348,10 @@ struct mediaDocumentItem { .height(Constants.LISTITEM_ROW_HEIGHT) .onClick(() => { item.permissions.forEach((permission) => { - if(permission == PRECISE_LOCATION_PERMISSION) { - return false - } if (!item.index) { + if((this.api >= Constants.API_VERSION_SUPPORT_STAGE) && (permission == PRECISE_LOCATION_PERMISSION)) { + return false + } this.grantUserGrantedPermission(item.accessTokenId, permission) if (nowGrantResult != Constants.PERMISSION_INDEX) { GrantResultFlag.push(-1) @@ -359,7 +359,15 @@ struct mediaDocumentItem { GrantResultFlag.push(0) } } else { - this.revokeUserGrantedPermission(item.accessTokenId, permission) + if((permission == PRECISE_LOCATION_PERMISSION) && (this.api >= Constants.API_VERSION_SUPPORT_STAGE)) { + if(this.accurateIsOn) { + this.revokeUserGrantedPermission(item.accessTokenId, permission) + this.accurateIsOn = false + } + }else { + this.revokeUserGrantedPermission(item.accessTokenId, permission) + } + if (nowRevokeResult != Constants.PERMISSION_INDEX) { RevokeResultFlag.push(-1) this.authorizeDialogController.open(); @@ -418,7 +426,7 @@ struct mediaDocumentItem { top: Constants.TERTIARY_LIST_PADDING_TOP, bottom: Constants.TERTIARY_LIST_PADDING_BOTTOM }) - if ((polymorphismGroup.indexOf(globalThis.currentPermissionGroup) !== -1) && (this.reqPermissions.includes(PRECISE_LOCATION_PERMISSION))) { + if ((this.api >= Constants.API_VERSION_SUPPORT_STAGE) && (permissions.includes(PRECISE_LOCATION_PERMISSION))) { Column() { Row() { Text($r('app.string.precise_location')) diff --git a/permissionmanager/src/main/ets/pages/authority-management.ets b/permissionmanager/src/main/ets/pages/authority-management.ets index 9076fd1..27a826e 100644 --- a/permissionmanager/src/main/ets/pages/authority-management.ets +++ b/permissionmanager/src/main/ets/pages/authority-management.ets @@ -34,6 +34,7 @@ var TAG = 'PermissionManager_MainAbility:' interface applicationPermissions { 'bundleName': string, + 'api': number, 'iconId': string, 'permissions': string[], 'labelId': string, @@ -58,6 +59,8 @@ interface groupPermission { let bundleInfosList: any[] = []; // Permission information array let textInput_placeholder: any = '' +const FUZZY_LOCATION_PERMISSION = 'ohos.permission.APPROXIMATELY_LOCATION' +const API_VERSION_SUPPORT_STAGE = 9 @Entry @Component @@ -359,6 +362,9 @@ struct authorityManagementPage { if (reqPermissionsLen > 0) { for (let j = 0; j < info.reqPermissions.length; j++) { var permission = info.reqPermissions[j]; + if((info.targetVersion < Constants.API_VERSION_SUPPORT_STAGE) && (permission == FUZZY_LOCATION_PERMISSION)) { + continue + } var flag = await acManager.getPermissionFlags(info.appInfo.accessTokenId, permission) if(flag == Constants.PRE_AUTHORIZATION_NOT_MODIFIED) { continue @@ -383,12 +389,13 @@ struct authorityManagementPage { } // adapt different api - if (info.compatibleVersion >= Constants.API_VERSION_SUPPORT_STAGE) { + if (info.compatibleVersion >= API_VERSION_SUPPORT_STAGE) { info.appInfo.iconId = info.hapModuleInfos[0].abilityInfo[0].iconId; } var ap: applicationPermissions = { 'bundleName': info.name, + 'api': info.targetVersion, 'tokenId': info.appInfo.accessTokenId, 'iconId': info.appInfo.iconId, 'labelId': info.appInfo.labelId, diff --git a/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets b/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets index c99657c..21610d1 100644 --- a/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets +++ b/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets @@ -35,6 +35,8 @@ var TAG = 'PermissionManager_MainAbility:' let routerData: any = router.getParams().routerData; // Routing jump data let backTitle = router.getParams().backTitle; // return title name +const FUZZY_LOCATION_PERMISSION = 'ohos.permission.APPROXIMATELY_LOCATION' +const PRECISE_LOCATION_PERMISSION = 'ohos.permission.LOCATION' class ApplicationObj { labelId: string @@ -129,7 +131,10 @@ struct locationInfoPage { // 0: have permission; -1: no permission this.polymorphismIsOn[index] = true for (let j = 0; j < routerData.length; j++) { - if (routerData[j].permission == 'ohos.permission.LOCATION') { + if ((routerData[j].permission == PRECISE_LOCATION_PERMISSION) && (res.targetVersion >= Constants.API_VERSION_SUPPORT_STAGE)) { + continue + } + if ((routerData[j].permission == FUZZY_LOCATION_PERMISSION) && (res.targetVersion < Constants.API_VERSION_SUPPORT_STAGE)) { continue } if (res.reqPermissions.indexOf(routerData[j].permission) == -1) { diff --git a/permissionmanager/src/main/ets/pages/dialogPlus.ets b/permissionmanager/src/main/ets/pages/dialogPlus.ets index a6a16f5..5aef9df 100644 --- a/permissionmanager/src/main/ets/pages/dialogPlus.ets +++ b/permissionmanager/src/main/ets/pages/dialogPlus.ets @@ -64,6 +64,7 @@ struct PermissionDialog { @State proxy: any = '' @State locationFlag: number = Constants.LOCATION_NONE @State resource: any = {} + @State bundleInfo: any = {} controller: CustomDialogController build() { @@ -220,18 +221,17 @@ struct PermissionDialog { async privacyAccept(group, accessTokenId, permissionList, userFixedFlag) { var acManager = abilityAccessCtrl.createAtManager() var num = 0 - if(group.name == 'LOCATION') { - if((this.locationFlag == Constants.LOCATION_UPGRADE) || - (this.locationFlag == Constants.LOCATION_BOTH_PRECISE)) { - await acManager.grantUserGrantedPermission(accessTokenId, PRECISE_LOCATION_PERMISSION, userFixedFlag) - var preciseIndex = permissionList.indexOf(PRECISE_LOCATION_PERMISSION) - this.result[preciseIndex] = abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED; - } - } group.permissions.forEach(async permission => { let result if(showSubpermissionsGrop.indexOf(group.name) == -1) { - result = await acManager.grantUserGrantedPermission(accessTokenId, permission, userFixedFlag) + if(group.name == 'LOCATION' && this.bundleInfo.targetVersion >= Constants.API_VERSION_SUPPORT_STAGE) { + if(!(((this.locationFlag == Constants.LOCATION_BOTH_FUZZY) || (this.locationFlag == Constants.LOCATION_FUZZY)) + && (permission == PRECISE_LOCATION_PERMISSION))) { + result = await acManager.grantUserGrantedPermission(accessTokenId, permission, userFixedFlag) + } + }else { + result = await acManager.grantUserGrantedPermission(accessTokenId, permission, userFixedFlag) + } }else { if(permissionList.includes(permission)) { result = await acManager.grantUserGrantedPermission(accessTokenId, permission, userFixedFlag) @@ -257,13 +257,6 @@ struct PermissionDialog { async privacyCancel(group, accessTokenId, permissionList, userFixedFlag) { var acManager = abilityAccessCtrl.createAtManager() - if(group.name == 'LOCATION') { - if((this.locationFlag == Constants.LOCATION_UPGRADE) || - (this.locationFlag == Constants.LOCATION_BOTH_FUZZY) || - (this.locationFlag == Constants.LOCATION_BOTH_PRECISE)) { - await acManager.revokeUserGrantedPermission(accessTokenId, PRECISE_LOCATION_PERMISSION, userFixedFlag) - } - } group.permissions.forEach(async permission => { let result if(showSubpermissionsGrop.indexOf(group.name) == -1) { @@ -280,13 +273,15 @@ struct PermissionDialog { getgrantGroups(stateGroup) { //Processing of positioning - if(this.reqPerms.includes(FUZZY_LOCATION_PERMISSION)) { - this.locationFlag = Constants.LOCATION_FUZZY - if(this.reqPerms.includes(PRECISE_LOCATION_PERMISSION)) { - this.locationFlag = Constants.LOCATION_BOTH_PRECISE - var fuzzyIndex = this.reqPerms.indexOf(FUZZY_LOCATION_PERMISSION) - if(stateGroup[fuzzyIndex] == Constants.PASS_OPER) { - this.locationFlag = Constants.LOCATION_UPGRADE + if(this.bundleInfo.targetVersion >= Constants.API_VERSION_SUPPORT_STAGE) { + if(this.reqPerms.includes(FUZZY_LOCATION_PERMISSION)) { + this.locationFlag = Constants.LOCATION_FUZZY + if(this.reqPerms.includes(PRECISE_LOCATION_PERMISSION)) { + this.locationFlag = Constants.LOCATION_BOTH_PRECISE + var fuzzyIndex = this.reqPerms.indexOf(FUZZY_LOCATION_PERMISSION) + if(stateGroup[fuzzyIndex] == Constants.PASS_OPER) { + this.locationFlag = Constants.LOCATION_UPGRADE + } } } } @@ -332,42 +327,35 @@ struct PermissionDialog { this.initStatus = Constants.INIT_NEED_TO_VERIFY } - getApplicationName(uid) { - bundle.getNameForUid(uid).then((data) => { - Log.info("getApplicationName bundleName:" + data) - Log.info("getApplicationName userId:" + Math.floor(uid/200000)) - bundle.getApplicationInfo(data, BundleFlag.GET_BUNDLE_DEFAULT, Math.floor(uid/200000)).then(applicationInfo => { - let context = globalThis.extensionContext.createBundleContext(data) - context.resourceManager.getString(applicationInfo.labelId, (err, value) => { - if (value == undefined) { - this.appName = applicationInfo.label - } else { - this.appName = value - } - Log.info("hap label:" + applicationInfo.label + ", value:"+this.appName) - }) - }).catch(err => { - Log.error("applicationInfo error :" + err) - this.initStatus = Constants.INIT_NEED_TO_TERMINATED - }) - bundle.getBundleInfo(data, Constants.PARMETER_BUNDLE_FLAG).then(bundleInfo => { - this.grantGroups.forEach((group) => { - if(group.description) { - Promise.all([globalThis.extensionContext.resourceManager.getString($r("app.string.separator").id), - globalThis.extensionContext.resourceManager.getString($r("app.string.reason_suffix").id)]) - .then(values => { - group.description = group.description.join(values[0]) + values[1] - this.getReason(group, bundleInfo, data) - }) - }else { - this.getReason(group, bundleInfo, data) - } - }) + getApplicationName(bundleName, uid) { + Log.info("getApplicationName bundleName:" + bundleName) + Log.info("getApplicationName userId:" + Math.floor(uid/200000)) + bundle.getApplicationInfo(bundleName, BundleFlag.GET_BUNDLE_DEFAULT, Math.floor(uid/200000)).then(applicationInfo => { + let context = globalThis.extensionContext.createBundleContext(bundleName) + context.resourceManager.getString(applicationInfo.labelId, (err, value) => { + if (value == undefined) { + this.appName = applicationInfo.label + } else { + this.appName = value + } + Log.info("hap label:" + applicationInfo.label + ", value:"+this.appName) }) }).catch(err => { - Log.error("getNameForUid error :" + JSON.stringify(err)) + Log.error("applicationInfo error :" + err) this.initStatus = Constants.INIT_NEED_TO_TERMINATED }) + this.grantGroups.forEach((group) => { + if(group.description) { + Promise.all([globalThis.extensionContext.resourceManager.getString($r("app.string.separator").id), + globalThis.extensionContext.resourceManager.getString($r("app.string.reason_suffix").id)]) + .then(values => { + group.description = group.description.join(values[0]) + values[1] + this.getReason(group, this.bundleInfo, bundleName) + }) + }else { + this.getReason(group, this.bundleInfo, bundleName) + } + }) } getReason(group, bundleInfo, bundleName) { @@ -418,8 +406,17 @@ struct PermissionDialog { Log.info("permission state=" + JSON.stringify(globalThis.abilityWant.parameters['ohos.user.grant.permission.state'])); this.result = new Array(this.reqPerms.length).fill(-1); this.getStrings() - this.getgrantGroups(globalThis.abilityWant.parameters['ohos.user.grant.permission.state']); - this.getApplicationName(globalThis.abilityWant.parameters['ohos.aafwk.param.callerUid']) + let uid = globalThis.abilityWant.parameters['ohos.aafwk.param.callerUid'] + bundle.getNameForUid(uid).then((data) => { + bundle.getBundleInfo(data, Constants.PARMETER_BUNDLE_FLAG).then(bundleInfo => { + this.bundleInfo = bundleInfo + this.getgrantGroups(globalThis.abilityWant.parameters['ohos.user.grant.permission.state']); + this.getApplicationName(data, uid) + }) + }).catch(err => { + Log.error("getNameForUid error :" + JSON.stringify(err)) + this.initStatus = Constants.INIT_NEED_TO_TERMINATED + }) } } -- Gitee