• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.adservices.download;
18 
19 import android.annotation.NonNull;
20 import android.provider.DeviceConfig;
21 
22 import com.google.android.libraries.mobiledatadownload.Flags;
23 
24 /**
25  * Flags for MDD
26  *
27  * <p>We only enable overriding for some flags that we may want to change the values. Other flags
28  * will get the default values.
29  */
30 public class MddFlags implements Flags {
31 
32     /*
33      * Keys for ALL MDD flags stored in DeviceConfig.
34      */
35     static final String KEY_MDD_MAINTENANCE_GCM_TASK_PERIOD_SECONDS =
36             "mdd_maintenance_gcm_task_period_seconds";
37     static final String KEY_MDD_CHARGING_GCM_TASK_PERIOD_SECONDS =
38             "mdd_charging_gcm_task_period_seconds";
39     static final String KEY_MDD_CELLULAR_CHARGING_GCM_TASK_PERIOD_SECONDS =
40             "mdd_cellular_charging_gcm_task_period_seconds";
41     static final String KEY_MDD_WIFI_CHARGING_GCM_TASK_PERIOD_SECONDS =
42             "mdd_wifi_charging_gcm_task_period_seconds";
43     static final String KEY_MDD_DEFAULT_SAMPLE_INTERVAL = "mdd_default_sample_interval";
44     static final String KEY_MDD_DOWNLOAD_EVENTS_SAMPLE_INTERVAL =
45             "mdd_download_events_sample_interval";
46     static final String KEY_MDD_GROUP_STATS_LOGGING_SAMPLE_INTERVAL =
47             "mdd_group_stats_logging_sample_interval";
48     static final String KEY_MDD_API_LOGGING_SAMPLE_INTERVAL = "mdd_api_logging_sample_interval";
49     static final String KEY_MDD_STORAGE_STATS_LOGGING_SAMPLE_INTERVAL =
50             "mdd_storage_stats_logging_sample_interval";
51     static final String KEY_MDD_NETWORK_STATS_LOGGING_SAMPLE_INTERVAL =
52             "mdd_network_stats_logging_sample_interval";
53     static final String KEY_MDD_MOBSTORE_FILE_SERVICE_STATS_SAMPLE_INTERVAL =
54             "mdd_mobstore_file_service_stats_sample_interval";
55     static final String KEY_MDD_ANDROID_SHARING_SAMPLE_INTERVAL =
56             "mdd_android_sharing_sample_interval";
57 
58     private static final MddFlags sSingleton = new MddFlags();
59 
60     /** Returns the singleton instance of the MddFlags. */
61     @NonNull
getInstance()62     public static MddFlags getInstance() {
63         return sSingleton;
64     }
65 
66     // PeriodTaskFlags
67     @Override
maintenanceGcmTaskPeriod()68     public long maintenanceGcmTaskPeriod() {
69         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
70         return DeviceConfig.getLong(
71                 DeviceConfig.NAMESPACE_ADSERVICES,
72                 /* flagName */ KEY_MDD_MAINTENANCE_GCM_TASK_PERIOD_SECONDS,
73                 /* defaultValue */ Flags.super.maintenanceGcmTaskPeriod());
74     }
75 
76     @Override
chargingGcmTaskPeriod()77     public long chargingGcmTaskPeriod() {
78         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
79         return DeviceConfig.getLong(
80                 DeviceConfig.NAMESPACE_ADSERVICES,
81                 /* flagName */ KEY_MDD_CHARGING_GCM_TASK_PERIOD_SECONDS,
82                 /* defaultValue */ Flags.super.chargingGcmTaskPeriod());
83     }
84 
85     @Override
cellularChargingGcmTaskPeriod()86     public long cellularChargingGcmTaskPeriod() {
87         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
88         return DeviceConfig.getLong(
89                 DeviceConfig.NAMESPACE_ADSERVICES,
90                 /* flagName */ KEY_MDD_CELLULAR_CHARGING_GCM_TASK_PERIOD_SECONDS,
91                 /* defaultValue */ Flags.super.cellularChargingGcmTaskPeriod());
92     }
93 
94     @Override
wifiChargingGcmTaskPeriod()95     public long wifiChargingGcmTaskPeriod() {
96         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
97         return DeviceConfig.getLong(
98                 DeviceConfig.NAMESPACE_ADSERVICES,
99                 /* flagName */ KEY_MDD_WIFI_CHARGING_GCM_TASK_PERIOD_SECONDS,
100                 /* defaultValue */ Flags.super.wifiChargingGcmTaskPeriod());
101     }
102 
103     // MddSampleIntervals
104     @Override
mddDefaultSampleInterval()105     public int mddDefaultSampleInterval() {
106         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
107         return DeviceConfig.getInt(
108                 DeviceConfig.NAMESPACE_ADSERVICES,
109                 /* flagName */ KEY_MDD_DEFAULT_SAMPLE_INTERVAL,
110                 /* defaultValue */ Flags.super.mddDefaultSampleInterval());
111     }
112 
113     @Override
mddDownloadEventsSampleInterval()114     public int mddDownloadEventsSampleInterval() {
115         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
116         return DeviceConfig.getInt(
117                 DeviceConfig.NAMESPACE_ADSERVICES,
118                 /* flagName */ KEY_MDD_DOWNLOAD_EVENTS_SAMPLE_INTERVAL,
119                 /* defaultValue */ Flags.super.mddDownloadEventsSampleInterval());
120     }
121 
122     @Override
groupStatsLoggingSampleInterval()123     public int groupStatsLoggingSampleInterval() {
124         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
125         return DeviceConfig.getInt(
126                 DeviceConfig.NAMESPACE_ADSERVICES,
127                 /* flagName */ KEY_MDD_GROUP_STATS_LOGGING_SAMPLE_INTERVAL,
128                 /* defaultValue */ Flags.super.groupStatsLoggingSampleInterval());
129     }
130 
131     @Override
apiLoggingSampleInterval()132     public int apiLoggingSampleInterval() {
133         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
134         return DeviceConfig.getInt(
135                 DeviceConfig.NAMESPACE_ADSERVICES,
136                 /* flagName */ KEY_MDD_API_LOGGING_SAMPLE_INTERVAL,
137                 /* defaultValue */ Flags.super.apiLoggingSampleInterval());
138     }
139 
140     @Override
storageStatsLoggingSampleInterval()141     public int storageStatsLoggingSampleInterval() {
142         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
143         return DeviceConfig.getInt(
144                 DeviceConfig.NAMESPACE_ADSERVICES,
145                 /* flagName */ KEY_MDD_STORAGE_STATS_LOGGING_SAMPLE_INTERVAL,
146                 /* defaultValue */ Flags.super.storageStatsLoggingSampleInterval());
147     }
148 
149     @Override
networkStatsLoggingSampleInterval()150     public int networkStatsLoggingSampleInterval() {
151         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
152         return DeviceConfig.getInt(
153                 DeviceConfig.NAMESPACE_ADSERVICES,
154                 /* flagName */ KEY_MDD_NETWORK_STATS_LOGGING_SAMPLE_INTERVAL,
155                 /* defaultValue */ Flags.super.networkStatsLoggingSampleInterval());
156     }
157 
158     @Override
mobstoreFileServiceStatsSampleInterval()159     public int mobstoreFileServiceStatsSampleInterval() {
160         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
161         return DeviceConfig.getInt(
162                 DeviceConfig.NAMESPACE_ADSERVICES,
163                 /* flagName */ KEY_MDD_MOBSTORE_FILE_SERVICE_STATS_SAMPLE_INTERVAL,
164                 /* defaultValue */ Flags.super.mobstoreFileServiceStatsSampleInterval());
165     }
166 
167     @Override
mddAndroidSharingSampleInterval()168     public int mddAndroidSharingSampleInterval() {
169         // The priority of applying the flag values: PH (DeviceConfig) and then hard-coded value.
170         return DeviceConfig.getInt(
171                 DeviceConfig.NAMESPACE_ADSERVICES,
172                 /* flagName */ KEY_MDD_ANDROID_SHARING_SAMPLE_INTERVAL,
173                 /* defaultValue */ Flags.super.mddAndroidSharingSampleInterval());
174     }
175 }
176