1 /* 2 * Copyright 2025 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 <memory> 20 #include <string> 21 #include <string_view> 22 23 #include <android-base/expected.h> 24 #include <ftl/finalizer.h> 25 #include <utils/StrongPointer.h> 26 27 namespace android::gui { 28 29 class ISurfaceComposer; 30 class ISurfaceComposerClient; 31 32 } // namespace android::gui 33 34 namespace android { 35 36 class SurfaceComposerClient; 37 38 } // namespace android 39 40 namespace android::surfaceflinger::tests::end2end::test_framework::surfaceflinger { 41 42 class SFController final { 43 struct Passkey; // Uses the passkey idiom to restrict construction. 44 45 public: 46 // Sets a property so that SurfaceFlinger uses the named HWC service. 47 static void useHwcService(std::string_view fqn); 48 49 // Makes an instance of the SFController. 50 [[nodiscard]] static auto make() -> base::expected<std::shared_ptr<SFController>, std::string>; 51 52 explicit SFController(Passkey pass); 53 54 // Starts SurfaceFlinger and establishes the AIDL interface connections. 55 [[nodiscard]] auto startAndConnect() -> base::expected<void, std::string>; 56 57 private: 58 [[nodiscard]] auto init() -> base::expected<void, std::string>; 59 static void start(); 60 void stop(); 61 62 sp<gui::ISurfaceComposer> mSurfaceComposerAidl; 63 sp<gui::ISurfaceComposerClient> mSurfaceComposerClientAidl; 64 sp<SurfaceComposerClient> mSurfaceComposerClient; 65 66 // Finalizers should be last so their destructors are invoked first. 67 ftl::FinalizerFtl mCleanup; 68 }; 69 70 } // namespace android::surfaceflinger::tests::end2end::test_framework::surfaceflinger 71