rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 1 | /* |
| 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 Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 20 | #include <mutex> |
rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 21 | #include <optional> |
| 22 | #include <string> |
| 23 | |
| 24 | namespace android { |
| 25 | // Manages flags for SurfaceFlinger, including default values, system properties, and Mendel |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 26 | // experiment configuration values. Can be called from any thread. |
rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 27 | class FlagManager { |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 28 | private: |
| 29 | // Effectively making the constructor private, while allowing std::make_unique to work |
| 30 | struct ConstructorTag {}; |
| 31 | |
rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 32 | public: |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame^] | 33 | static const FlagManager& getInstance(); |
| 34 | static FlagManager& getMutableInstance(); |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 35 | |
| 36 | FlagManager(ConstructorTag); |
rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 37 | virtual ~FlagManager(); |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame^] | 38 | |
| 39 | void markBootCompleted(); |
rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 40 | void dump(std::string& result) const; |
| 41 | |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame^] | 42 | bool test_flag() const; |
Matt Buckley | d23c796 | 2021-09-21 20:43:00 +0000 | [diff] [blame] | 43 | bool use_adpf_cpu_hint() const; |
Leon Scroggins III | a37ca99 | 2022-02-02 18:08:20 -0500 | [diff] [blame] | 44 | bool use_skia_tracing() const; |
| 45 | |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame^] | 46 | protected: |
| 47 | // overridden for unit tests |
| 48 | virtual std::optional<bool> getBoolProperty(const char*) const; |
| 49 | virtual bool getServerConfigurableFlag(const char*) const; |
| 50 | |
rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 51 | private: |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame^] | 52 | friend class TestableFlagManager; |
rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 53 | |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 54 | FlagManager(const FlagManager&) = delete; |
| 55 | |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame^] | 56 | std::atomic_bool mBootCompleted; |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 57 | |
| 58 | static std::unique_ptr<FlagManager> mInstance; |
| 59 | static std::once_flag mOnce; |
rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 60 | }; |
| 61 | } // namespace android |