blob: f91341f8f4ea8ac4daa95ceeca6167c1e31ed46e [file] [log] [blame]
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.statusbar;
import android.annotation.NonNull;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.Looper;
import android.provider.DeviceConfig;
import android.util.ArrayMap;
import java.util.Map;
import javax.inject.Inject;
/**
* Class to manage simple DeviceConfig-based feature flags.
*
* To enable or disable a flag, run:
*
* {@code
* $ adb shell device_config put systemui <key> <true|false>
* }
*
* You will probably need to @{$ adb reboot} afterwards in order for the code to pick up the change.
*/
public class FeatureFlags {
private final Map<String, Boolean> mCachedDeviceConfigFlags = new ArrayMap<>();
@Inject
public FeatureFlags() {
DeviceConfig.addOnPropertiesChangedListener(
"systemui",
new HandlerExecutor(new Handler(Looper.getMainLooper())),
this::onPropertiesChanged);
}
public boolean isNewNotifPipelineEnabled() {
return getDeviceConfigFlag("notification.newpipeline.enabled", false);
}
private void onPropertiesChanged(@NonNull DeviceConfig.Properties properties) {
synchronized (mCachedDeviceConfigFlags) {
for (String key : properties.getKeyset()) {
mCachedDeviceConfigFlags.remove(key);
}
}
}
private boolean getDeviceConfigFlag(String key, boolean defaultValue) {
synchronized (mCachedDeviceConfigFlags) {
Boolean flag = mCachedDeviceConfigFlags.get(key);
if (flag == null) {
flag = DeviceConfig.getBoolean("systemui", key, defaultValue);
mCachedDeviceConfigFlags.put(key, flag);
}
return flag;
}
}
}