• 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 android.util;
18 
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.provider.DeviceConfig;
22 
23 /**
24  * Util class for whether we should show the safety protection resources.
25  *
26  * @hide
27  */
28 public class SafetyProtectionUtils {
29     private static final String SAFETY_PROTECTION_RESOURCES_ENABLED = "safety_protection_enabled";
30 
31     /**
32      * Determines whether we should show the safety protection resources.
33      * We show the resources only if
34      * (1) the feature flag safety_protection_enabled is enabled and
35      * (2) the config value config_safetyProtectionEnabled is enabled/true and
36      * (3) the resources exist (currently the resources only exist on GMS devices)
37      *
38      * TODO: make this an API in U
39      *
40      * @hide
41      */
shouldShowSafetyProtectionResources(Context context)42     public static boolean shouldShowSafetyProtectionResources(Context context) {
43         return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
44                 SAFETY_PROTECTION_RESOURCES_ENABLED, false)
45                 && context.getResources().getBoolean(
46                         Resources.getSystem()
47                                 .getIdentifier("config_safetyProtectionEnabled",
48                                         "bool", "android"))
49                 && context.getDrawable(android.R.drawable.ic_safety_protection) != null
50                 && context.getString(android.R.string.safety_protection_display_text) != null
51                 && !context.getString(android.R.string.safety_protection_display_text).isEmpty();
52     }
53 }
54