1 /* 2 * Copyright (C) 2019 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 <binder/IServiceManager.h> 20 #include <binder/Status.h> 21 #include <utils/StrongPointer.h> 22 23 namespace android { 24 namespace binder { 25 namespace internal { 26 class ClientCounterCallback; 27 } // namespace internal 28 29 /** Exits when all services registered through this object have 0 clients */ 30 class LazyServiceRegistrar { 31 public: 32 static LazyServiceRegistrar& getInstance(); 33 status_t registerService(const sp<IBinder>& service, 34 const std::string& name = "default", 35 bool allowIsolated = false, 36 int dumpFlags = IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT); 37 /** 38 * Force the service to persist, even when it has 0 clients. 39 * If setting this flag from the server side, make sure to do so before calling registerService, 40 * or there may be a race with the default dynamic shutdown. 41 */ 42 void forcePersist(bool persist); 43 44 private: 45 std::shared_ptr<internal::ClientCounterCallback> mClientCC; 46 LazyServiceRegistrar(); 47 }; 48 49 } // namespace binder 50 } // namespace android