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.assist; 18 19 import static com.android.systemui.DejankUtils.whitelistIpcs; 20 21 import android.provider.DeviceConfig; 22 23 import androidx.annotation.Nullable; 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 class for retrieving System UI device configuration values. 33 * 34 * Can be mocked in tests for ease of testing the effects of particular values. 35 */ 36 @SysUISingleton 37 public class DeviceConfigHelper { 38 39 @Inject DeviceConfigHelper()40 public DeviceConfigHelper() {} 41 getLong(String name, long defaultValue)42 public long getLong(String name, long defaultValue) { 43 return whitelistIpcs(() -> 44 DeviceConfig.getLong(DeviceConfig.NAMESPACE_SYSTEMUI, name, defaultValue)); 45 } 46 getInt(String name, int defaultValue)47 public int getInt(String name, int defaultValue) { 48 return whitelistIpcs(() -> 49 DeviceConfig.getInt(DeviceConfig.NAMESPACE_SYSTEMUI, name, defaultValue)); 50 } 51 52 @Nullable getString(String name, @Nullable String defaultValue)53 public String getString(String name, @Nullable String defaultValue) { 54 return whitelistIpcs(() -> 55 DeviceConfig.getString(DeviceConfig.NAMESPACE_SYSTEMUI, name, defaultValue)); 56 } 57 getBoolean(String name, boolean defaultValue)58 public boolean getBoolean(String name, boolean defaultValue) { 59 return whitelistIpcs(() -> 60 DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI, name, defaultValue)); 61 } 62 addOnPropertiesChangedListener( Executor executor, DeviceConfig.OnPropertiesChangedListener listener)63 public void addOnPropertiesChangedListener( 64 Executor executor, DeviceConfig.OnPropertiesChangedListener listener) { 65 DeviceConfig.addOnPropertiesChangedListener( 66 DeviceConfig.NAMESPACE_SYSTEMUI, executor, listener); 67 } 68 removeOnPropertiesChangedListener( DeviceConfig.OnPropertiesChangedListener listener)69 public void removeOnPropertiesChangedListener( 70 DeviceConfig.OnPropertiesChangedListener listener) { 71 DeviceConfig.removeOnPropertiesChangedListener(listener); 72 } 73 } 74