blob: 8af0b4fc5a4528d5ac6712bf0d937b82555249e5 [file] [log] [blame]
rnlee81d32602021-07-27 13:24:07 -07001/*
2 * Copyright (C) 2021 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#pragma once
18
19#include <cstdint>
Ady Abraham53b0c492023-10-23 11:47:14 -070020#include <mutex>
rnlee81d32602021-07-27 13:24:07 -070021#include <optional>
22#include <string>
23
24namespace android {
25// Manages flags for SurfaceFlinger, including default values, system properties, and Mendel
Ady Abraham53b0c492023-10-23 11:47:14 -070026// experiment configuration values. Can be called from any thread.
rnlee81d32602021-07-27 13:24:07 -070027class FlagManager {
Ady Abraham53b0c492023-10-23 11:47:14 -070028private:
29 // Effectively making the constructor private, while allowing std::make_unique to work
30 struct ConstructorTag {};
31
rnlee81d32602021-07-27 13:24:07 -070032public:
Ady Abraham53b0c492023-10-23 11:47:14 -070033 static FlagManager& getInstance();
34
35 FlagManager(ConstructorTag);
36
rnlee81d32602021-07-27 13:24:07 -070037 virtual ~FlagManager();
38 void dump(std::string& result) const;
39
40 int64_t demo_flag() const;
41
Matt Buckleyd23c7962021-09-21 20:43:00 +000042 bool use_adpf_cpu_hint() const;
43
Leon Scroggins IIIa37ca992022-02-02 18:08:20 -050044 bool use_skia_tracing() const;
45
rnlee81d32602021-07-27 13:24:07 -070046private:
47 friend class FlagManagerTest;
48
Ady Abraham53b0c492023-10-23 11:47:14 -070049 FlagManager(const FlagManager&) = delete;
50
rnlee81d32602021-07-27 13:24:07 -070051 // Wrapper for mocking in test.
52 virtual std::string getServerConfigurableFlag(const std::string& experimentFlagName) const;
53
54 template <typename T>
55 T getValue(const std::string& experimentFlagName, std::optional<T> systemPropertyOpt,
56 T defaultValue) const;
Ady Abraham53b0c492023-10-23 11:47:14 -070057
58 static std::unique_ptr<FlagManager> mInstance;
59 static std::once_flag mOnce;
rnlee81d32602021-07-27 13:24:07 -070060};
61} // namespace android