• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.systemui.util;
18 
19 import android.annotation.CallbackExecutor;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.content.Context;
23 import android.provider.DeviceConfig;
24 import android.provider.Settings;
25 
26 import java.util.concurrent.Executor;
27 
28 import javax.inject.Inject;
29 
30 /**
31  * Wrapper around DeviceConfig useful for testing.
32  */
33 public class DeviceConfigProxy {
34     @Inject
DeviceConfigProxy()35     public DeviceConfigProxy() {
36     }
37 
38     /**
39      * Wrapped version of {@link DeviceConfig#addOnPropertiesChangedListener}.
40      */
addOnPropertiesChangedListener( @onNull String namespace, @NonNull @CallbackExecutor Executor executor, @NonNull DeviceConfig.OnPropertiesChangedListener onPropertiesChangedListener)41     public void addOnPropertiesChangedListener(
42             @NonNull String namespace,
43             @NonNull @CallbackExecutor Executor executor,
44             @NonNull DeviceConfig.OnPropertiesChangedListener onPropertiesChangedListener) {
45         DeviceConfig.addOnPropertiesChangedListener(
46                 namespace, executor, onPropertiesChangedListener);
47     }
48 
49     /**
50      * Wrapped version of {@link DeviceConfig#enforceReadPermission}.
51      */
enforceReadPermission(Context context, String namespace)52     public void enforceReadPermission(Context context, String namespace) {
53         DeviceConfig.enforceReadPermission(context, namespace);
54     }
55 
56     /**
57      * Wrapped version of {@link DeviceConfig#getBoolean}.
58      */
getBoolean( @onNull String namespace, @NonNull String name, boolean defaultValue)59     public boolean getBoolean(
60             @NonNull String namespace, @NonNull String name, boolean defaultValue) {
61         return DeviceConfig.getBoolean(namespace, name, defaultValue);
62     }
63 
64     /**
65      * Wrapped version of {@link DeviceConfig#getFloat}.
66      */
getFloat( @onNull String namespace, @NonNull String name, float defaultValue)67     public float getFloat(
68             @NonNull String namespace, @NonNull String name, float defaultValue) {
69         return DeviceConfig.getFloat(namespace, name, defaultValue);
70     }
71 
72     /**
73      * Wrapped version of {@link DeviceConfig#getInt}.
74      */
getInt(@onNull String namespace, @NonNull String name, int defaultValue)75     public int getInt(@NonNull String namespace, @NonNull String name, int defaultValue) {
76         return DeviceConfig.getInt(namespace, name, defaultValue);
77     }
78 
79     /**
80      * Wrapped version of {@link DeviceConfig#getLong}.
81      */
getLong(@onNull String namespace, @NonNull String name, long defaultValue)82     public long getLong(@NonNull String namespace, @NonNull String name, long defaultValue) {
83         return DeviceConfig.getLong(namespace, name, defaultValue);
84 
85     }
86 
87     /**
88      * Wrapped version of {@link DeviceConfig#getProperty}.
89      */
getProperty(@onNull String namespace, @NonNull String name)90     public String getProperty(@NonNull String namespace, @NonNull String name) {
91         return DeviceConfig.getProperty(namespace, name);
92     }
93 
94     /**
95      * Wrapped version of {@link DeviceConfig#getString}.
96      */
getString( @onNull String namespace, @NonNull String name, @Nullable String defaultValue)97     public String getString(
98             @NonNull String namespace, @NonNull String name, @Nullable String defaultValue) {
99         return DeviceConfig.getString(namespace, name, defaultValue);
100     }
101 
102     /**
103      * Wrapped version of {@link DeviceConfig#removeOnPropertiesChangedListener}.
104      *
105      * Like {@link #addOnPropertiesChangedListener}, this operates on a callback type that
106      * wraps the original callback type provided by {@link DeviceConfig}.
107      */
removeOnPropertiesChangedListener( @onNull DeviceConfig.OnPropertiesChangedListener onPropertiesChangedListener)108     public void removeOnPropertiesChangedListener(
109             @NonNull DeviceConfig.OnPropertiesChangedListener onPropertiesChangedListener) {
110         DeviceConfig.removeOnPropertiesChangedListener(onPropertiesChangedListener);
111     }
112 
113     /**
114      * Wrapped version of {@link DeviceConfig#resetToDefaults}.
115      */
resetToDefaults(@ettings.ResetMode int resetMode, @Nullable String namespace)116     public void resetToDefaults(@Settings.ResetMode int resetMode,
117             @Nullable String namespace) {
118         DeviceConfig.resetToDefaults(resetMode, namespace);
119     }
120 
121     /**
122      * Wrapped version of {@link DeviceConfig#setProperty}.
123      */
setProperty( @onNull String namespace, @NonNull String name, @Nullable String value, boolean makeDefault)124     public boolean setProperty(
125             @NonNull String namespace,
126             @NonNull String name,
127             @Nullable String value,
128             boolean makeDefault) {
129         return DeviceConfig.setProperty(namespace, name, value, makeDefault);
130     }
131 }
132