Brett Chabot | c9ee330 | 2020-01-31 09:20:28 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | |
| 21 | #include <map> |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | /** |
| 26 | * A local host simple implementation of IServiceManager, that does not |
| 27 | * communicate over binder. |
| 28 | */ |
| 29 | class ServiceManager : public IServiceManager { |
| 30 | public: |
| 31 | ServiceManager(); |
| 32 | |
| 33 | /** |
| 34 | * Equivalent of checkService. |
| 35 | */ |
| 36 | sp<IBinder> getService( const String16& name) const override; |
| 37 | |
| 38 | /** |
| 39 | * Retrieve an existing service, non-blocking. |
| 40 | */ |
| 41 | sp<IBinder> checkService( const String16& name) const override; |
| 42 | |
| 43 | /** |
| 44 | * Register a service. |
| 45 | */ |
| 46 | status_t addService(const String16& name, const sp<IBinder>& service, |
| 47 | bool allowIsolated = false, |
| 48 | int dumpsysFlags = DUMP_FLAG_PRIORITY_DEFAULT) override; |
| 49 | |
| 50 | /** |
| 51 | * Return list of all existing services. |
| 52 | */ |
| 53 | Vector<String16> listServices(int dumpsysFlags = 0) override; |
| 54 | |
| 55 | IBinder* onAsBinder() override; |
| 56 | |
| 57 | /** |
| 58 | * Effectively no-oped in this implementation - equivalent to checkService. |
| 59 | */ |
| 60 | sp<IBinder> waitForService(const String16& name) override; |
| 61 | |
| 62 | /** |
| 63 | * Check if a service is declared (e.g. VINTF manifest). |
| 64 | * |
| 65 | * If this returns true, waitForService should always be able to return the |
| 66 | * service. |
| 67 | */ |
| 68 | bool isDeclared(const String16& name) override; |
| 69 | |
| 70 | private: |
| 71 | std::map<String16, sp<IBinder>> mNameToService; |
| 72 | }; |
| 73 | |
| 74 | } // namespace android |