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