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