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