• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.permissioncontroller.permission.utils.v34
18 
19 import com.android.permission.safetylabel.DataCategory
20 import com.android.permission.safetylabel.DataType
21 import com.android.permission.safetylabel.DataTypeConstants
22 import com.android.permission.safetylabel.SafetyLabel
23 import com.android.permissioncontroller.permission.utils.PermissionMapping
24 
25 object SafetyLabelUtils {
26     /*
27      * Get the sharing purposes for a SafetyLabel related to a specific permission group.
28      */
29     @JvmStatic
30     fun getSafetyLabelSharingPurposesForGroup(
31         safetyLabel: SafetyLabel,
32         groupName: String
33     ): Set<Int> {
34         val purposeSet = mutableSetOf<Int>()
35         val categoriesForPermission = PermissionMapping
36             .getDataCategoriesForPermissionGroup(groupName)
37         categoriesForPermission.forEach categoryLoop@{ category ->
38             val dataCategory: DataCategory? = safetyLabel.dataLabel.dataShared[category]
39             if (dataCategory == null) {
40                 // Continue to next
41                 return@categoryLoop
42             }
43             val typesForCategory = DataTypeConstants.getValidDataTypesForCategory(category)
44             typesForCategory.forEach typeLoop@{ type ->
45                 val dataType: DataType? = dataCategory.dataTypes[type]
46                 if (dataType == null) {
47                     // Continue to next
48                     return@typeLoop
49                 }
50                 if (dataType.purposeSet.isNotEmpty()) {
51                     purposeSet.addAll(dataType.purposeSet)
52                 }
53             }
54         }
55 
56         return purposeSet
57     }
58 }
59