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 | #include "ServiceManager.h" |
| 18 | |
| 19 | namespace android { |
| 20 | |
| 21 | ServiceManager::ServiceManager() {} |
| 22 | |
| 23 | sp<IBinder> ServiceManager::getService( const String16& name) const { |
| 24 | // Servicemanager is single-threaded and cannot block. This method exists for legacy reasons. |
| 25 | return checkService(name); |
| 26 | } |
| 27 | |
| 28 | sp<IBinder> ServiceManager::checkService( const String16& name) const { |
| 29 | auto it = mNameToService.find(name); |
| 30 | if (it == mNameToService.end()) { |
| 31 | return nullptr; |
| 32 | } |
| 33 | return it->second; |
| 34 | } |
| 35 | |
| 36 | status_t ServiceManager::addService(const String16& name, const sp<IBinder>& service, |
| 37 | bool /*allowIsolated*/, |
| 38 | int /*dumpsysFlags*/) { |
| 39 | mNameToService[name] = service; |
| 40 | return NO_ERROR; |
| 41 | } |
| 42 | |
| 43 | Vector<String16> ServiceManager::listServices(int /*dumpsysFlags*/) { |
| 44 | Vector<String16> services; |
| 45 | for (auto const& [name, service] : mNameToService) { |
| 46 | (void) service; |
| 47 | services.push_back(name); |
| 48 | } |
| 49 | return services; |
| 50 | } |
| 51 | |
| 52 | IBinder* ServiceManager::onAsBinder() { |
| 53 | return nullptr; |
| 54 | } |
| 55 | |
| 56 | sp<IBinder> ServiceManager::waitForService(const String16& name) { |
| 57 | return checkService(name); |
| 58 | } |
| 59 | |
| 60 | bool ServiceManager::isDeclared(const String16& name) { |
| 61 | return mNameToService.find(name) != mNameToService.end(); |
| 62 | } |
| 63 | |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 64 | Vector<String16> ServiceManager::getDeclaredInstances(const String16& name) { |
| 65 | Vector<String16> out; |
| 66 | const String16 prefix = name + String16("/"); |
| 67 | for (const auto& [registeredName, service] : mNameToService) { |
| 68 | (void) service; |
| 69 | if (registeredName.startsWith(prefix)) { |
| 70 | out.add(String16(registeredName.string() + prefix.size())); |
| 71 | } |
| 72 | } |
| 73 | return out; |
| 74 | } |
| 75 | |
Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 76 | std::optional<String16> ServiceManager::updatableViaApex(const String16& name) { |
| 77 | (void)name; |
| 78 | return std::nullopt; |
| 79 | } |
| 80 | |
Devin Moore | 5e4c2f1 | 2021-09-09 22:36:33 +0000 | [diff] [blame] | 81 | std::optional<IServiceManager::ConnectionInfo> ServiceManager::getConnectionInfo( |
| 82 | const String16& name) { |
| 83 | (void)name; |
| 84 | return std::nullopt; |
| 85 | } |
| 86 | |
Jayant Chowdhary | 3070094 | 2022-01-31 14:12:40 -0800 | [diff] [blame] | 87 | status_t ServiceManager::registerForNotifications(const String16&, |
| 88 | const sp<LocalRegistrationCallback>&) { |
| 89 | return INVALID_OPERATION; |
| 90 | } |
| 91 | |
| 92 | status_t ServiceManager::unregisterForNotifications(const String16&, |
| 93 | const sp<LocalRegistrationCallback>&) { |
| 94 | return INVALID_OPERATION; |
| 95 | } |
| 96 | |
Jayant Chowdhary | a0a8eb2 | 2022-05-20 03:30:09 +0000 | [diff] [blame^] | 97 | std::vector<IServiceManager::ServiceDebugInfo> ServiceManager::getServiceDebugInfo() { |
| 98 | std::vector<IServiceManager::ServiceDebugInfo> ret; |
| 99 | return ret; |
| 100 | } |
Brett Chabot | c9ee330 | 2020-01-31 09:20:28 -0800 | [diff] [blame] | 101 | } // namespace android |