| 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> | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 21 | #include <binder/BpBinder.h> | 
|  | 22 | #include <binder/IPCThreadState.h> | 
|  | 23 | #include <binder/ProcessState.h> | 
| Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 24 | #include <binder/Stability.h> | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 25 | #include <cutils/android_filesystem_config.h> | 
|  | 26 | #include <cutils/multiuser.h> | 
| Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 27 | #include <thread> | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 28 |  | 
| Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 29 | #ifndef VENDORSERVICEMANAGER | 
|  | 30 | #include <vintf/VintfObject.h> | 
|  | 31 | #include <vintf/constants.h> | 
|  | 32 | #endif  // !VENDORSERVICEMANAGER | 
|  | 33 |  | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 34 | using ::android::binder::Status; | 
| Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 35 | using ::android::internal::Stability; | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 36 |  | 
|  | 37 | namespace android { | 
|  | 38 |  | 
| Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 39 | #ifndef VENDORSERVICEMANAGER | 
| Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 40 | struct ManifestWithDescription { | 
|  | 41 | std::shared_ptr<const vintf::HalManifest> manifest; | 
|  | 42 | const char* description; | 
|  | 43 | }; | 
|  | 44 | // func true -> stop search and forEachManifest will return true | 
|  | 45 | static bool forEachManifest(const std::function<bool(const ManifestWithDescription&)>& func) { | 
|  | 46 | for (const ManifestWithDescription& mwd : { | 
|  | 47 | ManifestWithDescription{ vintf::VintfObject::GetDeviceHalManifest(), "device" }, | 
|  | 48 | ManifestWithDescription{ vintf::VintfObject::GetFrameworkHalManifest(), "framework" }, | 
|  | 49 | }) { | 
|  | 50 | if (mwd.manifest == nullptr) { | 
|  | 51 | LOG(ERROR) << "NULL VINTF MANIFEST!: " << mwd.description; | 
|  | 52 | // note, we explicitly do not retry here, so that we can detect VINTF | 
|  | 53 | // or other bugs (b/151696835) | 
|  | 54 | continue; | 
|  | 55 | } | 
|  | 56 | if (func(mwd)) return true; | 
|  | 57 | } | 
|  | 58 | return false; | 
|  | 59 | } | 
|  | 60 |  | 
| Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 61 | struct AidlName { | 
|  | 62 | std::string package; | 
|  | 63 | std::string iface; | 
|  | 64 | std::string instance; | 
| Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 65 |  | 
| Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 66 | static bool fill(const std::string& name, AidlName* aname) { | 
|  | 67 | size_t firstSlash = name.find('/'); | 
|  | 68 | size_t lastDot = name.rfind('.', firstSlash); | 
|  | 69 | if (firstSlash == std::string::npos || lastDot == std::string::npos) { | 
|  | 70 | LOG(ERROR) << "VINTF HALs require names in the format type/instance (e.g. " | 
|  | 71 | << "some.package.foo.IFoo/default) but got: " << name; | 
|  | 72 | return false; | 
|  | 73 | } | 
|  | 74 | aname->package = name.substr(0, lastDot); | 
|  | 75 | aname->iface = name.substr(lastDot + 1, firstSlash - lastDot - 1); | 
|  | 76 | aname->instance = name.substr(firstSlash + 1); | 
|  | 77 | return true; | 
|  | 78 | } | 
|  | 79 | }; | 
|  | 80 |  | 
|  | 81 | static bool isVintfDeclared(const std::string& name) { | 
|  | 82 | AidlName aname; | 
|  | 83 | if (!AidlName::fill(name, &aname)) return false; | 
|  | 84 |  | 
|  | 85 | bool found = forEachManifest([&](const ManifestWithDescription& mwd) { | 
|  | 86 | if (mwd.manifest->hasAidlInstance(aname.package, aname.iface, aname.instance)) { | 
| Steven Moreland | 2edde8e | 2020-04-30 17:04:54 -0700 | [diff] [blame] | 87 | LOG(INFO) << "Found " << name << " in " << mwd.description << " VINTF manifest."; | 
| Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 88 | return true; // break | 
| Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 89 | } | 
| Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 90 | return false;  // continue | 
|  | 91 | }); | 
|  | 92 |  | 
|  | 93 | if (!found) { | 
|  | 94 | // Although it is tested, explicitly rebuilding qualified name, in case it | 
|  | 95 | // becomes something unexpected. | 
| Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 96 | LOG(ERROR) << "Could not find " << aname.package << "." << aname.iface << "/" | 
|  | 97 | << aname.instance << " in the VINTF manifest."; | 
| Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 98 | } | 
| Steven Moreland | 2edde8e | 2020-04-30 17:04:54 -0700 | [diff] [blame] | 99 |  | 
| Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 100 | return found; | 
|  | 101 | } | 
|  | 102 |  | 
| Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 103 | static std::optional<std::string> getVintfUpdatableApex(const std::string& name) { | 
|  | 104 | AidlName aname; | 
|  | 105 | if (!AidlName::fill(name, &aname)) return std::nullopt; | 
|  | 106 |  | 
|  | 107 | std::optional<std::string> updatableViaApex; | 
|  | 108 |  | 
|  | 109 | forEachManifest([&](const ManifestWithDescription& mwd) { | 
|  | 110 | mwd.manifest->forEachInstance([&](const auto& manifestInstance) { | 
|  | 111 | if (manifestInstance.format() != vintf::HalFormat::AIDL) return true; | 
|  | 112 | if (manifestInstance.package() != aname.package) return true; | 
|  | 113 | if (manifestInstance.interface() != aname.iface) return true; | 
|  | 114 | if (manifestInstance.instance() != aname.instance) return true; | 
|  | 115 | updatableViaApex = manifestInstance.updatableViaApex(); | 
|  | 116 | return false; // break (libvintf uses opposite convention) | 
|  | 117 | }); | 
|  | 118 | return false; // continue | 
|  | 119 | }); | 
|  | 120 |  | 
|  | 121 | return updatableViaApex; | 
|  | 122 | } | 
|  | 123 |  | 
| Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 124 | static std::vector<std::string> getVintfInstances(const std::string& interface) { | 
|  | 125 | size_t lastDot = interface.rfind('.'); | 
|  | 126 | if (lastDot == std::string::npos) { | 
|  | 127 | LOG(ERROR) << "VINTF interfaces require names in Java package format (e.g. some.package.foo.IFoo) but got: " << interface; | 
|  | 128 | return {}; | 
|  | 129 | } | 
|  | 130 | const std::string package = interface.substr(0, lastDot); | 
|  | 131 | const std::string iface = interface.substr(lastDot+1); | 
|  | 132 |  | 
|  | 133 | std::vector<std::string> ret; | 
|  | 134 | (void)forEachManifest([&](const ManifestWithDescription& mwd) { | 
|  | 135 | auto instances = mwd.manifest->getAidlInstances(package, iface); | 
|  | 136 | ret.insert(ret.end(), instances.begin(), instances.end()); | 
|  | 137 | return false;  // continue | 
|  | 138 | }); | 
|  | 139 |  | 
|  | 140 | return ret; | 
| Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 141 | } | 
| Steven Moreland | b82b8f8 | 2019-10-28 10:52:34 -0700 | [diff] [blame] | 142 |  | 
|  | 143 | static bool meetsDeclarationRequirements(const sp<IBinder>& binder, const std::string& name) { | 
|  | 144 | if (!Stability::requiresVintfDeclaration(binder)) { | 
|  | 145 | return true; | 
|  | 146 | } | 
|  | 147 |  | 
|  | 148 | return isVintfDeclared(name); | 
|  | 149 | } | 
| Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 150 | #endif  // !VENDORSERVICEMANAGER | 
|  | 151 |  | 
| Steven Moreland | d13f08b | 2019-11-18 14:23:09 -0800 | [diff] [blame] | 152 | ServiceManager::ServiceManager(std::unique_ptr<Access>&& access) : mAccess(std::move(access)) { | 
| Steven Moreland | 8d0c9a7 | 2020-04-30 16:51:56 -0700 | [diff] [blame] | 153 | // TODO(b/151696835): reenable performance hack when we solve bug, since with | 
|  | 154 | //     this hack and other fixes, it is unlikely we will see even an ephemeral | 
|  | 155 | //     failure when the manifest parse fails. The goal is that the manifest will | 
|  | 156 | //     be read incorrectly and cause the process trying to register a HAL to | 
|  | 157 | //     fail. If this is in fact an early boot kernel contention issue, then we | 
|  | 158 | //     will get no failure, and by its absence, be signalled to invest more | 
|  | 159 | //     effort in re-adding this performance hack. | 
|  | 160 | // #ifndef VENDORSERVICEMANAGER | 
|  | 161 | //     // can process these at any times, don't want to delay first VINTF client | 
|  | 162 | //     std::thread([] { | 
|  | 163 | //         vintf::VintfObject::GetDeviceHalManifest(); | 
|  | 164 | //         vintf::VintfObject::GetFrameworkHalManifest(); | 
|  | 165 | //     }).detach(); | 
|  | 166 | // #endif  // !VENDORSERVICEMANAGER | 
| Steven Moreland | d13f08b | 2019-11-18 14:23:09 -0800 | [diff] [blame] | 167 | } | 
| Steven Moreland | 130242d | 2019-08-26 17:41:32 -0700 | [diff] [blame] | 168 | ServiceManager::~ServiceManager() { | 
|  | 169 | // this should only happen in tests | 
|  | 170 |  | 
| Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 171 | for (const auto& [name, callbacks] : mNameToRegistrationCallback) { | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 172 | CHECK(!callbacks.empty()) << name; | 
|  | 173 | for (const auto& callback : callbacks) { | 
|  | 174 | CHECK(callback != nullptr) << name; | 
|  | 175 | } | 
|  | 176 | } | 
|  | 177 |  | 
| Steven Moreland | 130242d | 2019-08-26 17:41:32 -0700 | [diff] [blame] | 178 | for (const auto& [name, service] : mNameToService) { | 
|  | 179 | CHECK(service.binder != nullptr) << name; | 
|  | 180 | } | 
|  | 181 | } | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 182 |  | 
|  | 183 | Status ServiceManager::getService(const std::string& name, sp<IBinder>* outBinder) { | 
| Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 184 | *outBinder = tryGetService(name, true); | 
|  | 185 | // returns ok regardless of result for legacy reasons | 
|  | 186 | return Status::ok(); | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 187 | } | 
|  | 188 |  | 
|  | 189 | Status ServiceManager::checkService(const std::string& name, sp<IBinder>* outBinder) { | 
| Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 190 | *outBinder = tryGetService(name, false); | 
|  | 191 | // returns ok regardless of result for legacy reasons | 
|  | 192 | return Status::ok(); | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | sp<IBinder> ServiceManager::tryGetService(const std::string& name, bool startIfNotFound) { | 
| Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 196 | auto ctx = mAccess->getCallingContext(); | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 197 |  | 
| Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 198 | sp<IBinder> out; | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 199 | Service* service = nullptr; | 
| Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 200 | if (auto it = mNameToService.find(name); it != mNameToService.end()) { | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 201 | service = &(it->second); | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 202 |  | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 203 | if (!service->allowIsolated) { | 
| Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 204 | uid_t appid = multiuser_get_app_id(ctx.uid); | 
|  | 205 | bool isIsolated = appid >= AID_ISOLATED_START && appid <= AID_ISOLATED_END; | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 206 |  | 
| Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 207 | if (isIsolated) { | 
|  | 208 | return nullptr; | 
|  | 209 | } | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 210 | } | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 211 | out = service->binder; | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 212 | } | 
|  | 213 |  | 
| Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 214 | if (!mAccess->canFind(ctx, name)) { | 
| Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 215 | return nullptr; | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 216 | } | 
|  | 217 |  | 
| Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 218 | if (!out && startIfNotFound) { | 
|  | 219 | tryStartService(name); | 
|  | 220 | } | 
|  | 221 |  | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 222 | if (out) { | 
|  | 223 | // Setting this guarantee each time we hand out a binder ensures that the client-checking | 
|  | 224 | // loop knows about the event even if the client immediately drops the service | 
|  | 225 | service->guaranteeClient = true; | 
|  | 226 | } | 
|  | 227 |  | 
| Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 228 | return out; | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 229 | } | 
|  | 230 |  | 
| Steven Moreland | 905e2e8 | 2019-07-17 11:05:45 -0700 | [diff] [blame] | 231 | bool isValidServiceName(const std::string& name) { | 
|  | 232 | if (name.size() == 0) return false; | 
|  | 233 | if (name.size() > 127) return false; | 
|  | 234 |  | 
|  | 235 | for (char c : name) { | 
| Steven Moreland | bb7951d | 2019-08-20 16:58:25 -0700 | [diff] [blame] | 236 | if (c == '_' || c == '-' || c == '.' || c == '/') continue; | 
| Steven Moreland | 905e2e8 | 2019-07-17 11:05:45 -0700 | [diff] [blame] | 237 | if (c >= 'a' && c <= 'z') continue; | 
|  | 238 | if (c >= 'A' && c <= 'Z') continue; | 
|  | 239 | if (c >= '0' && c <= '9') continue; | 
|  | 240 | return false; | 
|  | 241 | } | 
|  | 242 |  | 
|  | 243 | return true; | 
|  | 244 | } | 
|  | 245 |  | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 246 | 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] | 247 | auto ctx = mAccess->getCallingContext(); | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 248 |  | 
|  | 249 | // apps cannot add services | 
|  | 250 | if (multiuser_get_app_id(ctx.uid) >= AID_APP) { | 
|  | 251 | return Status::fromExceptionCode(Status::EX_SECURITY); | 
|  | 252 | } | 
|  | 253 |  | 
| Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 254 | if (!mAccess->canAdd(ctx, name)) { | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 255 | return Status::fromExceptionCode(Status::EX_SECURITY); | 
|  | 256 | } | 
|  | 257 |  | 
|  | 258 | if (binder == nullptr) { | 
|  | 259 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); | 
|  | 260 | } | 
|  | 261 |  | 
| Steven Moreland | 905e2e8 | 2019-07-17 11:05:45 -0700 | [diff] [blame] | 262 | if (!isValidServiceName(name)) { | 
|  | 263 | LOG(ERROR) << "Invalid service name: " << name; | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 264 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); | 
|  | 265 | } | 
|  | 266 |  | 
| Steven Moreland | 86a17f8 | 2019-09-10 10:18:00 -0700 | [diff] [blame] | 267 | #ifndef VENDORSERVICEMANAGER | 
|  | 268 | if (!meetsDeclarationRequirements(binder, name)) { | 
|  | 269 | // already logged | 
|  | 270 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); | 
|  | 271 | } | 
|  | 272 | #endif  // !VENDORSERVICEMANAGER | 
|  | 273 |  | 
| Steven Moreland | 88860b0 | 2019-08-12 14:24:14 -0700 | [diff] [blame] | 274 | // implicitly unlinked when the binder is removed | 
| Steven Moreland | b098318 | 2021-04-02 03:14:04 +0000 | [diff] [blame] | 275 | if (binder->remoteBinder() != nullptr && | 
|  | 276 | binder->linkToDeath(sp<ServiceManager>::fromExisting(this)) != OK) { | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 277 | LOG(ERROR) << "Could not linkToDeath when adding " << name; | 
|  | 278 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); | 
|  | 279 | } | 
|  | 280 |  | 
| Devin Moore | 05ffe52 | 2020-08-06 13:58:29 -0700 | [diff] [blame] | 281 | // Overwrite the old service if it exists | 
|  | 282 | mNameToService[name] = Service { | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 283 | .binder = binder, | 
|  | 284 | .allowIsolated = allowIsolated, | 
|  | 285 | .dumpPriority = dumpPriority, | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 286 | .debugPid = ctx.debugPid, | 
| Devin Moore | 05ffe52 | 2020-08-06 13:58:29 -0700 | [diff] [blame] | 287 | }; | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 288 |  | 
| Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 289 | auto it = mNameToRegistrationCallback.find(name); | 
|  | 290 | if (it != mNameToRegistrationCallback.end()) { | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 291 | for (const sp<IServiceCallback>& cb : it->second) { | 
| Devin Moore | 05ffe52 | 2020-08-06 13:58:29 -0700 | [diff] [blame] | 292 | mNameToService[name].guaranteeClient = true; | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 293 | // permission checked in registerForNotifications | 
|  | 294 | cb->onRegistration(name, binder); | 
|  | 295 | } | 
|  | 296 | } | 
|  | 297 |  | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 298 | return Status::ok(); | 
|  | 299 | } | 
|  | 300 |  | 
|  | 301 | Status ServiceManager::listServices(int32_t dumpPriority, std::vector<std::string>* outList) { | 
| Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 302 | if (!mAccess->canList(mAccess->getCallingContext())) { | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 303 | return Status::fromExceptionCode(Status::EX_SECURITY); | 
|  | 304 | } | 
|  | 305 |  | 
|  | 306 | size_t toReserve = 0; | 
|  | 307 | for (auto const& [name, service] : mNameToService) { | 
|  | 308 | (void) name; | 
|  | 309 |  | 
|  | 310 | if (service.dumpPriority & dumpPriority) ++toReserve; | 
|  | 311 | } | 
|  | 312 |  | 
|  | 313 | CHECK(outList->empty()); | 
|  | 314 |  | 
|  | 315 | outList->reserve(toReserve); | 
|  | 316 | for (auto const& [name, service] : mNameToService) { | 
|  | 317 | (void) service; | 
|  | 318 |  | 
|  | 319 | if (service.dumpPriority & dumpPriority) { | 
|  | 320 | outList->push_back(name); | 
|  | 321 | } | 
|  | 322 | } | 
|  | 323 |  | 
|  | 324 | return Status::ok(); | 
|  | 325 | } | 
|  | 326 |  | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 327 | Status ServiceManager::registerForNotifications( | 
|  | 328 | const std::string& name, const sp<IServiceCallback>& callback) { | 
|  | 329 | auto ctx = mAccess->getCallingContext(); | 
|  | 330 |  | 
|  | 331 | if (!mAccess->canFind(ctx, name)) { | 
|  | 332 | return Status::fromExceptionCode(Status::EX_SECURITY); | 
|  | 333 | } | 
|  | 334 |  | 
|  | 335 | if (!isValidServiceName(name)) { | 
|  | 336 | LOG(ERROR) << "Invalid service name: " << name; | 
|  | 337 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); | 
|  | 338 | } | 
|  | 339 |  | 
|  | 340 | if (callback == nullptr) { | 
|  | 341 | return Status::fromExceptionCode(Status::EX_NULL_POINTER); | 
|  | 342 | } | 
|  | 343 |  | 
| Steven Moreland | b098318 | 2021-04-02 03:14:04 +0000 | [diff] [blame] | 344 | if (OK != | 
|  | 345 | IInterface::asBinder(callback)->linkToDeath( | 
|  | 346 | sp<ServiceManager>::fromExisting(this))) { | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 347 | LOG(ERROR) << "Could not linkToDeath when adding " << name; | 
|  | 348 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); | 
|  | 349 | } | 
|  | 350 |  | 
| Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 351 | mNameToRegistrationCallback[name].push_back(callback); | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 352 |  | 
|  | 353 | if (auto it = mNameToService.find(name); it != mNameToService.end()) { | 
|  | 354 | const sp<IBinder>& binder = it->second.binder; | 
|  | 355 |  | 
|  | 356 | // never null if an entry exists | 
|  | 357 | CHECK(binder != nullptr) << name; | 
|  | 358 | callback->onRegistration(name, binder); | 
|  | 359 | } | 
|  | 360 |  | 
|  | 361 | return Status::ok(); | 
|  | 362 | } | 
|  | 363 | Status ServiceManager::unregisterForNotifications( | 
|  | 364 | const std::string& name, const sp<IServiceCallback>& callback) { | 
|  | 365 | auto ctx = mAccess->getCallingContext(); | 
|  | 366 |  | 
|  | 367 | if (!mAccess->canFind(ctx, name)) { | 
|  | 368 | return Status::fromExceptionCode(Status::EX_SECURITY); | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 | bool found = false; | 
|  | 372 |  | 
| Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 373 | auto it = mNameToRegistrationCallback.find(name); | 
|  | 374 | if (it != mNameToRegistrationCallback.end()) { | 
|  | 375 | removeRegistrationCallback(IInterface::asBinder(callback), &it, &found); | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 376 | } | 
|  | 377 |  | 
|  | 378 | if (!found) { | 
|  | 379 | LOG(ERROR) << "Trying to unregister callback, but none exists " << name; | 
|  | 380 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); | 
|  | 381 | } | 
|  | 382 |  | 
|  | 383 | return Status::ok(); | 
|  | 384 | } | 
|  | 385 |  | 
| Steven Moreland | b82b8f8 | 2019-10-28 10:52:34 -0700 | [diff] [blame] | 386 | Status ServiceManager::isDeclared(const std::string& name, bool* outReturn) { | 
|  | 387 | auto ctx = mAccess->getCallingContext(); | 
|  | 388 |  | 
|  | 389 | if (!mAccess->canFind(ctx, name)) { | 
|  | 390 | return Status::fromExceptionCode(Status::EX_SECURITY); | 
|  | 391 | } | 
|  | 392 |  | 
|  | 393 | *outReturn = false; | 
|  | 394 |  | 
|  | 395 | #ifndef VENDORSERVICEMANAGER | 
|  | 396 | *outReturn = isVintfDeclared(name); | 
|  | 397 | #endif | 
|  | 398 | return Status::ok(); | 
|  | 399 | } | 
|  | 400 |  | 
| Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 401 | binder::Status ServiceManager::getDeclaredInstances(const std::string& interface, std::vector<std::string>* outReturn) { | 
|  | 402 | auto ctx = mAccess->getCallingContext(); | 
|  | 403 |  | 
|  | 404 | std::vector<std::string> allInstances; | 
|  | 405 | #ifndef VENDORSERVICEMANAGER | 
|  | 406 | allInstances = getVintfInstances(interface); | 
|  | 407 | #endif | 
|  | 408 |  | 
|  | 409 | outReturn->clear(); | 
|  | 410 |  | 
|  | 411 | for (const std::string& instance : allInstances) { | 
| Steven Moreland | 2e293aa | 2020-09-23 00:25:16 +0000 | [diff] [blame] | 412 | if (mAccess->canFind(ctx, interface + "/" + instance)) { | 
|  | 413 | outReturn->push_back(instance); | 
|  | 414 | } | 
|  | 415 | } | 
|  | 416 |  | 
|  | 417 | if (outReturn->size() == 0 && allInstances.size() != 0) { | 
|  | 418 | return Status::fromExceptionCode(Status::EX_SECURITY); | 
|  | 419 | } | 
|  | 420 |  | 
|  | 421 | return Status::ok(); | 
|  | 422 | } | 
|  | 423 |  | 
| Steven Moreland | edd4e07 | 2021-04-21 00:27:29 +0000 | [diff] [blame] | 424 | Status ServiceManager::updatableViaApex(const std::string& name, | 
|  | 425 | std::optional<std::string>* outReturn) { | 
|  | 426 | auto ctx = mAccess->getCallingContext(); | 
|  | 427 |  | 
|  | 428 | if (!mAccess->canFind(ctx, name)) { | 
|  | 429 | return Status::fromExceptionCode(Status::EX_SECURITY); | 
|  | 430 | } | 
|  | 431 |  | 
|  | 432 | *outReturn = std::nullopt; | 
|  | 433 |  | 
|  | 434 | #ifndef VENDORSERVICEMANAGER | 
|  | 435 | *outReturn = getVintfUpdatableApex(name); | 
|  | 436 | #endif | 
|  | 437 | return Status::ok(); | 
|  | 438 | } | 
|  | 439 |  | 
| Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 440 | void ServiceManager::removeRegistrationCallback(const wp<IBinder>& who, | 
|  | 441 | ServiceCallbackMap::iterator* it, | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 442 | bool* found) { | 
|  | 443 | std::vector<sp<IServiceCallback>>& listeners = (*it)->second; | 
|  | 444 |  | 
|  | 445 | for (auto lit = listeners.begin(); lit != listeners.end();) { | 
|  | 446 | if (IInterface::asBinder(*lit) == who) { | 
|  | 447 | if(found) *found = true; | 
|  | 448 | lit = listeners.erase(lit); | 
|  | 449 | } else { | 
|  | 450 | ++lit; | 
|  | 451 | } | 
|  | 452 | } | 
|  | 453 |  | 
|  | 454 | if (listeners.empty()) { | 
| Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 455 | *it = mNameToRegistrationCallback.erase(*it); | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 456 | } else { | 
| Jon Spivack | e223f08 | 2019-11-19 16:21:20 -0800 | [diff] [blame] | 457 | (*it)++; | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 458 | } | 
|  | 459 | } | 
|  | 460 |  | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 461 | void ServiceManager::binderDied(const wp<IBinder>& who) { | 
|  | 462 | for (auto it = mNameToService.begin(); it != mNameToService.end();) { | 
|  | 463 | if (who == it->second.binder) { | 
|  | 464 | it = mNameToService.erase(it); | 
|  | 465 | } else { | 
|  | 466 | ++it; | 
|  | 467 | } | 
|  | 468 | } | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 469 |  | 
| Jon Spivack | f288b1d | 2019-12-19 17:15:51 -0800 | [diff] [blame] | 470 | for (auto it = mNameToRegistrationCallback.begin(); it != mNameToRegistrationCallback.end();) { | 
|  | 471 | removeRegistrationCallback(who, &it, nullptr /*found*/); | 
| Steven Moreland | 27cfab0 | 2019-08-12 14:34:16 -0700 | [diff] [blame] | 472 | } | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 473 |  | 
|  | 474 | for (auto it = mNameToClientCallback.begin(); it != mNameToClientCallback.end();) { | 
|  | 475 | removeClientCallback(who, &it); | 
|  | 476 | } | 
| Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 477 | } | 
|  | 478 |  | 
| Jon Spivack | 0d84430 | 2019-07-22 18:40:34 -0700 | [diff] [blame] | 479 | void ServiceManager::tryStartService(const std::string& name) { | 
|  | 480 | ALOGI("Since '%s' could not be found, trying to start it as a lazy AIDL service", | 
|  | 481 | name.c_str()); | 
|  | 482 |  | 
|  | 483 | std::thread([=] { | 
|  | 484 | (void)base::SetProperty("ctl.interface_start", "aidl/" + name); | 
|  | 485 | }).detach(); | 
|  | 486 | } | 
|  | 487 |  | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 488 | Status ServiceManager::registerClientCallback(const std::string& name, const sp<IBinder>& service, | 
|  | 489 | const sp<IClientCallback>& cb) { | 
|  | 490 | if (cb == nullptr) { | 
|  | 491 | return Status::fromExceptionCode(Status::EX_NULL_POINTER); | 
|  | 492 | } | 
|  | 493 |  | 
|  | 494 | auto ctx = mAccess->getCallingContext(); | 
|  | 495 | if (!mAccess->canAdd(ctx, name)) { | 
|  | 496 | return Status::fromExceptionCode(Status::EX_SECURITY); | 
|  | 497 | } | 
|  | 498 |  | 
|  | 499 | auto serviceIt = mNameToService.find(name); | 
|  | 500 | if (serviceIt == mNameToService.end()) { | 
|  | 501 | LOG(ERROR) << "Could not add callback for nonexistent service: " << name; | 
|  | 502 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); | 
|  | 503 | } | 
|  | 504 |  | 
|  | 505 | if (serviceIt->second.debugPid != IPCThreadState::self()->getCallingPid()) { | 
|  | 506 | LOG(WARNING) << "Only a server can register for client callbacks (for " << name << ")"; | 
|  | 507 | return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION); | 
|  | 508 | } | 
|  | 509 |  | 
|  | 510 | if (serviceIt->second.binder != service) { | 
|  | 511 | LOG(WARNING) << "Tried to register client callback for " << name | 
|  | 512 | << " but a different service is registered under this name."; | 
|  | 513 | return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT); | 
|  | 514 | } | 
|  | 515 |  | 
| Steven Moreland | b098318 | 2021-04-02 03:14:04 +0000 | [diff] [blame] | 516 | if (OK != | 
|  | 517 | IInterface::asBinder(cb)->linkToDeath(sp<ServiceManager>::fromExisting(this))) { | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 518 | LOG(ERROR) << "Could not linkToDeath when adding client callback for " << name; | 
|  | 519 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); | 
|  | 520 | } | 
|  | 521 |  | 
|  | 522 | mNameToClientCallback[name].push_back(cb); | 
|  | 523 |  | 
|  | 524 | return Status::ok(); | 
|  | 525 | } | 
|  | 526 |  | 
|  | 527 | void ServiceManager::removeClientCallback(const wp<IBinder>& who, | 
|  | 528 | ClientCallbackMap::iterator* it) { | 
|  | 529 | std::vector<sp<IClientCallback>>& listeners = (*it)->second; | 
|  | 530 |  | 
|  | 531 | for (auto lit = listeners.begin(); lit != listeners.end();) { | 
|  | 532 | if (IInterface::asBinder(*lit) == who) { | 
|  | 533 | lit = listeners.erase(lit); | 
|  | 534 | } else { | 
|  | 535 | ++lit; | 
|  | 536 | } | 
|  | 537 | } | 
|  | 538 |  | 
|  | 539 | if (listeners.empty()) { | 
|  | 540 | *it = mNameToClientCallback.erase(*it); | 
|  | 541 | } else { | 
|  | 542 | (*it)++; | 
|  | 543 | } | 
|  | 544 | } | 
|  | 545 |  | 
|  | 546 | ssize_t ServiceManager::Service::getNodeStrongRefCount() { | 
| Steven Moreland | b098318 | 2021-04-02 03:14:04 +0000 | [diff] [blame] | 547 | sp<BpBinder> bpBinder = sp<BpBinder>::fromExisting(binder->remoteBinder()); | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 548 | if (bpBinder == nullptr) return -1; | 
|  | 549 |  | 
| Steven Moreland | e839388 | 2020-12-18 02:27:20 +0000 | [diff] [blame] | 550 | return ProcessState::self()->getStrongRefCountForNode(bpBinder); | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 551 | } | 
|  | 552 |  | 
|  | 553 | void ServiceManager::handleClientCallbacks() { | 
|  | 554 | for (const auto& [name, service] : mNameToService) { | 
| Jon Spivack | d9533c2 | 2020-01-27 22:19:22 +0000 | [diff] [blame] | 555 | handleServiceClientCallback(name, true); | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 556 | } | 
|  | 557 | } | 
|  | 558 |  | 
| Jon Spivack | d9533c2 | 2020-01-27 22:19:22 +0000 | [diff] [blame] | 559 | ssize_t ServiceManager::handleServiceClientCallback(const std::string& serviceName, | 
|  | 560 | bool isCalledOnInterval) { | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 561 | auto serviceIt = mNameToService.find(serviceName); | 
|  | 562 | if (serviceIt == mNameToService.end() || mNameToClientCallback.count(serviceName) < 1) { | 
|  | 563 | return -1; | 
|  | 564 | } | 
|  | 565 |  | 
|  | 566 | Service& service = serviceIt->second; | 
|  | 567 | ssize_t count = service.getNodeStrongRefCount(); | 
|  | 568 |  | 
|  | 569 | // binder driver doesn't support this feature | 
|  | 570 | if (count == -1) return count; | 
|  | 571 |  | 
|  | 572 | bool hasClients = count > 1; // this process holds a strong count | 
|  | 573 |  | 
|  | 574 | if (service.guaranteeClient) { | 
|  | 575 | // we have no record of this client | 
|  | 576 | if (!service.hasClients && !hasClients) { | 
|  | 577 | sendClientCallbackNotifications(serviceName, true); | 
|  | 578 | } | 
|  | 579 |  | 
|  | 580 | // guarantee is temporary | 
|  | 581 | service.guaranteeClient = false; | 
|  | 582 | } | 
|  | 583 |  | 
| Jon Spivack | d9533c2 | 2020-01-27 22:19:22 +0000 | [diff] [blame] | 584 | // only send notifications if this was called via the interval checking workflow | 
|  | 585 | if (isCalledOnInterval) { | 
|  | 586 | if (hasClients && !service.hasClients) { | 
|  | 587 | // client was retrieved in some other way | 
|  | 588 | sendClientCallbackNotifications(serviceName, true); | 
|  | 589 | } | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 590 |  | 
| Jon Spivack | d9533c2 | 2020-01-27 22:19:22 +0000 | [diff] [blame] | 591 | // there are no more clients, but the callback has not been called yet | 
|  | 592 | if (!hasClients && service.hasClients) { | 
|  | 593 | sendClientCallbackNotifications(serviceName, false); | 
|  | 594 | } | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 595 | } | 
|  | 596 |  | 
|  | 597 | return count; | 
|  | 598 | } | 
|  | 599 |  | 
|  | 600 | void ServiceManager::sendClientCallbackNotifications(const std::string& serviceName, bool hasClients) { | 
|  | 601 | auto serviceIt = mNameToService.find(serviceName); | 
|  | 602 | if (serviceIt == mNameToService.end()) { | 
|  | 603 | LOG(WARNING) << "sendClientCallbackNotifications could not find service " << serviceName; | 
|  | 604 | return; | 
|  | 605 | } | 
|  | 606 | Service& service = serviceIt->second; | 
|  | 607 |  | 
|  | 608 | CHECK(hasClients != service.hasClients) << "Record shows: " << service.hasClients | 
|  | 609 | << " so we can't tell clients again that we have client: " << hasClients; | 
|  | 610 |  | 
|  | 611 | LOG(INFO) << "Notifying " << serviceName << " they have clients: " << hasClients; | 
|  | 612 |  | 
|  | 613 | auto ccIt = mNameToClientCallback.find(serviceName); | 
|  | 614 | CHECK(ccIt != mNameToClientCallback.end()) | 
|  | 615 | << "sendClientCallbackNotifications could not find callbacks for service "; | 
|  | 616 |  | 
|  | 617 | for (const auto& callback : ccIt->second) { | 
|  | 618 | callback->onClients(service.binder, hasClients); | 
|  | 619 | } | 
|  | 620 |  | 
|  | 621 | service.hasClients = hasClients; | 
|  | 622 | } | 
|  | 623 |  | 
|  | 624 | Status ServiceManager::tryUnregisterService(const std::string& name, const sp<IBinder>& binder) { | 
|  | 625 | if (binder == nullptr) { | 
|  | 626 | return Status::fromExceptionCode(Status::EX_NULL_POINTER); | 
|  | 627 | } | 
|  | 628 |  | 
|  | 629 | auto ctx = mAccess->getCallingContext(); | 
|  | 630 | if (!mAccess->canAdd(ctx, name)) { | 
|  | 631 | return Status::fromExceptionCode(Status::EX_SECURITY); | 
|  | 632 | } | 
|  | 633 |  | 
|  | 634 | auto serviceIt = mNameToService.find(name); | 
|  | 635 | if (serviceIt == mNameToService.end()) { | 
|  | 636 | LOG(WARNING) << "Tried to unregister " << name | 
|  | 637 | << ", but that service wasn't registered to begin with."; | 
|  | 638 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); | 
|  | 639 | } | 
|  | 640 |  | 
|  | 641 | if (serviceIt->second.debugPid != IPCThreadState::self()->getCallingPid()) { | 
|  | 642 | LOG(WARNING) << "Only a server can unregister itself (for " << name << ")"; | 
|  | 643 | return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION); | 
|  | 644 | } | 
|  | 645 |  | 
|  | 646 | sp<IBinder> storedBinder = serviceIt->second.binder; | 
|  | 647 |  | 
|  | 648 | if (binder != storedBinder) { | 
|  | 649 | LOG(WARNING) << "Tried to unregister " << name | 
|  | 650 | << ", but a different service is registered under this name."; | 
|  | 651 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); | 
|  | 652 | } | 
|  | 653 |  | 
| Jon Spivack | 0f18f2c | 2020-03-13 20:45:18 -0700 | [diff] [blame] | 654 | if (serviceIt->second.guaranteeClient) { | 
|  | 655 | LOG(INFO) << "Tried to unregister " << name << ", but there is about to be a client."; | 
|  | 656 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); | 
|  | 657 | } | 
|  | 658 |  | 
| Jon Spivack | d9533c2 | 2020-01-27 22:19:22 +0000 | [diff] [blame] | 659 | int clients = handleServiceClientCallback(name, false); | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 660 |  | 
|  | 661 | // clients < 0: feature not implemented or other error. Assume clients. | 
|  | 662 | // Otherwise: | 
|  | 663 | // - kernel driver will hold onto one refcount (during this transaction) | 
|  | 664 | // - servicemanager has a refcount (guaranteed by this transaction) | 
|  | 665 | // So, if clients > 2, then at least one other service on the system must hold a refcount. | 
|  | 666 | if (clients < 0 || clients > 2) { | 
|  | 667 | // client callbacks are either disabled or there are other clients | 
| Jon Spivack | d9533c2 | 2020-01-27 22:19:22 +0000 | [diff] [blame] | 668 | LOG(INFO) << "Tried to unregister " << name << ", but there are clients: " << clients; | 
| Jon Spivack | 620d2dc | 2020-03-06 13:58:01 -0800 | [diff] [blame] | 669 | // Set this flag to ensure the clients are acknowledged in the next callback | 
|  | 670 | serviceIt->second.guaranteeClient = true; | 
| Jon Spivack | 9f503a4 | 2019-10-22 16:49:19 -0700 | [diff] [blame] | 671 | return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE); | 
|  | 672 | } | 
|  | 673 |  | 
|  | 674 | mNameToService.erase(name); | 
|  | 675 |  | 
|  | 676 | return Status::ok(); | 
|  | 677 | } | 
|  | 678 |  | 
| Steven Moreland | 3ea4327 | 2021-01-28 22:49:28 +0000 | [diff] [blame] | 679 | Status ServiceManager::getServiceDebugInfo(std::vector<ServiceDebugInfo>* outReturn) { | 
|  | 680 | if (!mAccess->canList(mAccess->getCallingContext())) { | 
|  | 681 | return Status::fromExceptionCode(Status::EX_SECURITY); | 
|  | 682 | } | 
|  | 683 |  | 
|  | 684 | outReturn->reserve(mNameToService.size()); | 
|  | 685 | for (auto const& [name, service] : mNameToService) { | 
|  | 686 | ServiceDebugInfo info; | 
|  | 687 | info.name = name; | 
|  | 688 | info.debugPid = service.debugPid; | 
|  | 689 |  | 
|  | 690 | outReturn->push_back(std::move(info)); | 
|  | 691 | } | 
|  | 692 |  | 
|  | 693 | return Status::ok(); | 
|  | 694 | } | 
|  | 695 |  | 
| Steven Moreland | 8d0c9a7 | 2020-04-30 16:51:56 -0700 | [diff] [blame] | 696 | }  // namespace android |