Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2024 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 | #include "BackendUnifiedServiceManager.h" |
| 17 | |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 18 | #include <android/os/IAccessor.h> |
| 19 | #include <binder/RpcSession.h> |
| 20 | |
Tomasz Wasilczyk | fe25f12 | 2024-06-26 12:45:57 -0700 | [diff] [blame] | 21 | #if defined(__BIONIC__) && !defined(__ANDROID_VNDK__) |
| 22 | #include <android-base/properties.h> |
| 23 | #endif |
| 24 | |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 25 | namespace android { |
| 26 | |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 27 | #ifdef LIBBINDER_CLIENT_CACHE |
| 28 | constexpr bool kUseCache = true; |
| 29 | #else |
| 30 | constexpr bool kUseCache = false; |
| 31 | #endif |
| 32 | |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 33 | using AidlServiceManager = android::os::IServiceManager; |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 34 | using android::os::IAccessor; |
| 35 | using binder::Status; |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 36 | |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 37 | static const char* kStaticCachableList[] = { |
Parth Sane | ac49270 | 2024-09-18 15:54:16 +0000 | [diff] [blame] | 38 | // go/keep-sorted start |
| 39 | "accessibility", |
| 40 | "account", |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 41 | "activity", |
Parth Sane | ac49270 | 2024-09-18 15:54:16 +0000 | [diff] [blame] | 42 | "alarm", |
| 43 | "android.system.keystore2.IKeystoreService/default", |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 44 | "appops", |
| 45 | "audio", |
| 46 | "batterystats", |
| 47 | "carrier_config", |
| 48 | "connectivity", |
Parth Sane | ac49270 | 2024-09-18 15:54:16 +0000 | [diff] [blame] | 49 | "content", |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 50 | "content_capture", |
| 51 | "device_policy", |
| 52 | "display", |
| 53 | "dropbox", |
| 54 | "econtroller", |
Parth Sane | ac49270 | 2024-09-18 15:54:16 +0000 | [diff] [blame] | 55 | "graphicsstats", |
| 56 | "input", |
| 57 | "input_method", |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 58 | "isub", |
Parth Sane | ac49270 | 2024-09-18 15:54:16 +0000 | [diff] [blame] | 59 | "jobscheduler", |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 60 | "legacy_permission", |
| 61 | "location", |
| 62 | "media.extractor", |
| 63 | "media.metrics", |
| 64 | "media.player", |
| 65 | "media.resource_manager", |
Parth Sane | ac49270 | 2024-09-18 15:54:16 +0000 | [diff] [blame] | 66 | "media_resource_monitor", |
| 67 | "mount", |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 68 | "netd_listener", |
| 69 | "netstats", |
| 70 | "network_management", |
| 71 | "nfc", |
Parth Sane | ac49270 | 2024-09-18 15:54:16 +0000 | [diff] [blame] | 72 | "notification", |
| 73 | "package", |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 74 | "package_native", |
| 75 | "performance_hint", |
| 76 | "permission", |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 77 | "permission_checker", |
Parth Sane | ac49270 | 2024-09-18 15:54:16 +0000 | [diff] [blame] | 78 | "permissionmgr", |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 79 | "phone", |
| 80 | "platform_compat", |
| 81 | "power", |
| 82 | "role", |
| 83 | "sensorservice", |
| 84 | "statscompanion", |
| 85 | "telephony.registry", |
| 86 | "thermalservice", |
| 87 | "time_detector", |
| 88 | "trust", |
| 89 | "uimode", |
Parth Sane | ac49270 | 2024-09-18 15:54:16 +0000 | [diff] [blame] | 90 | "user", |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 91 | "virtualdevice", |
| 92 | "virtualdevice_native", |
| 93 | "webviewupdate", |
Parth Sane | ac49270 | 2024-09-18 15:54:16 +0000 | [diff] [blame] | 94 | "window", |
| 95 | // go/keep-sorted end |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | bool BinderCacheWithInvalidation::isClientSideCachingEnabled(const std::string& serviceName) { |
| 99 | if (ProcessState::self()->getThreadPoolMaxTotalThreadCount() <= 0) { |
| 100 | ALOGW("Thread Pool max thread count is 0. Cannot cache binder as linkToDeath cannot be " |
| 101 | "implemented. serviceName: %s", |
| 102 | serviceName.c_str()); |
| 103 | return false; |
| 104 | } |
| 105 | for (const char* name : kStaticCachableList) { |
| 106 | if (name == serviceName) { |
| 107 | return true; |
| 108 | } |
| 109 | } |
| 110 | return false; |
| 111 | } |
| 112 | |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 113 | Status BackendUnifiedServiceManager::updateCache(const std::string& serviceName, |
| 114 | const os::Service& service) { |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 115 | if (!kUseCache) { |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 116 | return Status::ok(); |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 117 | } |
| 118 | if (service.getTag() == os::Service::Tag::binder) { |
| 119 | sp<IBinder> binder = service.get<os::Service::Tag::binder>(); |
| 120 | if (binder && mCacheForGetService->isClientSideCachingEnabled(serviceName) && |
| 121 | binder->isBinderAlive()) { |
| 122 | return mCacheForGetService->setItem(serviceName, binder); |
| 123 | } |
| 124 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 125 | return Status::ok(); |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | bool BackendUnifiedServiceManager::returnIfCached(const std::string& serviceName, |
| 129 | os::Service* _out) { |
| 130 | if (!kUseCache) { |
| 131 | return false; |
| 132 | } |
| 133 | sp<IBinder> item = mCacheForGetService->getItem(serviceName); |
| 134 | // TODO(b/363177618): Enable caching for binders which are always null. |
| 135 | if (item != nullptr && item->isBinderAlive()) { |
| 136 | *_out = os::Service::make<os::Service::Tag::binder>(item); |
| 137 | return true; |
| 138 | } |
| 139 | return false; |
| 140 | } |
| 141 | |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 142 | BackendUnifiedServiceManager::BackendUnifiedServiceManager(const sp<AidlServiceManager>& impl) |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 143 | : mTheRealServiceManager(impl) { |
| 144 | mCacheForGetService = std::make_shared<BinderCacheWithInvalidation>(); |
| 145 | } |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 146 | |
| 147 | sp<AidlServiceManager> BackendUnifiedServiceManager::getImpl() { |
| 148 | return mTheRealServiceManager; |
| 149 | } |
Alice Wang | 11da150 | 2024-07-25 12:03:22 +0000 | [diff] [blame] | 150 | |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 151 | Status BackendUnifiedServiceManager::getService(const ::std::string& name, |
| 152 | sp<IBinder>* _aidl_return) { |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 153 | os::Service service; |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 154 | Status status = getService2(name, &service); |
Alice Wang | 11da150 | 2024-07-25 12:03:22 +0000 | [diff] [blame] | 155 | *_aidl_return = service.get<os::Service::Tag::binder>(); |
| 156 | return status; |
| 157 | } |
| 158 | |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 159 | Status BackendUnifiedServiceManager::getService2(const ::std::string& name, os::Service* _out) { |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 160 | if (returnIfCached(name, _out)) { |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 161 | return Status::ok(); |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 162 | } |
Alice Wang | 11da150 | 2024-07-25 12:03:22 +0000 | [diff] [blame] | 163 | os::Service service; |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 164 | Status status = mTheRealServiceManager->getService2(name, &service); |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 165 | |
Devin Moore | 18f6375 | 2024-08-08 21:01:24 +0000 | [diff] [blame] | 166 | if (status.isOk()) { |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 167 | status = toBinderService(name, service, _out); |
| 168 | if (status.isOk()) { |
| 169 | return updateCache(name, service); |
| 170 | } |
Devin Moore | 18f6375 | 2024-08-08 21:01:24 +0000 | [diff] [blame] | 171 | } |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 172 | return status; |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 173 | } |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 174 | |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 175 | Status BackendUnifiedServiceManager::checkService(const ::std::string& name, os::Service* _out) { |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 176 | os::Service service; |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 177 | if (returnIfCached(name, _out)) { |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 178 | return Status::ok(); |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 181 | Status status = mTheRealServiceManager->checkService(name, &service); |
Devin Moore | 18f6375 | 2024-08-08 21:01:24 +0000 | [diff] [blame] | 182 | if (status.isOk()) { |
Parth Sane | b6ed0eb | 2024-06-25 14:38:42 +0000 | [diff] [blame] | 183 | status = toBinderService(name, service, _out); |
| 184 | if (status.isOk()) { |
| 185 | return updateCache(name, service); |
| 186 | } |
Devin Moore | 18f6375 | 2024-08-08 21:01:24 +0000 | [diff] [blame] | 187 | } |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 188 | return status; |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 189 | } |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 190 | |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 191 | Status BackendUnifiedServiceManager::toBinderService(const ::std::string& name, |
| 192 | const os::Service& in, os::Service* _out) { |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 193 | switch (in.getTag()) { |
| 194 | case os::Service::Tag::binder: { |
Devin Moore | 18f6375 | 2024-08-08 21:01:24 +0000 | [diff] [blame] | 195 | if (in.get<os::Service::Tag::binder>() == nullptr) { |
| 196 | // failed to find a service. Check to see if we have any local |
| 197 | // injected Accessors for this service. |
| 198 | os::Service accessor; |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 199 | Status status = getInjectedAccessor(name, &accessor); |
Devin Moore | 18f6375 | 2024-08-08 21:01:24 +0000 | [diff] [blame] | 200 | if (!status.isOk()) { |
| 201 | *_out = os::Service::make<os::Service::Tag::binder>(nullptr); |
| 202 | return status; |
| 203 | } |
| 204 | if (accessor.getTag() == os::Service::Tag::accessor && |
| 205 | accessor.get<os::Service::Tag::accessor>() != nullptr) { |
| 206 | ALOGI("Found local injected service for %s, will attempt to create connection", |
| 207 | name.c_str()); |
| 208 | // Call this again using the accessor Service to get the real |
| 209 | // service's binder into _out |
| 210 | return toBinderService(name, accessor, _out); |
| 211 | } |
| 212 | } |
| 213 | |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 214 | *_out = in; |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 215 | return Status::ok(); |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 216 | } |
| 217 | case os::Service::Tag::accessor: { |
| 218 | sp<IBinder> accessorBinder = in.get<os::Service::Tag::accessor>(); |
| 219 | sp<IAccessor> accessor = interface_cast<IAccessor>(accessorBinder); |
| 220 | if (accessor == nullptr) { |
| 221 | ALOGE("Service#accessor doesn't have accessor. VM is maybe starting..."); |
| 222 | *_out = os::Service::make<os::Service::Tag::binder>(nullptr); |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 223 | return Status::ok(); |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 224 | } |
| 225 | auto request = [=] { |
| 226 | os::ParcelFileDescriptor fd; |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 227 | Status ret = accessor->addConnection(&fd); |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 228 | if (ret.isOk()) { |
| 229 | return base::unique_fd(fd.release()); |
| 230 | } else { |
| 231 | ALOGE("Failed to connect to RpcSession: %s", ret.toString8().c_str()); |
| 232 | return base::unique_fd(-1); |
| 233 | } |
| 234 | }; |
| 235 | auto session = RpcSession::make(); |
Devin Moore | 18f6375 | 2024-08-08 21:01:24 +0000 | [diff] [blame] | 236 | status_t status = session->setupPreconnectedClient(base::unique_fd{}, request); |
| 237 | if (status != OK) { |
| 238 | ALOGE("Failed to set up preconnected binder RPC client: %s", |
| 239 | statusToString(status).c_str()); |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 240 | return Status::fromStatusT(status); |
Devin Moore | 18f6375 | 2024-08-08 21:01:24 +0000 | [diff] [blame] | 241 | } |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 242 | session->setSessionSpecificRoot(accessorBinder); |
| 243 | *_out = os::Service::make<os::Service::Tag::binder>(session->getRootObject()); |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 244 | return Status::ok(); |
Alice Wang | 8578f13 | 2024-05-03 09:01:56 +0000 | [diff] [blame] | 245 | } |
| 246 | default: { |
| 247 | LOG_ALWAYS_FATAL("Unknown service type: %d", in.getTag()); |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 252 | Status BackendUnifiedServiceManager::addService(const ::std::string& name, |
| 253 | const sp<IBinder>& service, bool allowIsolated, |
| 254 | int32_t dumpPriority) { |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 255 | return mTheRealServiceManager->addService(name, service, allowIsolated, dumpPriority); |
| 256 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 257 | Status BackendUnifiedServiceManager::listServices(int32_t dumpPriority, |
| 258 | ::std::vector<::std::string>* _aidl_return) { |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 259 | return mTheRealServiceManager->listServices(dumpPriority, _aidl_return); |
| 260 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 261 | Status BackendUnifiedServiceManager::registerForNotifications( |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 262 | const ::std::string& name, const sp<os::IServiceCallback>& callback) { |
| 263 | return mTheRealServiceManager->registerForNotifications(name, callback); |
| 264 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 265 | Status BackendUnifiedServiceManager::unregisterForNotifications( |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 266 | const ::std::string& name, const sp<os::IServiceCallback>& callback) { |
| 267 | return mTheRealServiceManager->unregisterForNotifications(name, callback); |
| 268 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 269 | Status BackendUnifiedServiceManager::isDeclared(const ::std::string& name, bool* _aidl_return) { |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 270 | return mTheRealServiceManager->isDeclared(name, _aidl_return); |
| 271 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 272 | Status BackendUnifiedServiceManager::getDeclaredInstances( |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 273 | const ::std::string& iface, ::std::vector<::std::string>* _aidl_return) { |
| 274 | return mTheRealServiceManager->getDeclaredInstances(iface, _aidl_return); |
| 275 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 276 | Status BackendUnifiedServiceManager::updatableViaApex( |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 277 | const ::std::string& name, ::std::optional<::std::string>* _aidl_return) { |
| 278 | return mTheRealServiceManager->updatableViaApex(name, _aidl_return); |
| 279 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 280 | Status BackendUnifiedServiceManager::getUpdatableNames(const ::std::string& apexName, |
| 281 | ::std::vector<::std::string>* _aidl_return) { |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 282 | return mTheRealServiceManager->getUpdatableNames(apexName, _aidl_return); |
| 283 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 284 | Status BackendUnifiedServiceManager::getConnectionInfo( |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 285 | const ::std::string& name, ::std::optional<os::ConnectionInfo>* _aidl_return) { |
| 286 | return mTheRealServiceManager->getConnectionInfo(name, _aidl_return); |
| 287 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 288 | Status BackendUnifiedServiceManager::registerClientCallback( |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 289 | const ::std::string& name, const sp<IBinder>& service, |
| 290 | const sp<os::IClientCallback>& callback) { |
| 291 | return mTheRealServiceManager->registerClientCallback(name, service, callback); |
| 292 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 293 | Status BackendUnifiedServiceManager::tryUnregisterService(const ::std::string& name, |
| 294 | const sp<IBinder>& service) { |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 295 | return mTheRealServiceManager->tryUnregisterService(name, service); |
| 296 | } |
Devin Moore | 678984f | 2024-10-18 22:43:22 +0000 | [diff] [blame^] | 297 | Status BackendUnifiedServiceManager::getServiceDebugInfo( |
Parth Sane | 56a0471 | 2024-04-22 14:21:07 +0000 | [diff] [blame] | 298 | ::std::vector<os::ServiceDebugInfo>* _aidl_return) { |
| 299 | return mTheRealServiceManager->getServiceDebugInfo(_aidl_return); |
| 300 | } |
| 301 | |
| 302 | [[clang::no_destroy]] static std::once_flag gUSmOnce; |
| 303 | [[clang::no_destroy]] static sp<BackendUnifiedServiceManager> gUnifiedServiceManager; |
| 304 | |
| 305 | sp<BackendUnifiedServiceManager> getBackendUnifiedServiceManager() { |
| 306 | std::call_once(gUSmOnce, []() { |
| 307 | #if defined(__BIONIC__) && !defined(__ANDROID_VNDK__) |
| 308 | /* wait for service manager */ { |
| 309 | using std::literals::chrono_literals::operator""s; |
| 310 | using android::base::WaitForProperty; |
| 311 | while (!WaitForProperty("servicemanager.ready", "true", 1s)) { |
| 312 | ALOGE("Waited for servicemanager.ready for a second, waiting another..."); |
| 313 | } |
| 314 | } |
| 315 | #endif |
| 316 | |
| 317 | sp<AidlServiceManager> sm = nullptr; |
| 318 | while (sm == nullptr) { |
| 319 | sm = interface_cast<AidlServiceManager>( |
| 320 | ProcessState::self()->getContextObject(nullptr)); |
| 321 | if (sm == nullptr) { |
| 322 | ALOGE("Waiting 1s on context object on %s.", |
| 323 | ProcessState::self()->getDriverName().c_str()); |
| 324 | sleep(1); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | gUnifiedServiceManager = sp<BackendUnifiedServiceManager>::make(sm); |
| 329 | }); |
| 330 | |
| 331 | return gUnifiedServiceManager; |
| 332 | } |
| 333 | |
Devin Moore | 18f6375 | 2024-08-08 21:01:24 +0000 | [diff] [blame] | 334 | } // namespace android |