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.permissioncontroller.safetycenter.service;
18 
19 import android.app.job.JobService;
20 import android.provider.DeviceConfig;
21 
22 import java.time.Duration;
23 
24 /** A class so that the Safety Center {@link JobService} can access {@link DeviceConfig} flags. */
25 public class SafetyCenterJobServiceFlags {
26     private static final Duration DEFAULT_PERIODIC_BACKGROUND_REFRESH_INTERVAL = Duration.ofDays(1);
27     private static final String PROPERTY_BACKGROUND_REFRESH_IS_ENABLED =
28             "safety_center_background_refresh_is_enabled";
29     private static final String PROPERTY_PERIODIC_BACKGROUND_REFRESH_INTERVAL_MILLIS =
30             "safety_center_periodic_background_interval_millis";
31 
32     /** Returns whether background refreshes should be enabled. */
areBackgroundRefreshesEnabled()33     static boolean areBackgroundRefreshesEnabled() {
34         return DeviceConfig.getBoolean(
35                 DeviceConfig.NAMESPACE_PRIVACY, PROPERTY_BACKGROUND_REFRESH_IS_ENABLED, true);
36     }
37 
38     /**
39      * Returns the interval that should be used when scheduling periodic background refresh jobs.
40      */
getPeriodicBackgroundRefreshInterval()41     static Duration getPeriodicBackgroundRefreshInterval() {
42         return Duration.ofMillis(
43                 DeviceConfig.getLong(
44                         DeviceConfig.NAMESPACE_PRIVACY,
45                         PROPERTY_PERIODIC_BACKGROUND_REFRESH_INTERVAL_MILLIS,
46                         DEFAULT_PERIODIC_BACKGROUND_REFRESH_INTERVAL.toMillis()));
47     }
48 }
49