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 
17 package android.ext.services.common;
18 
19 import android.annotation.TargetApi;
20 import android.provider.DeviceConfig;
21 
22 
23 /**
24  * Adservices Flags Implementation that delegates to DeviceConfig.
25  */
26 public class AdservicesPhFlags {
27     /**
28      * Gets the value of periodic interval to run the AdServices check deletion job from
29      * device config flags
30      *
31      * @return value periodic interval in millis
32      **/
33     @TargetApi(33)
getAppsearchDeletePeriodicIntervalMillis()34     public Long getAppsearchDeletePeriodicIntervalMillis() {
35         return DeviceConfig.getLong(
36                 DeviceConfig.NAMESPACE_ADSERVICES,
37                 /* name= */ "ext_appsearch_delete_periodic_job_interval_ms",
38                 /* defaultValue= */ 7 * 24 * 60 * 60 * 1000L); // 1 week in millis
39     }
40 
41     /**
42      * Gets the value of periodic flex to run the adservices check deletion job from
43      * device config flags
44      *
45      * @return value periodic flex in millis
46      **/
47     @TargetApi(33)
getAppsearchDeleteJobFlexMillis()48     public Long getAppsearchDeleteJobFlexMillis() {
49         return DeviceConfig.getLong(
50                 DeviceConfig.NAMESPACE_ADSERVICES,
51                 /* name= */ "ext_appsearch_delete_scheduler_job_flex_ms",
52                 /* defaultValue= */ 15 * 60 * 1000L); // 15 Minutes in millis
53     }
54 
55     /**
56      * Check if AdServices flags are set to enable AdServices, this includes checking if the
57      * global_kill_switch is disabled and the adservice_enabled is true.
58      *
59      * @return {@code true} AdService is enabled; else {@code false}.
60      **/
61     @TargetApi(33)
isAdServicesEnabled()62     public boolean isAdServicesEnabled() {
63         return !DeviceConfig.getBoolean(
64                 DeviceConfig.NAMESPACE_ADSERVICES,
65                 /* flagName */ "global_kill_switch",
66                 /* defaultValue */ true)
67                 && DeviceConfig.getBoolean(
68                 DeviceConfig.NAMESPACE_ADSERVICES,
69                 /* flagName */ "adservice_enabled",
70                 /* defaultValue */ false);
71     }
72 
73     /**
74      * Check if Appsearch deletion job is enabled.
75      *
76      * @return {@code true} Appsearch deletion job is enabled; else {@code false}.
77      **/
78     @TargetApi(33)
isAppsearchDeleteJobEnabled()79     public boolean isAppsearchDeleteJobEnabled() {
80         return DeviceConfig.getBoolean(
81                 DeviceConfig.NAMESPACE_ADSERVICES,
82                 /* flagName */ "ext_enable_appsearch_delete_job",
83                 /* defaultValue */ true);
84     }
85 
86     /**
87      * Gets the value of min minutes after which to check AdServices status
88      *
89      * @return value of min minutes
90      **/
91     @TargetApi(33)
getMinMinutesFromOtaToCheckAdServicesStatus()92     public Long getMinMinutesFromOtaToCheckAdServicesStatus() {
93         return DeviceConfig.getLong(
94                 DeviceConfig.NAMESPACE_ADSERVICES,
95                 /* name= */ "ext_min_minutes_from_ota_check_adservices_status",
96                 /* defaultValue= */ 7 * 24 * 60L); // 1 Week in minutes
97     }
98 
99     /**
100      * Gets the value of min minutes to delete Appsearch data from date of OTA
101      *
102      * @return value of min minutes
103      **/
104     @TargetApi(33)
getMinMinutesFromOtaToDeleteAppsearchData()105     public Long getMinMinutesFromOtaToDeleteAppsearchData() {
106         return DeviceConfig.getLong(
107                 DeviceConfig.NAMESPACE_ADSERVICES,
108                 /* name= */ "ext_min_minutes_from_ota_delete_appsearch_data",
109                 /* defaultValue= */ 365 * 24 * 60L); // 1 Year in minutes
110     }
111 
112     /**
113      * Gets the value of min minutes to delete Appsearch data from date of first time AdServices
114      * was found to be enabled
115      *
116      * @return value of min minutes
117      **/
118     @TargetApi(33)
getMinMinutesToDeleteFromAdServicesEnabled()119     public Long getMinMinutesToDeleteFromAdServicesEnabled() {
120         return DeviceConfig.getLong(
121                 DeviceConfig.NAMESPACE_ADSERVICES,
122                 /* name= */ "ext_min_minutes_to_delete_from_adservices_enabled",
123                 /* defaultValue= */ 2 * 7 * 24 * 60L); // 2 Weeks in minutes
124     }
125 
126     /**
127      * max delete attempts on appsearch dbs before cancelling the job
128      *
129      * @return value of min delete attempts
130      **/
131     @TargetApi(33)
getMaxAppsearchAdServicesDeleteAttempts()132     public int getMaxAppsearchAdServicesDeleteAttempts() {
133         return DeviceConfig.getInt(
134                 DeviceConfig.NAMESPACE_ADSERVICES,
135                 /* name= */ "ext_max_appsearch_adservices_delete_attempts",
136                 /* defaultValue= */ 10);
137     }
138 
139     /**
140      * returns if the job should do nothing in case the job needs to be updated
141      * and job cannot be scheduled again, so keeping the periodic job running
142      *
143      * @return true if job should do nothing
144      **/
145     @TargetApi(33)
shouldDoNothingAdServicesAppsearchDeleteJob()146     public boolean shouldDoNothingAdServicesAppsearchDeleteJob() {
147         return DeviceConfig.getBoolean(
148                 DeviceConfig.NAMESPACE_ADSERVICES,
149                 /* name= */ "ext_do_nothing_adservices_appsearch_delete_job",
150                 /* defaultValue= */ false);
151     }
152 
153 }
154