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