1 /*
2  * 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 #pragma once
17 
18 #include <stdlib.h>
19 
20 #include <map>
21 
22 #include "stats_annotations.h"
23 
24 namespace android {
25 namespace os {
26 namespace statsd {
27 
28 #define DEFAULT_RESTRICTED_CATEGORY_TTL_DAYS 7
29 
30 // Restricted categories used internally by statsd.
31 enum StatsdRestrictionCategory : int32_t {
32     CATEGORY_UNKNOWN = -1,
33     CATEGORY_NO_RESTRICTION = 0,
34     CATEGORY_DIAGNOSTIC = ASTATSLOG_RESTRICTION_CATEGORY_DIAGNOSTIC,
35     CATEGORY_SYSTEM_INTELLIGENCE = ASTATSLOG_RESTRICTION_CATEGORY_SYSTEM_INTELLIGENCE,
36     CATEGORY_AUTHENTICATION = ASTATSLOG_RESTRICTION_CATEGORY_AUTHENTICATION,
37     CATEGORY_FRAUD_AND_ABUSE = ASTATSLOG_RESTRICTION_CATEGORY_FRAUD_AND_ABUSE,
38 };
39 
40 // Single instance shared across the process.
41 class RestrictedPolicyManager {
42     RestrictedPolicyManager() = default;
43 
44 public:
45     static RestrictedPolicyManager& getInstance();
46 
47     // Gets the TTL in days for a particular restricted category. Returns the default for unknown
48     // categories.
49     int32_t getRestrictedCategoryTtl(StatsdRestrictionCategory categoryId) const;
50 
51 private:
52     std::map<StatsdRestrictionCategory, int32_t> mRestrictionCategoryTtlInDaysMap;
53 };
54 }  // namespace statsd
55 }  // namespace os
56 }  // namespace android
57