diff options
author | Yi-an Chen <theianchen@google.com> | 2023-04-11 01:40:17 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2023-04-11 01:40:17 +0000 |
commit | 287223390d6b9ed380acea00085a4ef6a0b79285 (patch) | |
tree | 30ac4d1c5e0ee9bc6dfd3f4ef29b4020ece612e8 /PermissionController/src/com/android/permissioncontroller/permission/utils | |
parent | 8a895351f968fbcff4512d93dcae5d35dc50981a (diff) | |
parent | 08c6c7c2af769362d81c2f12ee3b423871d0cebe (diff) | |
download | Permission-287223390d6b9ed380acea00085a4ef6a0b79285.tar.gz |
Merge "Add tests for PermissionMapping" into udc-dev
Diffstat (limited to 'PermissionController/src/com/android/permissioncontroller/permission/utils')
2 files changed, 58 insertions, 36 deletions
diff --git a/PermissionController/src/com/android/permissioncontroller/permission/utils/PermissionMapping.kt b/PermissionController/src/com/android/permissioncontroller/permission/utils/PermissionMapping.kt index c4355b1e5..be72e6f2f 100644 --- a/PermissionController/src/com/android/permissioncontroller/permission/utils/PermissionMapping.kt +++ b/PermissionController/src/com/android/permissioncontroller/permission/utils/PermissionMapping.kt @@ -26,11 +26,7 @@ import android.util.Log import com.android.modules.utils.build.SdkLevel import com.android.permissioncontroller.permission.model.livedatatypes.LightAppPermGroup -import com.android.permission.safetylabel.DataCategory import com.android.permission.safetylabel.DataCategoryConstants -import com.android.permission.safetylabel.DataType -import com.android.permission.safetylabel.DataTypeConstants -import com.android.permission.safetylabel.SafetyLabel /** * This file contains the canonical mapping of permission to permission group, used in the @@ -390,38 +386,6 @@ object PermissionMapping { return AppOpsManager.opToPermission(opName)?.let { getGroupOfPlatformPermission(it) } } - /* - * Get the sharing purposes for a SafetyLabel related to a specific permission group. - */ - @JvmStatic - fun getSafetyLabelSharingPurposesForGroup( - safetyLabel: SafetyLabel, - groupName: String - ): Set<Int> { - val purposeSet = mutableSetOf<Int>() - val categoriesForPermission = getDataCategoriesForPermissionGroup(groupName) - categoriesForPermission.forEach categoryLoop@{ category -> - val dataCategory: DataCategory? = safetyLabel.dataLabel.dataShared[category] - if (dataCategory == null) { - // Continue to next - return@categoryLoop - } - val typesForCategory = DataTypeConstants.getValidDataTypesForCategory(category) - typesForCategory.forEach typeLoop@{ type -> - val dataType: DataType? = dataCategory.dataTypes[type] - if (dataType == null) { - // Continue to next - return@typeLoop - } - if (dataType.purposeSet.isNotEmpty()) { - purposeSet.addAll(dataType.purposeSet) - } - } - } - - return purposeSet - } - /** * Get the SafetyLabel categories pertaining to a specified permission group. * diff --git a/PermissionController/src/com/android/permissioncontroller/permission/utils/v34/SafetyLabelUtils.kt b/PermissionController/src/com/android/permissioncontroller/permission/utils/v34/SafetyLabelUtils.kt new file mode 100644 index 000000000..5dbe203f9 --- /dev/null +++ b/PermissionController/src/com/android/permissioncontroller/permission/utils/v34/SafetyLabelUtils.kt @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * 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. + */ + +package com.android.permissioncontroller.permission.utils.v34 + +import com.android.permission.safetylabel.DataCategory +import com.android.permission.safetylabel.DataType +import com.android.permission.safetylabel.DataTypeConstants +import com.android.permission.safetylabel.SafetyLabel +import com.android.permissioncontroller.permission.utils.PermissionMapping + +object SafetyLabelUtils { + /* + * Get the sharing purposes for a SafetyLabel related to a specific permission group. + */ + @JvmStatic + fun getSafetyLabelSharingPurposesForGroup( + safetyLabel: SafetyLabel, + groupName: String + ): Set<Int> { + val purposeSet = mutableSetOf<Int>() + val categoriesForPermission = PermissionMapping + .getDataCategoriesForPermissionGroup(groupName) + categoriesForPermission.forEach categoryLoop@{ category -> + val dataCategory: DataCategory? = safetyLabel.dataLabel.dataShared[category] + if (dataCategory == null) { + // Continue to next + return@categoryLoop + } + val typesForCategory = DataTypeConstants.getValidDataTypesForCategory(category) + typesForCategory.forEach typeLoop@{ type -> + val dataType: DataType? = dataCategory.dataTypes[type] + if (dataType == null) { + // Continue to next + return@typeLoop + } + if (dataType.purposeSet.isNotEmpty()) { + purposeSet.addAll(dataType.purposeSet) + } + } + } + + return purposeSet + } +} |