blob: 1a689937beeaeb7992f2a392ab7ba9ed3227bd64 [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 Abrahamc589dc42023-10-26 16:20:53 -070033 static const FlagManager& getInstance();
34 static FlagManager& getMutableInstance();
Ady Abraham53b0c492023-10-23 11:47:14 -070035
36 FlagManager(ConstructorTag);
rnlee81d32602021-07-27 13:24:07 -070037 virtual ~FlagManager();
Ady Abrahamc589dc42023-10-26 16:20:53 -070038
39 void markBootCompleted();
rnlee81d32602021-07-27 13:24:07 -070040 void dump(std::string& result) const;
41
Ady Abrahamd6d80162023-10-23 12:57:41 -070042 void setUnitTestMode();
43
44 /// Legacy server flags ///
Ady Abrahamc589dc42023-10-26 16:20:53 -070045 bool test_flag() const;
Matt Buckleyd23c7962021-09-21 20:43:00 +000046 bool use_adpf_cpu_hint() const;
Leon Scroggins IIIa37ca992022-02-02 18:08:20 -050047 bool use_skia_tracing() const;
48
Ady Abrahamd6d80162023-10-23 12:57:41 -070049 /// 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 Johnson8c144002023-10-30 15:47:44 -070054 bool hotplug2() const;
Brian Johnson4f095462023-10-31 10:12:55 -070055 bool hdcp_level_hal() const;
Ady Abrahamd6d80162023-10-23 12:57:41 -070056
57 /// Trunk stable server flags ///
58 bool late_boot_misc2() const;
59 bool dont_skip_on_early() const;
60
Ady Abrahamc589dc42023-10-26 16:20:53 -070061protected:
62 // overridden for unit tests
63 virtual std::optional<bool> getBoolProperty(const char*) const;
64 virtual bool getServerConfigurableFlag(const char*) const;
65
rnlee81d32602021-07-27 13:24:07 -070066private:
Ady Abrahamc589dc42023-10-26 16:20:53 -070067 friend class TestableFlagManager;
rnlee81d32602021-07-27 13:24:07 -070068
Ady Abraham53b0c492023-10-23 11:47:14 -070069 FlagManager(const FlagManager&) = delete;
70
Ady Abrahamd6d80162023-10-23 12:57:41 -070071 std::atomic_bool mBootCompleted = false;
72 std::atomic_bool mUnitTestMode = false;
Ady Abraham53b0c492023-10-23 11:47:14 -070073
74 static std::unique_ptr<FlagManager> mInstance;
75 static std::once_flag mOnce;
rnlee81d32602021-07-27 13:24:07 -070076};
77} // namespace android