1 /*
2  * Copyright (C) 2022 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.permission.safetylabel;
18 
19 import static java.lang.annotation.RetentionPolicy.SOURCE;
20 
21 import android.annotation.StringDef;
22 
23 import java.lang.annotation.Retention;
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.HashSet;
27 import java.util.Set;
28 
29 /**
30  * Constants for determining valid {@link String} data types for usage within {@link SafetyLabel},
31  * {@link DataCategory}, and {@link DataType}
32  */
33 public class DataCategoryConstants {
34 
35     /** List of valid Safety Label data collection/sharing categories */
36     @Retention(SOURCE)
37     @StringDef(
38             prefix = "CATEGORY_",
39             value = {
40                 CATEGORY_PERSONAL,
41                 CATEGORY_FINANCIAL,
42                 CATEGORY_LOCATION,
43                 CATEGORY_EMAIL_TEXT_MESSAGE,
44                 CATEGORY_PHOTO_VIDEO,
45                 CATEGORY_AUDIO,
46                 CATEGORY_STORAGE,
47                 CATEGORY_HEALTH_FITNESS,
48                 CATEGORY_CONTACTS,
49                 CATEGORY_CALENDAR,
50                 CATEGORY_IDENTIFIERS,
51                 CATEGORY_APP_PERFORMANCE,
52                 CATEGORY_ACTIONS_IN_APP,
53                 CATEGORY_SEARCH_AND_BROWSING,
54             })
55     public @interface Category {}
56 
57     public static final String CATEGORY_PERSONAL = "personal";
58     public static final String CATEGORY_FINANCIAL = "financial";
59     public static final String CATEGORY_LOCATION = "location";
60     public static final String CATEGORY_EMAIL_TEXT_MESSAGE = "email_text_message";
61     public static final String CATEGORY_PHOTO_VIDEO = "photo_video";
62     public static final String CATEGORY_AUDIO = "audio";
63     public static final String CATEGORY_STORAGE = "storage";
64     public static final String CATEGORY_HEALTH_FITNESS = "health_fitness";
65     public static final String CATEGORY_CONTACTS = "contacts";
66     public static final String CATEGORY_CALENDAR = "calendar";
67     public static final String CATEGORY_IDENTIFIERS = "identifiers";
68     public static final String CATEGORY_APP_PERFORMANCE = "app_performance";
69     public static final String CATEGORY_ACTIONS_IN_APP = "actions_in_app";
70     public static final String CATEGORY_SEARCH_AND_BROWSING = "search_and_browsing";
71 
72     /** Set of valid categories */
73     @DataCategoryConstants.Category
74     public static final Set<String> VALID_CATEGORIES =
75             Collections.unmodifiableSet(
76                     new HashSet<>(
77                             Arrays.asList(
78                                     CATEGORY_PERSONAL,
79                                     CATEGORY_FINANCIAL,
80                                     CATEGORY_LOCATION,
81                                     CATEGORY_EMAIL_TEXT_MESSAGE,
82                                     CATEGORY_PHOTO_VIDEO,
83                                     CATEGORY_AUDIO,
84                                     CATEGORY_STORAGE,
85                                     CATEGORY_HEALTH_FITNESS,
86                                     CATEGORY_CONTACTS,
87                                     CATEGORY_CALENDAR,
88                                     CATEGORY_IDENTIFIERS,
89                                     CATEGORY_APP_PERFORMANCE,
90                                     CATEGORY_ACTIONS_IN_APP,
91                                     CATEGORY_SEARCH_AND_BROWSING)));
92 
93     /** Returns {@link Set} of valid {@link String} category keys */
getValidDataCategories()94     public static Set<String> getValidDataCategories() {
95         return VALID_CATEGORIES;
96     }
97 
DataCategoryConstants()98     private DataCategoryConstants() {
99         /* do nothing - hide constructor */
100     }
101 }
102