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 | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 42 | void setUnitTestMode(); |
| 43 | |
| 44 | /// Legacy server flags /// |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame] | 45 | bool test_flag() const; |
Matt Buckley | d23c796 | 2021-09-21 20:43:00 +0000 | [diff] [blame] | 46 | bool use_adpf_cpu_hint() const; |
Leon Scroggins III | a37ca99 | 2022-02-02 18:08:20 -0500 | [diff] [blame] | 47 | bool use_skia_tracing() const; |
| 48 | |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 49 | /// Trunk stable readonly flags /// |
| 50 | bool connected_display() const; |
| 51 | bool enable_small_area_detection() const; |
| 52 | bool misc1() const; |
| 53 | bool vrr_config() const; |
Brian Johnson | 8c14400 | 2023-10-30 15:47:44 -0700 | [diff] [blame] | 54 | bool hotplug2() const; |
Brian Johnson | 4f09546 | 2023-10-31 10:12:55 -0700 | [diff] [blame] | 55 | bool hdcp_level_hal() const; |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 56 | |
| 57 | /// Trunk stable server flags /// |
| 58 | bool late_boot_misc2() const; |
| 59 | bool dont_skip_on_early() const; |
| 60 | |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame] | 61 | protected: |
| 62 | // overridden for unit tests |
| 63 | virtual std::optional<bool> getBoolProperty(const char*) const; |
| 64 | virtual bool getServerConfigurableFlag(const char*) const; |
| 65 | |
rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 66 | private: |
Ady Abraham | c589dc4 | 2023-10-26 16:20:53 -0700 | [diff] [blame] | 67 | friend class TestableFlagManager; |
rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 68 | |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 69 | FlagManager(const FlagManager&) = delete; |
| 70 | |
Ady Abraham | d6d8016 | 2023-10-23 12:57:41 -0700 | [diff] [blame] | 71 | std::atomic_bool mBootCompleted = false; |
| 72 | std::atomic_bool mUnitTestMode = false; |
Ady Abraham | 53b0c49 | 2023-10-23 11:47:14 -0700 | [diff] [blame] | 73 | |
| 74 | static std::unique_ptr<FlagManager> mInstance; |
| 75 | static std::once_flag mOnce; |
rnlee | 81d3260 | 2021-07-27 13:24:07 -0700 | [diff] [blame] | 76 | }; |
| 77 | } // namespace android |