blob: e3e4f80905fa4dbf64092d8bcc4d4733d553aced [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 Abrahamb6041f62023-11-03 12:14:26 -070049 /// Trunk stable server flags ///
50 bool late_boot_misc2() const;
51 bool dont_skip_on_early() const;
Sally Qide329f22023-09-26 16:21:39 -070052 bool refresh_rate_overlay_on_external_display() const;
Ady Abrahamb6041f62023-11-03 12:14:26 -070053
Ady Abrahamd6d80162023-10-23 12:57:41 -070054 /// Trunk stable readonly flags ///
55 bool connected_display() const;
56 bool enable_small_area_detection() const;
57 bool misc1() const;
58 bool vrr_config() const;
Brian Johnson8c144002023-10-30 15:47:44 -070059 bool hotplug2() const;
Brian Johnson4f095462023-10-31 10:12:55 -070060 bool hdcp_level_hal() const;
Leon Scroggins IIIb315af52023-11-02 10:03:23 -040061 bool multithreaded_present() const;
Ady Abrahamd6d80162023-10-23 12:57:41 -070062
Ady Abrahamc589dc42023-10-26 16:20:53 -070063protected:
64 // overridden for unit tests
65 virtual std::optional<bool> getBoolProperty(const char*) const;
66 virtual bool getServerConfigurableFlag(const char*) const;
67
rnlee81d32602021-07-27 13:24:07 -070068private:
Ady Abrahamc589dc42023-10-26 16:20:53 -070069 friend class TestableFlagManager;
rnlee81d32602021-07-27 13:24:07 -070070
Ady Abraham53b0c492023-10-23 11:47:14 -070071 FlagManager(const FlagManager&) = delete;
72
Ady Abrahamb6041f62023-11-03 12:14:26 -070073 void dumpFlag(std::string& result, bool readonly, const char* name,
74 std::function<bool()> getter) const;
75
Ady Abrahamd6d80162023-10-23 12:57:41 -070076 std::atomic_bool mBootCompleted = false;
77 std::atomic_bool mUnitTestMode = false;
Ady Abraham53b0c492023-10-23 11:47:14 -070078
79 static std::unique_ptr<FlagManager> mInstance;
80 static std::once_flag mOnce;
rnlee81d32602021-07-27 13:24:07 -070081};
82} // namespace android