blob: 6d6e008c4fb6f244a183082c012200862731daa7 [file] [log] [blame]
Brett Chabotc9ee3302020-01-31 09:20:28 -08001/*
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>
Steven Morelandedd4e072021-04-21 00:27:29 +000022#include <optional>
Brett Chabotc9ee3302020-01-31 09:20:28 -080023
24namespace android {
25
26/**
27 * A local host simple implementation of IServiceManager, that does not
28 * communicate over binder.
29*/
30class ServiceManager : public IServiceManager {
31public:
32 ServiceManager();
33
Brett Chabotc9ee3302020-01-31 09:20:28 -080034 sp<IBinder> getService( const String16& name) const override;
35
Brett Chabotc9ee3302020-01-31 09:20:28 -080036 sp<IBinder> checkService( const String16& name) const override;
37
Brett Chabotc9ee3302020-01-31 09:20:28 -080038 status_t addService(const String16& name, const sp<IBinder>& service,
39 bool allowIsolated = false,
40 int dumpsysFlags = DUMP_FLAG_PRIORITY_DEFAULT) override;
41
Brett Chabotc9ee3302020-01-31 09:20:28 -080042 Vector<String16> listServices(int dumpsysFlags = 0) override;
43
44 IBinder* onAsBinder() override;
45
Brett Chabotc9ee3302020-01-31 09:20:28 -080046 sp<IBinder> waitForService(const String16& name) override;
47
Steven Morelandc68e32d2020-09-24 16:34:21 +000048 bool isDeclared(const String16& name) override;
Brett Chabotc9ee3302020-01-31 09:20:28 -080049
Steven Moreland2e293aa2020-09-23 00:25:16 +000050 Vector<String16> getDeclaredInstances(const String16& iface) override;
51
Steven Morelandedd4e072021-04-21 00:27:29 +000052 std::optional<String16> updatableViaApex(const String16& name) override;
53
Devin Moore5e4c2f12021-09-09 22:36:33 +000054 std::optional<IServiceManager::ConnectionInfo> getConnectionInfo(const String16& name) override;
55
Jayant Chowdhary30700942022-01-31 14:12:40 -080056 status_t registerForNotifications(const String16& name,
57 const sp<LocalRegistrationCallback>& callback) override;
58
59 status_t unregisterForNotifications(const String16& name,
60 const sp<LocalRegistrationCallback>& callback) override;
Brett Chabotc9ee3302020-01-31 09:20:28 -080061private:
62 std::map<String16, sp<IBinder>> mNameToService;
63};
64
65} // namespace android