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 <stdint.h> 20 #include <sys/types.h> 21 22 #include <android/gui/ISurfaceComposer.h> 23 #include <ui/DisplayId.h> 24 25 #include <utils/Singleton.h> 26 #include <utils/StrongPointer.h> 27 28 namespace android { 29 30 // --------------------------------------------------------------------------- 31 32 // --------------------------------------------------------------------------- 33 34 // This holds our connection to the composer service (i.e. SurfaceFlinger). 35 // If the remote side goes away, we will re-establish the connection. 36 // Users of this class should not retain the value from 37 // getComposerService() for an extended period. 38 // 39 // (TODO: b/219785927, It's not clear that using Singleton is useful here anymore.) 40 class ComposerServiceAIDL : public Singleton<ComposerServiceAIDL> { 41 sp<gui::ISurfaceComposer> mComposerService; 42 sp<IBinder::DeathRecipient> mDeathObserver; 43 mutable std::mutex mMutex; 44 45 ComposerServiceAIDL(); 46 bool connectLocked(); 47 void composerServiceDied(); 48 friend class Singleton<ComposerServiceAIDL>; 49 50 public: 51 // Get a connection to the Composer Service. This will block until 52 // a connection is established. Returns null if permission is denied. 53 static sp<gui::ISurfaceComposer> getComposerService(); 54 }; 55 56 // --------------------------------------------------------------------------- 57 }; // namespace android 58