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