Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 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 | #include "ServiceManager.h" |
| 18 | |
| 19 | #include <android-base/logging.h> |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 20 | #include <android-base/properties.h> |
Devin Moore | 42407bc | 2023-09-26 21:30:39 +0000 | [diff] [blame] | 21 | #include <android-base/strings.h> |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 22 | #include <binder/BpBinder.h> |
| 23 | #include <binder/IPCThreadState.h> |
| 24 | #include <binder/ProcessState.h> |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 25 | #include <binder/Stability.h> |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 26 | #include <cutils/android_filesystem_config.h> |
| 27 | #include <cutils/multiuser.h> |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 28 | #include <thread> |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 29 | |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 30 | #ifndef VENDORSERVICEMANAGER |
| 31 | #include <vintf/VintfObject.h> |
Yifan Hong | 0a9b56e | 2021-11-30 16:45:40 -0800 | [diff] [blame] | 32 | #ifdef __ANDROID_RECOVERY__ |
| 33 | #include <vintf/VintfObjectRecovery.h> |
| 34 | #endif // __ANDROID_RECOVERY__ |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 35 | #include <vintf/constants.h> |
| 36 | #endif // !VENDORSERVICEMANAGER |
| 37 | |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 38 | using ::android::binder::Status; |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 39 | using ::android::internal::Stability; |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 40 | |
| 41 | namespace android { |
| 42 | |
Steven Moreland | b9e1cbe | 2023-02-01 22:44:45 +0000 | [diff] [blame] | 43 | bool is_multiuser_uid_isolated(uid_t uid) { |
| 44 | uid_t appid = multiuser_get_app_id(uid); |
| 45 | return appid >= AID_ISOLATED_START && appid <= AID_ISOLATED_END; |
| 46 | } |
| 47 | |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 48 | #ifndef VENDORSERVICEMANAGER |
Yifan Hong | 0a9b56e | 2021-11-30 16:45:40 -0800 | [diff] [blame] | 49 | |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 50 | struct ManifestWithDescription { |
| 51 | std::shared_ptr<const vintf::HalManifest> manifest; |
| 52 | const char* description; |
| 53 | }; |
Yifan Hong | 0a9b56e | 2021-11-30 16:45:40 -0800 | [diff] [blame] | 54 | static std::vector<ManifestWithDescription> GetManifestsWithDescription() { |
| 55 | #ifdef __ANDROID_RECOVERY__ |
| 56 | auto vintfObject = vintf::VintfObjectRecovery::GetInstance(); |
| 57 | if (vintfObject == nullptr) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 58 | ALOGE("NULL VintfObjectRecovery!"); |
Yifan Hong | 0a9b56e | 2021-11-30 16:45:40 -0800 | [diff] [blame] | 59 | return {}; |
| 60 | } |
| 61 | return {ManifestWithDescription{vintfObject->getRecoveryHalManifest(), "recovery"}}; |
| 62 | #else |
| 63 | auto vintfObject = vintf::VintfObject::GetInstance(); |
| 64 | if (vintfObject == nullptr) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 65 | ALOGE("NULL VintfObject!"); |
Yifan Hong | 0a9b56e | 2021-11-30 16:45:40 -0800 | [diff] [blame] | 66 | return {}; |
| 67 | } |
| 68 | return {ManifestWithDescription{vintfObject->getDeviceHalManifest(), "device"}, |
| 69 | ManifestWithDescription{vintfObject->getFrameworkHalManifest(), "framework"}}; |
| 70 | #endif |
| 71 | } |
| 72 | |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 73 | // func true -> stop search and forEachManifest will return true |
| 74 | static bool forEachManifest(const std::function<bool(const ManifestWithDescription&)>& func) { |
Yifan Hong | 0a9b56e | 2021-11-30 16:45:40 -0800 | [diff] [blame] | 75 | for (const ManifestWithDescription& mwd : GetManifestsWithDescription()) { |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 76 | if (mwd.manifest == nullptr) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 77 | ALOGE("NULL VINTF MANIFEST!: %s", mwd.description); |
| 78 | // note, we explicitly do not retry here, so that we can detect VINTF |
| 79 | // or other bugs (b/151696835) |
| 80 | continue; |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 81 | } |
| 82 | if (func(mwd)) return true; |
| 83 | } |
| 84 | return false; |
| 85 | } |
| 86 | |
Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 87 | struct AidlName { |
| 88 | std::string package; |
| 89 | std::string iface; |
| 90 | std::string instance; |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 91 | |
Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 92 | static bool fill(const std::string& name, AidlName* aname) { |
| 93 | size_t firstSlash = name.find('/'); |
| 94 | size_t lastDot = name.rfind('.', firstSlash); |
| 95 | if (firstSlash == std::string::npos || lastDot == std::string::npos) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 96 | ALOGE("VINTF HALs require names in the format type/instance (e.g. " |
| 97 | "some.package.foo.IFoo/default) but got: %s", |
| 98 | name.c_str()); |
Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 99 | return false; |
| 100 | } |
| 101 | aname->package = name.substr(0, lastDot); |
| 102 | aname->iface = name.substr(lastDot + 1, firstSlash - lastDot - 1); |
| 103 | aname->instance = name.substr(firstSlash + 1); |
| 104 | return true; |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | static bool isVintfDeclared(const std::string& name) { |
| 109 | AidlName aname; |
| 110 | if (!AidlName::fill(name, &aname)) return false; |
| 111 | |
| 112 | bool found = forEachManifest([&](const ManifestWithDescription& mwd) { |
| 113 | if (mwd.manifest->hasAidlInstance(aname.package, aname.iface, aname.instance)) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 114 | ALOGI("Found %s in %s VINTF manifest.", name.c_str(), mwd.description); |
Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 115 | return true; // break |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 116 | } |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 117 | return false; // continue |
| 118 | }); |
| 119 | |
| 120 | if (!found) { |
Devin Moore | 42407bc | 2023-09-26 21:30:39 +0000 | [diff] [blame] | 121 | std::set<std::string> instances; |
| 122 | forEachManifest([&](const ManifestWithDescription& mwd) { |
| 123 | std::set<std::string> res = mwd.manifest->getAidlInstances(aname.package, aname.iface); |
| 124 | instances.insert(res.begin(), res.end()); |
| 125 | return true; |
| 126 | }); |
| 127 | |
| 128 | std::string available; |
| 129 | if (instances.empty()) { |
| 130 | available = "No alternative instances declared in VINTF"; |
| 131 | } else { |
| 132 | // for logging only. We can't return this information to the client |
| 133 | // because they may not have permissions to find or list those |
| 134 | // instances |
| 135 | available = "VINTF declared instances: " + base::Join(instances, ", "); |
| 136 | } |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 137 | // Although it is tested, explicitly rebuilding qualified name, in case it |
| 138 | // becomes something unexpected. |
Devin Moore | 42407bc | 2023-09-26 21:30:39 +0000 | [diff] [blame] | 139 | ALOGI("Could not find %s.%s/%s in the VINTF manifest. %s.", aname.package.c_str(), |
| 140 | aname.iface.c_str(), aname.instance.c_str(), available.c_str()); |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 141 | } |
Steven Moreland | 2edde8e | 2020-04-30 17:04:54 -0700 | [diff] [blame] | 142 | |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 143 | return found; |
| 144 | } |
| 145 | |
Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 146 | static std::optional<std::string> getVintfUpdatableApex(const std::string& name) { |
| 147 | AidlName aname; |
| 148 | if (!AidlName::fill(name, &aname)) return std::nullopt; |
| 149 | |
| 150 | std::optional<std::string> updatableViaApex; |
| 151 | |
| 152 | forEachManifest([&](const ManifestWithDescription& mwd) { |
| 153 | mwd.manifest->forEachInstance([&](const auto& manifestInstance) { |
| 154 | if (manifestInstance.format() != vintf::HalFormat::AIDL) return true; |
| 155 | if (manifestInstance.package() != aname.package) return true; |
| 156 | if (manifestInstance.interface() != aname.iface) return true; |
| 157 | if (manifestInstance.instance() != aname.instance) return true; |
| 158 | updatableViaApex = manifestInstance.updatableViaApex(); |
| 159 | return false; // break (libvintf uses opposite convention) |
| 160 | }); |
Jooyung Han | ce94b75 | 2022-11-14 18:55:06 +0900 | [diff] [blame] | 161 | if (updatableViaApex.has_value()) return true; // break (found match) |
Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 162 | return false; // continue |
| 163 | }); |
| 164 | |
| 165 | return updatableViaApex; |
| 166 | } |
| 167 | |
Jooyung Han | 76944fe | 2022-10-25 17:02:45 +0900 | [diff] [blame] | 168 | static std::vector<std::string> getVintfUpdatableInstances(const std::string& apexName) { |
| 169 | std::vector<std::string> instances; |
| 170 | |
| 171 | forEachManifest([&](const ManifestWithDescription& mwd) { |
| 172 | mwd.manifest->forEachInstance([&](const auto& manifestInstance) { |
| 173 | if (manifestInstance.format() == vintf::HalFormat::AIDL && |
| 174 | manifestInstance.updatableViaApex().has_value() && |
| 175 | manifestInstance.updatableViaApex().value() == apexName) { |
| 176 | std::string aname = manifestInstance.package() + "." + |
| 177 | manifestInstance.interface() + "/" + manifestInstance.instance(); |
| 178 | instances.push_back(aname); |
| 179 | } |
Jooyung Han | ce94b75 | 2022-11-14 18:55:06 +0900 | [diff] [blame] | 180 | return true; // continue (libvintf uses opposite convention) |
Jooyung Han | 76944fe | 2022-10-25 17:02:45 +0900 | [diff] [blame] | 181 | }); |
| 182 | return false; // continue |
| 183 | }); |
| 184 | |
| 185 | return instances; |
| 186 | } |
| 187 | |
Devin Moore | 5e4c2f1 | 2021-09-09 22:36:33 +0000 | [diff] [blame] | 188 | static std::optional<ConnectionInfo> getVintfConnectionInfo(const std::string& name) { |
| 189 | AidlName aname; |
| 190 | if (!AidlName::fill(name, &aname)) return std::nullopt; |
| 191 | |
| 192 | std::optional<std::string> ip; |
| 193 | std::optional<uint64_t> port; |
| 194 | forEachManifest([&](const ManifestWithDescription& mwd) { |
| 195 | mwd.manifest->forEachInstance([&](const auto& manifestInstance) { |
| 196 | if (manifestInstance.format() != vintf::HalFormat::AIDL) return true; |
| 197 | if (manifestInstance.package() != aname.package) return true; |
| 198 | if (manifestInstance.interface() != aname.iface) return true; |
| 199 | if (manifestInstance.instance() != aname.instance) return true; |
| 200 | ip = manifestInstance.ip(); |
| 201 | port = manifestInstance.port(); |
| 202 | return false; // break (libvintf uses opposite convention) |
| 203 | }); |
| 204 | return false; // continue |
| 205 | }); |
| 206 | |
| 207 | if (ip.has_value() && port.has_value()) { |
| 208 | ConnectionInfo info; |
| 209 | info.ipAddress = *ip; |
| 210 | info.port = *port; |
| 211 | return std::make_optional<ConnectionInfo>(info); |
| 212 | } else { |
| 213 | return std::nullopt; |
| 214 | } |
| 215 | } |
| 216 | |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 217 | static std::vector<std::string> getVintfInstances(const std::string& interface) { |
| 218 | size_t lastDot = interface.rfind('.'); |
| 219 | if (lastDot == std::string::npos) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 220 | ALOGE("VINTF interfaces require names in Java package format (e.g. some.package.foo.IFoo) " |
| 221 | "but got: %s", |
| 222 | interface.c_str()); |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 223 | return {}; |
| 224 | } |
| 225 | const std::string package = interface.substr(0, lastDot); |
| 226 | const std::string iface = interface.substr(lastDot+1); |
| 227 | |
| 228 | std::vector<std::string> ret; |
| 229 | (void)forEachManifest([&](const ManifestWithDescription& mwd) { |
| 230 | auto instances = mwd.manifest->getAidlInstances(package, iface); |
| 231 | ret.insert(ret.end(), instances.begin(), instances.end()); |
| 232 | return false; // continue |
| 233 | }); |
| 234 | |
| 235 | return ret; |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 236 | } |
Steven Moreland | b82b8f8 | 2019-10-28 10:52:34 -0700 | [diff] [blame] | 237 | |
| 238 | static bool meetsDeclarationRequirements(const sp<IBinder>& binder, const std::string& name) { |
| 239 | if (!Stability::requiresVintfDeclaration(binder)) { |
| 240 | return true; |
| 241 | } |
| 242 | |
| 243 | return isVintfDeclared(name); |
| 244 | } |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 245 | #endif // !VENDORSERVICEMANAGER |
| 246 | |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 247 | ServiceManager::Service::~Service() { |
Steven Moreland | cb59156 | 2023-03-06 15:53:44 +0000 | [diff] [blame] | 248 | if (hasClients) { |
| 249 | // only expected to happen on process death, we don't store the service |
| 250 | // name this late (it's in the map that holds this service), but if it |
| 251 | // is happening, we might want to change 'unlinkToDeath' to explicitly |
| 252 | // clear this bit so that we can abort in other cases, where it would |
| 253 | // mean inconsistent logic in servicemanager (unexpected and tested, but |
| 254 | // the original lazy service impl here had that bug). |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 255 | LOG(WARNING) << "a service was removed when there are clients"; |
| 256 | } |
| 257 | } |
| 258 | |
Steven Moreland | d13f08b | 2019-11-18 14:23:09 -0800 | [diff] [blame] | 259 | ServiceManager::ServiceManager(std::unique_ptr<Access>&& access) : mAccess(std::move(access)) { |
Steven Moreland | 8d0c9a7 | 2020-04-30 16:51:56 -0700 | [diff] [blame] | 260 | // TODO(b/151696835): reenable performance hack when we solve bug, since with |
| 261 | // this hack and other fixes, it is unlikely we will see even an ephemeral |
| 262 | // failure when the manifest parse fails. The goal is that the manifest will |
| 263 | // be read incorrectly and cause the process trying to register a HAL to |
| 264 | // fail. If this is in fact an early boot kernel contention issue, then we |
| 265 | // will get no failure, and by its absence, be signalled to invest more |
| 266 | // effort in re-adding this performance hack. |
| 267 | // #ifndef VENDORSERVICEMANAGER |
| 268 | // // can process these at any times, don't want to delay first VINTF client |
| 269 | // std::thread([] { |
| 270 | // vintf::VintfObject::GetDeviceHalManifest(); |
| 271 | // vintf::VintfObject::GetFrameworkHalManifest(); |
| 272 | // }).detach(); |
| 273 | // #endif // !VENDORSERVICEMANAGER |
Steven Moreland | d13f08b | 2019-11-18 14:23:09 -0800 | [diff] [blame] | 274 | } |
Steven Moreland | 130242d | 2019-08-26 17:41:32 -0700 | [diff] [blame] | 275 | ServiceManager::~ServiceManager() { |
| 276 | // this should only happen in tests |
| 277 | |
Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 278 | for (const auto& [name, callbacks] : mNameToRegistrationCallback) { |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 279 | CHECK(!callbacks.empty()) << name; |
| 280 | for (const auto& callback : callbacks) { |
| 281 | CHECK(callback != nullptr) << name; |
| 282 | } |
| 283 | } |
| 284 | |
Steven Moreland | 130242d | 2019-08-26 17:41:32 -0700 | [diff] [blame] | 285 | for (const auto& [name, service] : mNameToService) { |
| 286 | CHECK(service.binder != nullptr) << name; |
| 287 | } |
| 288 | } |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 289 | |
| 290 | Status ServiceManager::getService(const std::string& name, sp<IBinder>* outBinder) { |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 291 | *outBinder = tryGetService(name, true); |
| 292 | // returns ok regardless of result for legacy reasons |
| 293 | return Status::ok(); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | Status ServiceManager::checkService(const std::string& name, sp<IBinder>* outBinder) { |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 297 | *outBinder = tryGetService(name, false); |
| 298 | // returns ok regardless of result for legacy reasons |
| 299 | return Status::ok(); |
| 300 | } |
| 301 | |
| 302 | sp<IBinder> ServiceManager::tryGetService(const std::string& name, bool startIfNotFound) { |
Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 303 | auto ctx = mAccess->getCallingContext(); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 304 | |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 305 | sp<IBinder> out; |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 306 | Service* service = nullptr; |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 307 | if (auto it = mNameToService.find(name); it != mNameToService.end()) { |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 308 | service = &(it->second); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 309 | |
Steven Moreland | b9e1cbe | 2023-02-01 22:44:45 +0000 | [diff] [blame] | 310 | if (!service->allowIsolated && is_multiuser_uid_isolated(ctx.uid)) { |
| 311 | return nullptr; |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 312 | } |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 313 | out = service->binder; |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 316 | if (!mAccess->canFind(ctx, name)) { |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 317 | return nullptr; |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 320 | if (!out && startIfNotFound) { |
Steven Moreland | aa33e85 | 2023-05-10 16:42:15 +0000 | [diff] [blame] | 321 | tryStartService(ctx, name); |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 324 | if (out) { |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 325 | // Force onClients to get sent, and then make sure the timerfd won't clear it |
| 326 | // by setting guaranteeClient again. This logic could be simplified by using |
| 327 | // a time-based guarantee. However, forcing onClients(true) to get sent |
| 328 | // right here is always going to be important for processes serving multiple |
| 329 | // lazy interfaces. |
| 330 | service->guaranteeClient = true; |
| 331 | CHECK(handleServiceClientCallback(2 /* sm + transaction */, name, false)); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 332 | service->guaranteeClient = true; |
| 333 | } |
| 334 | |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 335 | return out; |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Steven Moreland | 905e2e8 | 2019-07-17 11:05:45 -0700 | [diff] [blame] | 338 | bool isValidServiceName(const std::string& name) { |
| 339 | if (name.size() == 0) return false; |
| 340 | if (name.size() > 127) return false; |
| 341 | |
| 342 | for (char c : name) { |
Steven Moreland | bb7951d | 2019-08-20 16:58:25 -0700 | [diff] [blame] | 343 | if (c == '_' || c == '-' || c == '.' || c == '/') continue; |
Steven Moreland | 905e2e8 | 2019-07-17 11:05:45 -0700 | [diff] [blame] | 344 | if (c >= 'a' && c <= 'z') continue; |
| 345 | if (c >= 'A' && c <= 'Z') continue; |
| 346 | if (c >= '0' && c <= '9') continue; |
| 347 | return false; |
| 348 | } |
| 349 | |
| 350 | return true; |
| 351 | } |
| 352 | |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 353 | Status ServiceManager::addService(const std::string& name, const sp<IBinder>& binder, bool allowIsolated, int32_t dumpPriority) { |
Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 354 | auto ctx = mAccess->getCallingContext(); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 355 | |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 356 | if (multiuser_get_app_id(ctx.uid) >= AID_APP) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 357 | return Status::fromExceptionCode(Status::EX_SECURITY, "App UIDs cannot add services."); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 360 | if (!mAccess->canAdd(ctx, name)) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 361 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | if (binder == nullptr) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 365 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Null binder."); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Steven Moreland | 905e2e8 | 2019-07-17 11:05:45 -0700 | [diff] [blame] | 368 | if (!isValidServiceName(name)) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 369 | ALOGE("Invalid service name: %s", name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 370 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Invalid service name."); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 373 | #ifndef VENDORSERVICEMANAGER |
| 374 | if (!meetsDeclarationRequirements(binder, name)) { |
| 375 | // already logged |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 376 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "VINTF declaration error."); |
Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 377 | } |
| 378 | #endif // !VENDORSERVICEMANAGER |
| 379 | |
Devin Moore | 4e21def | 2023-02-24 21:54:14 +0000 | [diff] [blame] | 380 | if ((dumpPriority & DUMP_FLAG_PRIORITY_ALL) == 0) { |
| 381 | ALOGW("Dump flag priority is not set when adding %s", name.c_str()); |
| 382 | } |
| 383 | |
Steven Moreland | 88860b0 | 2019-08-12 14:24:14 -0700 | [diff] [blame] | 384 | // implicitly unlinked when the binder is removed |
Steven Moreland | b098318 | 2021-04-02 03:14:04 +0000 | [diff] [blame] | 385 | if (binder->remoteBinder() != nullptr && |
| 386 | binder->linkToDeath(sp<ServiceManager>::fromExisting(this)) != OK) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 387 | ALOGE("Could not linkToDeath when adding %s", name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 388 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "Couldn't linkToDeath."); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 391 | auto it = mNameToService.find(name); |
Steven Moreland | 7957867 | 2023-04-27 19:38:00 +0000 | [diff] [blame] | 392 | bool prevClients = false; |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 393 | if (it != mNameToService.end()) { |
| 394 | const Service& existing = it->second; |
Steven Moreland | 7957867 | 2023-04-27 19:38:00 +0000 | [diff] [blame] | 395 | prevClients = existing.hasClients; |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 396 | |
| 397 | // We could do better than this because if the other service dies, it |
| 398 | // may not have an entry here. However, this case is unlikely. We are |
| 399 | // only trying to detect when two different services are accidentally installed. |
| 400 | |
| 401 | if (existing.ctx.uid != ctx.uid) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 402 | ALOGW("Service '%s' originally registered from UID %u but it is now being registered " |
| 403 | "from UID %u. Multiple instances installed?", |
| 404 | name.c_str(), existing.ctx.uid, ctx.uid); |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | if (existing.ctx.sid != ctx.sid) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 408 | ALOGW("Service '%s' originally registered from SID %s but it is now being registered " |
| 409 | "from SID %s. Multiple instances installed?", |
| 410 | name.c_str(), existing.ctx.sid.c_str(), ctx.sid.c_str()); |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 413 | ALOGI("Service '%s' originally registered from PID %d but it is being registered again " |
| 414 | "from PID %d. Bad state? Late death notification? Multiple instances installed?", |
| 415 | name.c_str(), existing.ctx.debugPid, ctx.debugPid); |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Devin Moore | 05ffe52 | 2020-08-06 13:58:29 -0700 | [diff] [blame] | 418 | // Overwrite the old service if it exists |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 419 | mNameToService[name] = Service{ |
| 420 | .binder = binder, |
| 421 | .allowIsolated = allowIsolated, |
| 422 | .dumpPriority = dumpPriority, |
Steven Moreland | 7957867 | 2023-04-27 19:38:00 +0000 | [diff] [blame] | 423 | .hasClients = prevClients, // see b/279898063, matters if existing callbacks |
Steven Moreland | efea66b | 2023-06-17 01:59:34 +0000 | [diff] [blame] | 424 | .guaranteeClient = false, |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 425 | .ctx = ctx, |
Devin Moore | 05ffe52 | 2020-08-06 13:58:29 -0700 | [diff] [blame] | 426 | }; |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 427 | |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 428 | if (auto it = mNameToRegistrationCallback.find(name); it != mNameToRegistrationCallback.end()) { |
Steven Moreland | efea66b | 2023-06-17 01:59:34 +0000 | [diff] [blame] | 429 | // If someone is currently waiting on the service, notify the service that |
| 430 | // we're waiting and flush it to the service. |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 431 | mNameToService[name].guaranteeClient = true; |
| 432 | CHECK(handleServiceClientCallback(2 /* sm + transaction */, name, false)); |
| 433 | mNameToService[name].guaranteeClient = true; |
| 434 | |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 435 | for (const sp<IServiceCallback>& cb : it->second) { |
| 436 | // permission checked in registerForNotifications |
| 437 | cb->onRegistration(name, binder); |
| 438 | } |
| 439 | } |
| 440 | |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 441 | return Status::ok(); |
| 442 | } |
| 443 | |
| 444 | Status ServiceManager::listServices(int32_t dumpPriority, std::vector<std::string>* outList) { |
Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 445 | if (!mAccess->canList(mAccess->getCallingContext())) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 446 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | size_t toReserve = 0; |
| 450 | for (auto const& [name, service] : mNameToService) { |
| 451 | (void) name; |
| 452 | |
| 453 | if (service.dumpPriority & dumpPriority) ++toReserve; |
| 454 | } |
| 455 | |
| 456 | CHECK(outList->empty()); |
| 457 | |
| 458 | outList->reserve(toReserve); |
| 459 | for (auto const& [name, service] : mNameToService) { |
| 460 | (void) service; |
| 461 | |
| 462 | if (service.dumpPriority & dumpPriority) { |
| 463 | outList->push_back(name); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | return Status::ok(); |
| 468 | } |
| 469 | |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 470 | Status ServiceManager::registerForNotifications( |
| 471 | const std::string& name, const sp<IServiceCallback>& callback) { |
| 472 | auto ctx = mAccess->getCallingContext(); |
| 473 | |
| 474 | if (!mAccess->canFind(ctx, name)) { |
Steven Moreland | b9e1cbe | 2023-02-01 22:44:45 +0000 | [diff] [blame] | 475 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux"); |
| 476 | } |
| 477 | |
| 478 | // note - we could allow isolated apps to get notifications if we |
| 479 | // keep track of isolated callbacks and non-isolated callbacks, but |
| 480 | // this is done since isolated apps shouldn't access lazy services |
| 481 | // so we should be able to use different APIs to keep things simple. |
| 482 | // Here, we disallow everything, because the service might not be |
| 483 | // registered yet. |
| 484 | if (is_multiuser_uid_isolated(ctx.uid)) { |
| 485 | return Status::fromExceptionCode(Status::EX_SECURITY, "isolated app"); |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | if (!isValidServiceName(name)) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 489 | ALOGE("Invalid service name: %s", name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 490 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Invalid service name."); |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | if (callback == nullptr) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 494 | return Status::fromExceptionCode(Status::EX_NULL_POINTER, "Null callback."); |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Steven Moreland | b098318 | 2021-04-02 03:14:04 +0000 | [diff] [blame] | 497 | if (OK != |
| 498 | IInterface::asBinder(callback)->linkToDeath( |
| 499 | sp<ServiceManager>::fromExisting(this))) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 500 | ALOGE("Could not linkToDeath when adding %s", name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 501 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "Couldn't link to death."); |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 504 | mNameToRegistrationCallback[name].push_back(callback); |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 505 | |
| 506 | if (auto it = mNameToService.find(name); it != mNameToService.end()) { |
| 507 | const sp<IBinder>& binder = it->second.binder; |
| 508 | |
| 509 | // never null if an entry exists |
| 510 | CHECK(binder != nullptr) << name; |
| 511 | callback->onRegistration(name, binder); |
| 512 | } |
| 513 | |
| 514 | return Status::ok(); |
| 515 | } |
| 516 | Status ServiceManager::unregisterForNotifications( |
| 517 | const std::string& name, const sp<IServiceCallback>& callback) { |
| 518 | auto ctx = mAccess->getCallingContext(); |
| 519 | |
| 520 | if (!mAccess->canFind(ctx, name)) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 521 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | bool found = false; |
| 525 | |
Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 526 | auto it = mNameToRegistrationCallback.find(name); |
| 527 | if (it != mNameToRegistrationCallback.end()) { |
| 528 | removeRegistrationCallback(IInterface::asBinder(callback), &it, &found); |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | if (!found) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 532 | ALOGE("Trying to unregister callback, but none exists %s", name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 533 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "Nothing to unregister."); |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | return Status::ok(); |
| 537 | } |
| 538 | |
Steven Moreland | b82b8f8 | 2019-10-28 10:52:34 -0700 | [diff] [blame] | 539 | Status ServiceManager::isDeclared(const std::string& name, bool* outReturn) { |
| 540 | auto ctx = mAccess->getCallingContext(); |
| 541 | |
| 542 | if (!mAccess->canFind(ctx, name)) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 543 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); |
Steven Moreland | b82b8f8 | 2019-10-28 10:52:34 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | *outReturn = false; |
| 547 | |
| 548 | #ifndef VENDORSERVICEMANAGER |
| 549 | *outReturn = isVintfDeclared(name); |
| 550 | #endif |
| 551 | return Status::ok(); |
| 552 | } |
| 553 | |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 554 | binder::Status ServiceManager::getDeclaredInstances(const std::string& interface, std::vector<std::string>* outReturn) { |
| 555 | auto ctx = mAccess->getCallingContext(); |
| 556 | |
| 557 | std::vector<std::string> allInstances; |
| 558 | #ifndef VENDORSERVICEMANAGER |
| 559 | allInstances = getVintfInstances(interface); |
| 560 | #endif |
| 561 | |
| 562 | outReturn->clear(); |
| 563 | |
| 564 | for (const std::string& instance : allInstances) { |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 565 | if (mAccess->canFind(ctx, interface + "/" + instance)) { |
| 566 | outReturn->push_back(instance); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | if (outReturn->size() == 0 && allInstances.size() != 0) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 571 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); |
Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | return Status::ok(); |
| 575 | } |
| 576 | |
Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 577 | Status ServiceManager::updatableViaApex(const std::string& name, |
| 578 | std::optional<std::string>* outReturn) { |
| 579 | auto ctx = mAccess->getCallingContext(); |
| 580 | |
| 581 | if (!mAccess->canFind(ctx, name)) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 582 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); |
Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | *outReturn = std::nullopt; |
| 586 | |
| 587 | #ifndef VENDORSERVICEMANAGER |
| 588 | *outReturn = getVintfUpdatableApex(name); |
| 589 | #endif |
| 590 | return Status::ok(); |
| 591 | } |
| 592 | |
Jooyung Han | 76944fe | 2022-10-25 17:02:45 +0900 | [diff] [blame] | 593 | Status ServiceManager::getUpdatableNames([[maybe_unused]] const std::string& apexName, |
| 594 | std::vector<std::string>* outReturn) { |
| 595 | auto ctx = mAccess->getCallingContext(); |
| 596 | |
| 597 | std::vector<std::string> apexUpdatableInstances; |
| 598 | #ifndef VENDORSERVICEMANAGER |
| 599 | apexUpdatableInstances = getVintfUpdatableInstances(apexName); |
| 600 | #endif |
| 601 | |
| 602 | outReturn->clear(); |
| 603 | |
| 604 | for (const std::string& instance : apexUpdatableInstances) { |
| 605 | if (mAccess->canFind(ctx, instance)) { |
| 606 | outReturn->push_back(instance); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if (outReturn->size() == 0 && apexUpdatableInstances.size() != 0) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 611 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); |
Jooyung Han | 76944fe | 2022-10-25 17:02:45 +0900 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | return Status::ok(); |
| 615 | } |
| 616 | |
Devin Moore | 5e4c2f1 | 2021-09-09 22:36:33 +0000 | [diff] [blame] | 617 | Status ServiceManager::getConnectionInfo(const std::string& name, |
| 618 | std::optional<ConnectionInfo>* outReturn) { |
| 619 | auto ctx = mAccess->getCallingContext(); |
| 620 | |
| 621 | if (!mAccess->canFind(ctx, name)) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 622 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); |
Devin Moore | 5e4c2f1 | 2021-09-09 22:36:33 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | *outReturn = std::nullopt; |
| 626 | |
| 627 | #ifndef VENDORSERVICEMANAGER |
| 628 | *outReturn = getVintfConnectionInfo(name); |
| 629 | #endif |
| 630 | return Status::ok(); |
| 631 | } |
| 632 | |
Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 633 | void ServiceManager::removeRegistrationCallback(const wp<IBinder>& who, |
| 634 | ServiceCallbackMap::iterator* it, |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 635 | bool* found) { |
| 636 | std::vector<sp<IServiceCallback>>& listeners = (*it)->second; |
| 637 | |
| 638 | for (auto lit = listeners.begin(); lit != listeners.end();) { |
| 639 | if (IInterface::asBinder(*lit) == who) { |
| 640 | if(found) *found = true; |
| 641 | lit = listeners.erase(lit); |
| 642 | } else { |
| 643 | ++lit; |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | if (listeners.empty()) { |
Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 648 | *it = mNameToRegistrationCallback.erase(*it); |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 649 | } else { |
Jon Spivack | e223f08 | 2019-11-19 16:21:20 -0800 | [diff] [blame] | 650 | (*it)++; |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 654 | void ServiceManager::binderDied(const wp<IBinder>& who) { |
| 655 | for (auto it = mNameToService.begin(); it != mNameToService.end();) { |
| 656 | if (who == it->second.binder) { |
Steven Moreland | 7957867 | 2023-04-27 19:38:00 +0000 | [diff] [blame] | 657 | // TODO: currently, this entry contains the state also |
| 658 | // associated with mNameToClientCallback. If we allowed |
| 659 | // other processes to register client callbacks, we |
| 660 | // would have to preserve hasClients (perhaps moving |
| 661 | // that state into mNameToClientCallback, which is complicated |
| 662 | // because those callbacks are associated w/ particular binder |
| 663 | // objects, though they are indexed by name now, they may |
| 664 | // need to be indexed by binder at that point). |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 665 | it = mNameToService.erase(it); |
| 666 | } else { |
| 667 | ++it; |
| 668 | } |
| 669 | } |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 670 | |
Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 671 | for (auto it = mNameToRegistrationCallback.begin(); it != mNameToRegistrationCallback.end();) { |
| 672 | removeRegistrationCallback(who, &it, nullptr /*found*/); |
Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 673 | } |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 674 | |
| 675 | for (auto it = mNameToClientCallback.begin(); it != mNameToClientCallback.end();) { |
| 676 | removeClientCallback(who, &it); |
| 677 | } |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Steven Moreland | aa33e85 | 2023-05-10 16:42:15 +0000 | [diff] [blame] | 680 | void ServiceManager::tryStartService(const Access::CallingContext& ctx, const std::string& name) { |
| 681 | ALOGI("Since '%s' could not be found (requested by debug pid %d), trying to start it as a lazy " |
| 682 | "AIDL service. (if it's not configured to be a lazy service, it may be stuck starting or " |
| 683 | "still starting).", |
| 684 | name.c_str(), ctx.debugPid); |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 685 | |
| 686 | std::thread([=] { |
Steven Moreland | bfe9fba | 2021-04-27 18:39:57 +0000 | [diff] [blame] | 687 | if (!base::SetProperty("ctl.interface_start", "aidl/" + name)) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 688 | ALOGI("Tried to start aidl service %s as a lazy service, but was unable to. Usually " |
| 689 | "this happens when a " |
| 690 | "service is not installed, but if the service is intended to be used as a " |
| 691 | "lazy service, then it may be configured incorrectly.", |
| 692 | name.c_str()); |
Steven Moreland | bfe9fba | 2021-04-27 18:39:57 +0000 | [diff] [blame] | 693 | } |
Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 694 | }).detach(); |
| 695 | } |
| 696 | |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 697 | Status ServiceManager::registerClientCallback(const std::string& name, const sp<IBinder>& service, |
| 698 | const sp<IClientCallback>& cb) { |
| 699 | if (cb == nullptr) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 700 | return Status::fromExceptionCode(Status::EX_NULL_POINTER, "Callback null."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | auto ctx = mAccess->getCallingContext(); |
| 704 | if (!mAccess->canAdd(ctx, name)) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 705 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | auto serviceIt = mNameToService.find(name); |
| 709 | if (serviceIt == mNameToService.end()) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 710 | ALOGE("Could not add callback for nonexistent service: %s", name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 711 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Service doesn't exist."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 714 | if (serviceIt->second.ctx.debugPid != IPCThreadState::self()->getCallingPid()) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 715 | ALOGW("Only a server can register for client callbacks (for %s)", name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 716 | return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION, |
| 717 | "Only service can register client callback for itself."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | if (serviceIt->second.binder != service) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 721 | ALOGW("Tried to register client callback for %s but a different service is registered " |
| 722 | "under this name.", |
| 723 | name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 724 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT, "Service mismatch."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Steven Moreland | b098318 | 2021-04-02 03:14:04 +0000 | [diff] [blame] | 727 | if (OK != |
| 728 | IInterface::asBinder(cb)->linkToDeath(sp<ServiceManager>::fromExisting(this))) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 729 | ALOGE("Could not linkToDeath when adding client callback for %s", name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 730 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "Couldn't linkToDeath."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Steven Moreland | 7957867 | 2023-04-27 19:38:00 +0000 | [diff] [blame] | 733 | // WARNING: binderDied makes an assumption about this. If we open up client |
| 734 | // callbacks to other services, certain race conditions may lead to services |
| 735 | // getting extra client callback notifications. |
| 736 | // Make sure all callbacks have been told about a consistent state - b/278038751 |
Steven Moreland | 7bb4ab8 | 2023-04-13 20:29:33 +0000 | [diff] [blame] | 737 | if (serviceIt->second.hasClients) { |
| 738 | cb->onClients(service, true); |
| 739 | } |
| 740 | |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 741 | mNameToClientCallback[name].push_back(cb); |
| 742 | |
Steven Moreland | efea66b | 2023-06-17 01:59:34 +0000 | [diff] [blame] | 743 | // Flush updated info to client callbacks (especially if guaranteeClient |
| 744 | // and !hasClient, see b/285202885). We may or may not have clients at |
| 745 | // this point, so ignore the return value. |
| 746 | (void)handleServiceClientCallback(2 /* sm + transaction */, name, false); |
| 747 | |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 748 | return Status::ok(); |
| 749 | } |
| 750 | |
| 751 | void ServiceManager::removeClientCallback(const wp<IBinder>& who, |
| 752 | ClientCallbackMap::iterator* it) { |
| 753 | std::vector<sp<IClientCallback>>& listeners = (*it)->second; |
| 754 | |
| 755 | for (auto lit = listeners.begin(); lit != listeners.end();) { |
| 756 | if (IInterface::asBinder(*lit) == who) { |
| 757 | lit = listeners.erase(lit); |
| 758 | } else { |
| 759 | ++lit; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | if (listeners.empty()) { |
| 764 | *it = mNameToClientCallback.erase(*it); |
| 765 | } else { |
| 766 | (*it)++; |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | ssize_t ServiceManager::Service::getNodeStrongRefCount() { |
Steven Moreland | b098318 | 2021-04-02 03:14:04 +0000 | [diff] [blame] | 771 | sp<BpBinder> bpBinder = sp<BpBinder>::fromExisting(binder->remoteBinder()); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 772 | if (bpBinder == nullptr) return -1; |
| 773 | |
Steven Moreland | e839388 | 2020-12-18 02:27:20 +0000 | [diff] [blame] | 774 | return ProcessState::self()->getStrongRefCountForNode(bpBinder); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | void ServiceManager::handleClientCallbacks() { |
| 778 | for (const auto& [name, service] : mNameToService) { |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 779 | handleServiceClientCallback(1 /* sm has one refcount */, name, true); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 783 | bool ServiceManager::handleServiceClientCallback(size_t knownClients, |
| 784 | const std::string& serviceName, |
| 785 | bool isCalledOnInterval) { |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 786 | auto serviceIt = mNameToService.find(serviceName); |
| 787 | if (serviceIt == mNameToService.end() || mNameToClientCallback.count(serviceName) < 1) { |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 788 | return true; // return we do have clients a.k.a. DON'T DO ANYTHING |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | Service& service = serviceIt->second; |
| 792 | ssize_t count = service.getNodeStrongRefCount(); |
| 793 | |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 794 | // binder driver doesn't support this feature, consider we have clients |
| 795 | if (count == -1) return true; |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 796 | |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 797 | bool hasKernelReportedClients = static_cast<size_t>(count) > knownClients; |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 798 | |
| 799 | if (service.guaranteeClient) { |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 800 | if (!service.hasClients && !hasKernelReportedClients) { |
Steven Moreland | 3e083b2 | 2023-01-26 00:46:30 +0000 | [diff] [blame] | 801 | sendClientCallbackNotifications(serviceName, true, |
| 802 | "service is guaranteed to be in use"); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | // guarantee is temporary |
| 806 | service.guaranteeClient = false; |
| 807 | } |
| 808 | |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 809 | // Regardless of this situation, we want to give this notification as soon as possible. |
| 810 | // This way, we have a chance of preventing further thrashing. |
| 811 | if (hasKernelReportedClients && !service.hasClients) { |
| 812 | sendClientCallbackNotifications(serviceName, true, "we now have a record of a client"); |
| 813 | } |
Steven Moreland | 6641765 | 2023-02-01 22:19:41 +0000 | [diff] [blame] | 814 | |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 815 | // But limit rate of shutting down service. |
| 816 | if (isCalledOnInterval) { |
| 817 | if (!hasKernelReportedClients && service.hasClients) { |
Steven Moreland | 3e083b2 | 2023-01-26 00:46:30 +0000 | [diff] [blame] | 818 | sendClientCallbackNotifications(serviceName, false, |
| 819 | "we now have no record of a client"); |
Jon Spivack | d9533c2 | 2020-01-27 22:19:22 +0000 | [diff] [blame] | 820 | } |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 823 | // May be different than 'hasKernelReportedClients'. We intentionally delay |
| 824 | // information about clients going away to reduce thrashing. |
| 825 | return service.hasClients; |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Steven Moreland | 3e083b2 | 2023-01-26 00:46:30 +0000 | [diff] [blame] | 828 | void ServiceManager::sendClientCallbackNotifications(const std::string& serviceName, |
| 829 | bool hasClients, const char* context) { |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 830 | auto serviceIt = mNameToService.find(serviceName); |
| 831 | if (serviceIt == mNameToService.end()) { |
Steven Moreland | 3e083b2 | 2023-01-26 00:46:30 +0000 | [diff] [blame] | 832 | ALOGW("sendClientCallbackNotifications could not find service %s when %s", |
| 833 | serviceName.c_str(), context); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 834 | return; |
| 835 | } |
| 836 | Service& service = serviceIt->second; |
| 837 | |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 838 | CHECK_NE(hasClients, service.hasClients) << context; |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 839 | |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 840 | ALOGI("Notifying %s they %s (previously: %s) have clients when %s", serviceName.c_str(), |
| 841 | hasClients ? "do" : "don't", service.hasClients ? "do" : "don't", context); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 842 | |
| 843 | auto ccIt = mNameToClientCallback.find(serviceName); |
| 844 | CHECK(ccIt != mNameToClientCallback.end()) |
Steven Moreland | 3e083b2 | 2023-01-26 00:46:30 +0000 | [diff] [blame] | 845 | << "sendClientCallbackNotifications could not find callbacks for service when " |
| 846 | << context; |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 847 | |
| 848 | for (const auto& callback : ccIt->second) { |
| 849 | callback->onClients(service.binder, hasClients); |
| 850 | } |
| 851 | |
| 852 | service.hasClients = hasClients; |
| 853 | } |
| 854 | |
| 855 | Status ServiceManager::tryUnregisterService(const std::string& name, const sp<IBinder>& binder) { |
| 856 | if (binder == nullptr) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 857 | return Status::fromExceptionCode(Status::EX_NULL_POINTER, "Null service."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | auto ctx = mAccess->getCallingContext(); |
| 861 | if (!mAccess->canAdd(ctx, name)) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 862 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | auto serviceIt = mNameToService.find(name); |
| 866 | if (serviceIt == mNameToService.end()) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 867 | ALOGW("Tried to unregister %s, but that service wasn't registered to begin with.", |
| 868 | name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 869 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "Service not registered."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 872 | if (serviceIt->second.ctx.debugPid != IPCThreadState::self()->getCallingPid()) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 873 | ALOGW("Only a server can unregister itself (for %s)", name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 874 | return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION, |
| 875 | "Service can only unregister itself."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | sp<IBinder> storedBinder = serviceIt->second.binder; |
| 879 | |
| 880 | if (binder != storedBinder) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 881 | ALOGW("Tried to unregister %s, but a different service is registered under this name.", |
| 882 | name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 883 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, |
| 884 | "Different service registered under this name."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 887 | // important because we don't have timer-based guarantees, we don't want to clear |
| 888 | // this |
Jon Spivack | 0f18f2c | 2020-03-13 20:45:18 -0700 | [diff] [blame] | 889 | if (serviceIt->second.guaranteeClient) { |
Pawan Wagh | 3752616 | 2022-09-29 21:55:26 +0000 | [diff] [blame] | 890 | ALOGI("Tried to unregister %s, but there is about to be a client.", name.c_str()); |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 891 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, |
| 892 | "Can't unregister, pending client."); |
Jon Spivack | 0f18f2c | 2020-03-13 20:45:18 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 895 | // - kernel driver will hold onto one refcount (during this transaction) |
| 896 | // - servicemanager has a refcount (guaranteed by this transaction) |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 897 | constexpr size_t kKnownClients = 2; |
| 898 | |
| 899 | if (handleServiceClientCallback(kKnownClients, name, false)) { |
| 900 | ALOGI("Tried to unregister %s, but there are clients.", name.c_str()); |
| 901 | |
| 902 | // Since we had a failed registration attempt, and the HIDL implementation of |
| 903 | // delaying service shutdown for multiple periods wasn't ported here... this may |
| 904 | // help reduce thrashing, but we should be able to remove it. |
Jon Spivack | 620d2dc | 2020-03-06 13:58:01 -0800 | [diff] [blame] | 905 | serviceIt->second.guaranteeClient = true; |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 906 | |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 907 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, |
| 908 | "Can't unregister, known client."); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Steven Moreland | b836190 | 2023-02-01 23:18:04 +0000 | [diff] [blame] | 911 | ALOGI("Unregistering %s", name.c_str()); |
Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 912 | mNameToService.erase(name); |
| 913 | |
| 914 | return Status::ok(); |
| 915 | } |
| 916 | |
Steven Moreland | 3ea4327 | 2021-01-28 22:49:28 +0000 | [diff] [blame] | 917 | Status ServiceManager::getServiceDebugInfo(std::vector<ServiceDebugInfo>* outReturn) { |
| 918 | if (!mAccess->canList(mAccess->getCallingContext())) { |
Steven Moreland | ffb905b | 2023-03-28 18:24:37 +0000 | [diff] [blame] | 919 | return Status::fromExceptionCode(Status::EX_SECURITY, "SELinux denied."); |
Steven Moreland | 3ea4327 | 2021-01-28 22:49:28 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | outReturn->reserve(mNameToService.size()); |
| 923 | for (auto const& [name, service] : mNameToService) { |
| 924 | ServiceDebugInfo info; |
| 925 | info.name = name; |
Steven Moreland | 7ee423b | 2022-09-24 03:52:08 +0000 | [diff] [blame] | 926 | info.debugPid = service.ctx.debugPid; |
Steven Moreland | 3ea4327 | 2021-01-28 22:49:28 +0000 | [diff] [blame] | 927 | |
| 928 | outReturn->push_back(std::move(info)); |
| 929 | } |
| 930 | |
| 931 | return Status::ok(); |
| 932 | } |
| 933 | |
Pawan Wagh | 243888e | 2022-09-20 19:37:35 +0000 | [diff] [blame] | 934 | void ServiceManager::clear() { |
| 935 | mNameToService.clear(); |
| 936 | mNameToRegistrationCallback.clear(); |
| 937 | mNameToClientCallback.clear(); |
| 938 | } |
| 939 | |
Steven Moreland | 8d0c9a7 | 2020-04-30 16:51:56 -0700 | [diff] [blame] | 940 | } // namespace android |