blob: 9b4338b1f337eebce5f9ebe6b5fa0edfbbdec79c [file] [log] [blame]
Steven Moreland5d5ef7f2016-10-20 19:19:55 -07001/*
2 * Copyright (C) 2016 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#define LOG_TAG "ServiceManagement"
18
Jiyong Park3ab546c2017-04-06 20:28:07 +090019#include <android/dlext.h>
Yifan Hong9a22d1d2017-01-25 14:19:26 -080020#include <condition_variable>
21#include <dlfcn.h>
22#include <dirent.h>
Steven Moreland405d7612017-04-07 20:31:22 -070023#include <fstream>
24#include <pthread.h>
Yifan Hong9a22d1d2017-01-25 14:19:26 -080025#include <unistd.h>
26
27#include <mutex>
28#include <regex>
Yifan Hongbd0d8f72017-05-24 19:43:51 -070029#include <set>
Yifan Hong9a22d1d2017-01-25 14:19:26 -080030
Martijn Coenen12f04d92016-12-07 17:29:41 +010031#include <hidl/HidlBinderSupport.h>
Justin Yun1f048102017-12-01 15:30:08 +090032#include <hidl/HidlInternal.h>
Steven Morelande69e8d32018-03-14 10:55:42 -070033#include <hidl/HidlTransportUtils.h>
Steven Moreland5d5ef7f2016-10-20 19:19:55 -070034#include <hidl/ServiceManagement.h>
Steven Moreland5d5ef7f2016-10-20 19:19:55 -070035#include <hidl/Status.h>
Peter Kalauskas64ffced2018-09-05 16:41:08 -070036#include <utils/SystemClock.h>
Steven Moreland5d5ef7f2016-10-20 19:19:55 -070037
Peter Kalauskas64ffced2018-09-05 16:41:08 -070038#include <android-base/file.h>
Steven Moreland337e6b62017-01-18 17:25:13 -080039#include <android-base/logging.h>
Peter Kalauskas64ffced2018-09-05 16:41:08 -070040#include <android-base/parseint.h>
Steven Morelandc1cee2c2017-03-24 16:23:11 +000041#include <android-base/properties.h>
Justin Yun1f048102017-12-01 15:30:08 +090042#include <android-base/stringprintf.h>
Peter Kalauskas64ffced2018-09-05 16:41:08 -070043#include <android-base/strings.h>
Steven Moreland5d5ef7f2016-10-20 19:19:55 -070044#include <hwbinder/IPCThreadState.h>
45#include <hwbinder/Parcel.h>
Jerry Zhang86ae9992018-05-30 17:11:09 -070046#if !defined(__ANDROID_RECOVERY__)
Jiyong Parkba8ace12017-05-15 15:44:39 +090047#include <vndksupport/linker.h>
Jerry Zhang86ae9992018-05-30 17:11:09 -070048#endif
Steven Moreland5d5ef7f2016-10-20 19:19:55 -070049
Steven Moreland89909692018-05-30 14:11:19 -070050#include <android/hidl/manager/1.2/BnHwServiceManager.h>
51#include <android/hidl/manager/1.2/BpHwServiceManager.h>
52#include <android/hidl/manager/1.2/IServiceManager.h>
Steven Moreland5d5ef7f2016-10-20 19:19:55 -070053
Yifan Hong9a22d1d2017-01-25 14:19:26 -080054#define RE_COMPONENT "[a-zA-Z_][a-zA-Z_0-9]*"
55#define RE_PATH RE_COMPONENT "(?:[.]" RE_COMPONENT ")*"
56static const std::regex gLibraryFileNamePattern("(" RE_PATH "@[0-9]+[.][0-9]+)-impl(.*?).so");
57
Steven Morelandc1cee2c2017-03-24 16:23:11 +000058using android::base::WaitForProperty;
59
Steven Morelandbb9eb2a2018-10-11 12:10:01 -070060using ::android::hidl::base::V1_0::IBase;
Steven Moreland2a2678e2017-07-21 18:07:38 -070061using IServiceManager1_0 = android::hidl::manager::V1_0::IServiceManager;
62using IServiceManager1_1 = android::hidl::manager::V1_1::IServiceManager;
Steven Moreland89909692018-05-30 14:11:19 -070063using IServiceManager1_2 = android::hidl::manager::V1_2::IServiceManager;
Steven Morelandbb9eb2a2018-10-11 12:10:01 -070064using ::android::hidl::manager::V1_0::IServiceNotification;
Steven Moreland5d5ef7f2016-10-20 19:19:55 -070065
66namespace android {
67namespace hardware {
68
Steven Morelandc1cee2c2017-03-24 16:23:11 +000069static const char* kHwServicemanagerReadyProperty = "hwservicemanager.ready";
70
Yifan Hongdeacf142018-07-10 17:33:34 -070071#if defined(__ANDROID_RECOVERY__)
72static constexpr bool kIsRecovery = true;
73#else
74static constexpr bool kIsRecovery = false;
75#endif
76
Steven Morelandbb9eb2a2018-10-11 12:10:01 -070077static void waitForHwServiceManager() {
Steven Morelandc1cee2c2017-03-24 16:23:11 +000078 using std::literals::chrono_literals::operator""s;
79
80 while (!WaitForProperty(kHwServicemanagerReadyProperty, "true", 1s)) {
81 LOG(WARNING) << "Waited for hwservicemanager.ready for a second, waiting another...";
82 }
83}
84
Steven Moreland405d7612017-04-07 20:31:22 -070085bool endsWith(const std::string &in, const std::string &suffix) {
86 return in.size() >= suffix.size() &&
87 in.substr(in.size() - suffix.size()) == suffix;
88}
Steven Moreland5d5ef7f2016-10-20 19:19:55 -070089
Steven Moreland405d7612017-04-07 20:31:22 -070090bool startsWith(const std::string &in, const std::string &prefix) {
91 return in.size() >= prefix.size() &&
92 in.substr(0, prefix.size()) == prefix;
93}
94
Steven Morelandbb9eb2a2018-10-11 12:10:01 -070095static std::string binaryName() {
Steven Moreland405d7612017-04-07 20:31:22 -070096 std::ifstream ifs("/proc/self/cmdline");
97 std::string cmdline;
98 if (!ifs.is_open()) {
99 return "";
100 }
101 ifs >> cmdline;
102
Chih-Hung Hsieh41649d52017-08-03 14:27:21 -0700103 size_t idx = cmdline.rfind('/');
Steven Moreland405d7612017-04-07 20:31:22 -0700104 if (idx != std::string::npos) {
105 cmdline = cmdline.substr(idx + 1);
106 }
107
108 return cmdline;
109}
110
Steven Morelandbb9eb2a2018-10-11 12:10:01 -0700111static std::string packageWithoutVersion(const std::string& packageAndVersion) {
Steven Moreland7d09a402018-04-06 10:44:05 -0700112 size_t at = packageAndVersion.find('@');
113 if (at == std::string::npos) return packageAndVersion;
114 return packageAndVersion.substr(0, at);
115}
116
Steven Morelandbb9eb2a2018-10-11 12:10:01 -0700117static void tryShortenProcessName(const std::string& descriptor) {
Steven Moreland7d09a402018-04-06 10:44:05 -0700118 const static std::string kTasks = "/proc/self/task/";
119
120 // make sure that this binary name is in the same package
Steven Moreland405d7612017-04-07 20:31:22 -0700121 std::string processName = binaryName();
122
Steven Moreland7d09a402018-04-06 10:44:05 -0700123 // e.x. android.hardware.foo is this package
Steven Morelandbb9eb2a2018-10-11 12:10:01 -0700124 if (!startsWith(packageWithoutVersion(processName), packageWithoutVersion(descriptor))) {
Steven Moreland405d7612017-04-07 20:31:22 -0700125 return;
126 }
127
Steven Morelandbb9eb2a2018-10-11 12:10:01 -0700128 // e.x. android.hardware.module.foo@1.2::IFoo -> foo@1.2
129 size_t lastDot = descriptor.rfind('.');
Steven Moreland7d09a402018-04-06 10:44:05 -0700130 if (lastDot == std::string::npos) return;
Steven Morelandbb9eb2a2018-10-11 12:10:01 -0700131 size_t secondDot = descriptor.rfind('.', lastDot - 1);
Steven Moreland7d09a402018-04-06 10:44:05 -0700132 if (secondDot == std::string::npos) return;
Steven Moreland405d7612017-04-07 20:31:22 -0700133
Steven Moreland7d09a402018-04-06 10:44:05 -0700134 std::string newName = processName.substr(secondDot + 1, std::string::npos);
135 ALOGI("Removing namespace from process name %s to %s.", processName.c_str(), newName.c_str());
136
137 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(kTasks.c_str()), closedir);
138 if (dir == nullptr) return;
139
140 dirent* dp;
141 while ((dp = readdir(dir.get())) != nullptr) {
142 if (dp->d_type != DT_DIR) continue;
143 if (dp->d_name[0] == '.') continue;
144
145 std::fstream fs(kTasks + dp->d_name + "/comm");
146 if (!fs.is_open()) {
147 ALOGI("Could not rename process, failed read comm for %s.", dp->d_name);
148 continue;
149 }
150
151 std::string oldComm;
152 fs >> oldComm;
153
154 // don't rename if it already has an explicit name
Steven Morelandbb9eb2a2018-10-11 12:10:01 -0700155 if (startsWith(descriptor, oldComm)) {
Steven Moreland7d09a402018-04-06 10:44:05 -0700156 fs.seekg(0, fs.beg);
157 fs << newName;
158 }
Steven Moreland405d7612017-04-07 20:31:22 -0700159 }
Steven Moreland405d7612017-04-07 20:31:22 -0700160}
161
162namespace details {
163
Peter Kalauskas64ffced2018-09-05 16:41:08 -0700164/*
165 * Returns the age of the current process by reading /proc/self/stat and comparing starttime to the
166 * current time. This is useful for measuring how long it took a HAL to register itself.
167 */
Steven Morelandbb9eb2a2018-10-11 12:10:01 -0700168static long getProcessAgeMs() {
Peter Kalauskas64ffced2018-09-05 16:41:08 -0700169 constexpr const int PROCFS_STAT_STARTTIME_INDEX = 21;
170 std::string content;
171 android::base::ReadFileToString("/proc/self/stat", &content, false);
172 auto stats = android::base::Split(content, " ");
173 if (stats.size() <= PROCFS_STAT_STARTTIME_INDEX) {
174 LOG(INFO) << "Could not read starttime from /proc/self/stat";
175 return -1;
176 }
177 const std::string& startTimeString = stats[PROCFS_STAT_STARTTIME_INDEX];
178 static const int64_t ticksPerSecond = sysconf(_SC_CLK_TCK);
179 const int64_t uptime = android::uptimeMillis();
180
181 unsigned long long startTimeInClockTicks = 0;
182 if (android::base::ParseUint(startTimeString, &startTimeInClockTicks)) {
183 long startTimeMs = 1000ULL * startTimeInClockTicks / ticksPerSecond;
184 return uptime - startTimeMs;
185 }
186 return -1;
187}
188
Steven Morelandbb9eb2a2018-10-11 12:10:01 -0700189static void onRegistrationImpl(const std::string& descriptor, const std::string& instanceName) {
Peter Kalauskas64ffced2018-09-05 16:41:08 -0700190 long halStartDelay = getProcessAgeMs();
191 if (halStartDelay >= 0) {
192 // The "start delay" printed here is an estimate of how long it took the HAL to go from
193 // process creation to registering itself as a HAL. Actual start time could be longer
194 // because the process might not have joined the threadpool yet, so it might not be ready to
195 // process transactions.
Steven Morelandbb9eb2a2018-10-11 12:10:01 -0700196 LOG(INFO) << "Registered " << descriptor << "/" << instanceName << " (start delay of "
Peter Kalauskas64ffced2018-09-05 16:41:08 -0700197 << halStartDelay << "ms)";
198 }
Steven Morelandbb9eb2a2018-10-11 12:10:01 -0700199
200 tryShortenProcessName(descriptor);
201}
202
203void onRegistration(const std::string& packageName, const std::string& interfaceName,
204 const std::string& instanceName) {
205 return onRegistrationImpl(packageName + "::" + interfaceName, instanceName);
Steven Moreland405d7612017-04-07 20:31:22 -0700206}
207
208} // details
209
Steven Moreland2a2678e2017-07-21 18:07:38 -0700210sp<IServiceManager1_0> defaultServiceManager() {
Steven Moreland89909692018-05-30 14:11:19 -0700211 return defaultServiceManager1_2();
Steven Moreland2a2678e2017-07-21 18:07:38 -0700212}
213sp<IServiceManager1_1> defaultServiceManager1_1() {
Steven Moreland89909692018-05-30 14:11:19 -0700214 return defaultServiceManager1_2();
215}
216sp<IServiceManager1_2> defaultServiceManager1_2() {
217 using android::hidl::manager::V1_2::BnHwServiceManager;
218 using android::hidl::manager::V1_2::BpHwServiceManager;
219
220 static std::mutex gDefaultServiceManagerLock;
221 static sp<IServiceManager1_2> gDefaultServiceManager;
222
Steven Moreland5d5ef7f2016-10-20 19:19:55 -0700223 {
Steven Moreland89909692018-05-30 14:11:19 -0700224 std::lock_guard<std::mutex> _l(gDefaultServiceManagerLock);
225 if (gDefaultServiceManager != nullptr) {
226 return gDefaultServiceManager;
Yifan Hong8fb656b2017-03-16 14:30:40 -0700227 }
Steven Moreland405d7612017-04-07 20:31:22 -0700228
Yifan Hong8fb656b2017-03-16 14:30:40 -0700229 if (access("/dev/hwbinder", F_OK|R_OK|W_OK) != 0) {
230 // HwBinder not available on this device or not accessible to
231 // this process.
232 return nullptr;
233 }
Steven Morelandc1cee2c2017-03-24 16:23:11 +0000234
235 waitForHwServiceManager();
236
Steven Moreland89909692018-05-30 14:11:19 -0700237 while (gDefaultServiceManager == nullptr) {
238 gDefaultServiceManager =
239 fromBinder<IServiceManager1_2, BpHwServiceManager, BnHwServiceManager>(
240 ProcessState::self()->getContextObject(nullptr));
241 if (gDefaultServiceManager == nullptr) {
Steven Morelandc1cee2c2017-03-24 16:23:11 +0000242 LOG(ERROR) << "Waited for hwservicemanager, but got nullptr.";
Steven Moreland5d5ef7f2016-10-20 19:19:55 -0700243 sleep(1);
Yifan Hong8fb656b2017-03-16 14:30:40 -0700244 }
Steven Moreland5d5ef7f2016-10-20 19:19:55 -0700245 }
246 }
247
Steven Moreland89909692018-05-30 14:11:19 -0700248 return gDefaultServiceManager;
Steven Moreland5d5ef7f2016-10-20 19:19:55 -0700249}
250
Steven Moreland0091c092017-01-20 23:15:18 +0000251std::vector<std::string> search(const std::string &path,
252 const std::string &prefix,
253 const std::string &suffix) {
254 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(path.c_str()), closedir);
255 if (!dir) return {};
256
257 std::vector<std::string> results{};
258
259 dirent* dp;
260 while ((dp = readdir(dir.get())) != nullptr) {
261 std::string name = dp->d_name;
262
Steven Moreland819c05d2017-04-06 17:24:22 -0700263 if (startsWith(name, prefix) &&
264 endsWith(name, suffix)) {
Steven Moreland0091c092017-01-20 23:15:18 +0000265 results.push_back(name);
266 }
267 }
268
269 return results;
270}
271
Yifan Hongbd0d8f72017-05-24 19:43:51 -0700272bool matchPackageName(const std::string& lib, std::string* matchedName, std::string* implName) {
Yifan Hong9a22d1d2017-01-25 14:19:26 -0800273 std::smatch match;
274 if (std::regex_match(lib, match, gLibraryFileNamePattern)) {
275 *matchedName = match.str(1) + "::I*";
Yifan Hongbd0d8f72017-05-24 19:43:51 -0700276 *implName = match.str(2);
Yifan Hong9a22d1d2017-01-25 14:19:26 -0800277 return true;
278 }
279 return false;
280}
281
Yifan Hong7f49f592017-02-03 15:11:44 -0800282static void registerReference(const hidl_string &interfaceName, const hidl_string &instanceName) {
Yifan Hongdeacf142018-07-10 17:33:34 -0700283 if (kIsRecovery) {
284 // No hwservicemanager in recovery.
285 return;
286 }
287
Steven Moreland2a2678e2017-07-21 18:07:38 -0700288 sp<IServiceManager1_0> binderizedManager = defaultServiceManager();
Yifan Hong7f49f592017-02-03 15:11:44 -0800289 if (binderizedManager == nullptr) {
290 LOG(WARNING) << "Could not registerReference for "
291 << interfaceName << "/" << instanceName
292 << ": null binderized manager.";
293 return;
294 }
Martijn Coenenaf4aba52017-04-27 09:41:13 -0700295 auto ret = binderizedManager->registerPassthroughClient(interfaceName, instanceName);
Yifan Hong7f49f592017-02-03 15:11:44 -0800296 if (!ret.isOk()) {
297 LOG(WARNING) << "Could not registerReference for "
298 << interfaceName << "/" << instanceName
299 << ": " << ret.description();
Steven Moreland0aeaa782017-03-22 08:11:07 -0700300 return;
Yifan Hong7f49f592017-02-03 15:11:44 -0800301 }
Steven Morelande681aa52017-02-15 16:22:37 -0800302 LOG(VERBOSE) << "Successfully registerReference for "
303 << interfaceName << "/" << instanceName;
Yifan Hong7f49f592017-02-03 15:11:44 -0800304}
305
Yifan Hongbd0d8f72017-05-24 19:43:51 -0700306using InstanceDebugInfo = hidl::manager::V1_0::IServiceManager::InstanceDebugInfo;
307static inline void fetchPidsForPassthroughLibraries(
308 std::map<std::string, InstanceDebugInfo>* infos) {
309 static const std::string proc = "/proc/";
310
311 std::map<std::string, std::set<pid_t>> pids;
312 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(proc.c_str()), closedir);
313 if (!dir) return;
314 dirent* dp;
315 while ((dp = readdir(dir.get())) != nullptr) {
Stephen Hinesfd9ecee2017-09-27 18:52:52 -0700316 pid_t pid = strtoll(dp->d_name, nullptr, 0);
Yifan Hongbd0d8f72017-05-24 19:43:51 -0700317 if (pid == 0) continue;
318 std::string mapsPath = proc + dp->d_name + "/maps";
319 std::ifstream ifs{mapsPath};
320 if (!ifs.is_open()) continue;
321
322 for (std::string line; std::getline(ifs, line);) {
323 // The last token of line should look like
324 // vendor/lib64/hw/android.hardware.foo@1.0-impl-extra.so
325 // Use some simple filters to ignore bad lines before extracting libFileName
326 // and checking the key in info to make parsing faster.
327 if (line.back() != 'o') continue;
328 if (line.rfind('@') == std::string::npos) continue;
329
330 auto spacePos = line.rfind(' ');
331 if (spacePos == std::string::npos) continue;
332 auto libFileName = line.substr(spacePos + 1);
333 auto it = infos->find(libFileName);
334 if (it == infos->end()) continue;
335 pids[libFileName].insert(pid);
336 }
337 }
338 for (auto& pair : *infos) {
339 pair.second.clientPids =
340 std::vector<pid_t>{pids[pair.first].begin(), pids[pair.first].end()};
341 }
342}
343
Steven Moreland2a2678e2017-07-21 18:07:38 -0700344struct PassthroughServiceManager : IServiceManager1_1 {
Chih-Hung Hsieh41649d52017-08-03 14:27:21 -0700345 static void openLibs(
346 const std::string& fqName,
347 const std::function<bool /* continue */ (void* /* handle */, const std::string& /* lib */,
348 const std::string& /* sym */)>& eachLib) {
Steven Moreland819c05d2017-04-06 17:24:22 -0700349 //fqName looks like android.hardware.foo@1.0::IFoo
Steven Moreland519306f2017-06-06 17:14:12 -0700350 size_t idx = fqName.find("::");
Steven Moreland819c05d2017-04-06 17:24:22 -0700351
352 if (idx == std::string::npos ||
Steven Moreland519306f2017-06-06 17:14:12 -0700353 idx + strlen("::") + 1 >= fqName.size()) {
Steven Moreland337e6b62017-01-18 17:25:13 -0800354 LOG(ERROR) << "Invalid interface name passthrough lookup: " << fqName;
Steven Moreland519306f2017-06-06 17:14:12 -0700355 return;
Steven Moreland337e6b62017-01-18 17:25:13 -0800356 }
357
Steven Moreland519306f2017-06-06 17:14:12 -0700358 std::string packageAndVersion = fqName.substr(0, idx);
359 std::string ifaceName = fqName.substr(idx + strlen("::"));
Steven Moreland819c05d2017-04-06 17:24:22 -0700360
361 const std::string prefix = packageAndVersion + "-impl";
362 const std::string sym = "HIDL_FETCH_" + ifaceName;
Steven Moreland348802d2017-02-23 12:48:55 -0800363
Steven Moreland77f4c852017-10-12 11:05:53 -0700364 constexpr int dlMode = RTLD_LAZY;
365 void* handle = nullptr;
Steven Moreland337e6b62017-01-18 17:25:13 -0800366
Steven Morelanda29905c2017-03-01 10:42:35 -0800367 dlerror(); // clear
368
Justin Yun1f048102017-12-01 15:30:08 +0900369 static std::string halLibPathVndkSp = android::base::StringPrintf(
370 HAL_LIBRARY_PATH_VNDK_SP_FOR_VERSION, details::getVndkVersionStr().c_str());
Steven Morelandf7dea692017-07-14 12:49:28 -0700371 std::vector<std::string> paths = {HAL_LIBRARY_PATH_ODM, HAL_LIBRARY_PATH_VENDOR,
Justin Yun1f048102017-12-01 15:30:08 +0900372 halLibPathVndkSp, HAL_LIBRARY_PATH_SYSTEM};
Steven Moreland77f4c852017-10-12 11:05:53 -0700373
Steven Morelandf7dea692017-07-14 12:49:28 -0700374#ifdef LIBHIDL_TARGET_DEBUGGABLE
375 const char* env = std::getenv("TREBLE_TESTING_OVERRIDE");
376 const bool trebleTestingOverride = env && !strcmp(env, "true");
377 if (trebleTestingOverride) {
Steven Moreland77f4c852017-10-12 11:05:53 -0700378 // Load HAL implementations that are statically linked
379 handle = dlopen(nullptr, dlMode);
380 if (handle == nullptr) {
381 const char* error = dlerror();
382 LOG(ERROR) << "Failed to dlopen self: "
383 << (error == nullptr ? "unknown error" : error);
384 } else if (!eachLib(handle, "SELF", sym)) {
385 return;
386 }
387
Steven Morelandf7dea692017-07-14 12:49:28 -0700388 const char* vtsRootPath = std::getenv("VTS_ROOT_PATH");
389 if (vtsRootPath && strlen(vtsRootPath) > 0) {
390 const std::string halLibraryPathVtsOverride =
391 std::string(vtsRootPath) + HAL_LIBRARY_PATH_SYSTEM;
Steven Moreland77f4c852017-10-12 11:05:53 -0700392 paths.insert(paths.begin(), halLibraryPathVtsOverride);
Steven Morelandf7dea692017-07-14 12:49:28 -0700393 }
394 }
395#endif
Steven Moreland77f4c852017-10-12 11:05:53 -0700396
Steven Morelandf7dea692017-07-14 12:49:28 -0700397 for (const std::string& path : paths) {
Steven Moreland0091c092017-01-20 23:15:18 +0000398 std::vector<std::string> libs = search(path, prefix, ".so");
399
Steven Moreland0091c092017-01-20 23:15:18 +0000400 for (const std::string &lib : libs) {
Steven Moreland348802d2017-02-23 12:48:55 -0800401 const std::string fullPath = path + lib;
402
Yifan Hongdeacf142018-07-10 17:33:34 -0700403 if (kIsRecovery || path == HAL_LIBRARY_PATH_SYSTEM) {
Jiyong Park3ab546c2017-04-06 20:28:07 +0900404 handle = dlopen(fullPath.c_str(), dlMode);
Steven Moreland65c00cb2017-10-12 11:35:22 -0700405 } else {
Jerry Zhang86ae9992018-05-30 17:11:09 -0700406#if !defined(__ANDROID_RECOVERY__)
Steven Moreland65c00cb2017-10-12 11:35:22 -0700407 handle = android_load_sphal_library(fullPath.c_str(), dlMode);
Jerry Zhang86ae9992018-05-30 17:11:09 -0700408#endif
Jiyong Park3ab546c2017-04-06 20:28:07 +0900409 }
410
Steven Moreland348802d2017-02-23 12:48:55 -0800411 if (handle == nullptr) {
412 const char* error = dlerror();
413 LOG(ERROR) << "Failed to dlopen " << lib << ": "
414 << (error == nullptr ? "unknown error" : error);
415 continue;
Steven Moreland0091c092017-01-20 23:15:18 +0000416 }
Steven Moreland348802d2017-02-23 12:48:55 -0800417
Steven Moreland519306f2017-06-06 17:14:12 -0700418 if (!eachLib(handle, lib, sym)) {
419 return;
Steven Moreland348802d2017-02-23 12:48:55 -0800420 }
Steven Moreland337e6b62017-01-18 17:25:13 -0800421 }
422 }
Steven Moreland519306f2017-06-06 17:14:12 -0700423 }
Steven Moreland337e6b62017-01-18 17:25:13 -0800424
Steven Moreland519306f2017-06-06 17:14:12 -0700425 Return<sp<IBase>> get(const hidl_string& fqName,
426 const hidl_string& name) override {
427 sp<IBase> ret = nullptr;
428
429 openLibs(fqName, [&](void* handle, const std::string &lib, const std::string &sym) {
430 IBase* (*generator)(const char* name);
431 *(void **)(&generator) = dlsym(handle, sym.c_str());
432 if(!generator) {
433 const char* error = dlerror();
434 LOG(ERROR) << "Passthrough lookup opened " << lib
435 << " but could not find symbol " << sym << ": "
436 << (error == nullptr ? "unknown error" : error);
437 dlclose(handle);
438 return true;
439 }
440
441 ret = (*generator)(name.c_str());
442
443 if (ret == nullptr) {
444 dlclose(handle);
445 return true; // this module doesn't provide this instance name
446 }
447
Steven Morelande69e8d32018-03-14 10:55:42 -0700448 // Actual fqname might be a subclass.
449 // This assumption is tested in vts_treble_vintf_test
450 using ::android::hardware::details::getDescriptor;
451 std::string actualFqName = getDescriptor(ret.get());
452 CHECK(actualFqName.size() > 0);
453 registerReference(actualFqName, name);
Steven Moreland519306f2017-06-06 17:14:12 -0700454 return false;
455 });
456
457 return ret;
Steven Moreland337e6b62017-01-18 17:25:13 -0800458 }
459
Martijn Coenen67a02492017-03-06 13:04:48 +0100460 Return<bool> add(const hidl_string& /* name */,
Steven Moreland337e6b62017-01-18 17:25:13 -0800461 const sp<IBase>& /* service */) override {
462 LOG(FATAL) << "Cannot register services with passthrough service manager.";
463 return false;
464 }
465
Steven Morelandc601c5f2017-04-06 09:26:07 -0700466 Return<Transport> getTransport(const hidl_string& /* fqName */,
467 const hidl_string& /* name */) {
468 LOG(FATAL) << "Cannot getTransport with passthrough service manager.";
469 return Transport::EMPTY;
470 }
471
Yifan Hong705e5da2017-03-02 16:59:39 -0800472 Return<void> list(list_cb /* _hidl_cb */) override {
473 LOG(FATAL) << "Cannot list services with passthrough service manager.";
Steven Moreland337e6b62017-01-18 17:25:13 -0800474 return Void();
475 }
476 Return<void> listByInterface(const hidl_string& /* fqInstanceName */,
477 listByInterface_cb /* _hidl_cb */) override {
478 // TODO: add this functionality
479 LOG(FATAL) << "Cannot list services with passthrough service manager.";
480 return Void();
481 }
482
483 Return<bool> registerForNotifications(const hidl_string& /* fqName */,
484 const hidl_string& /* name */,
485 const sp<IServiceNotification>& /* callback */) override {
486 // This makes no sense.
487 LOG(FATAL) << "Cannot register for notifications with passthrough service manager.";
488 return false;
489 }
490
Yifan Hong705e5da2017-03-02 16:59:39 -0800491 Return<void> debugDump(debugDump_cb _hidl_cb) override {
492 using Arch = ::android::hidl::base::V1_0::DebugInfo::Architecture;
Yifan Hongbd0d8f72017-05-24 19:43:51 -0700493 using std::literals::string_literals::operator""s;
Justin Yun1f048102017-12-01 15:30:08 +0900494 static std::string halLibPathVndkSp64 = android::base::StringPrintf(
495 HAL_LIBRARY_PATH_VNDK_SP_64BIT_FOR_VERSION, details::getVndkVersionStr().c_str());
496 static std::string halLibPathVndkSp32 = android::base::StringPrintf(
497 HAL_LIBRARY_PATH_VNDK_SP_32BIT_FOR_VERSION, details::getVndkVersionStr().c_str());
Jiyong Park56eb1492017-08-04 16:16:13 +0900498 static std::vector<std::pair<Arch, std::vector<const char*>>> sAllPaths{
499 {Arch::IS_64BIT,
500 {HAL_LIBRARY_PATH_ODM_64BIT, HAL_LIBRARY_PATH_VENDOR_64BIT,
Justin Yun1f048102017-12-01 15:30:08 +0900501 halLibPathVndkSp64.c_str(), HAL_LIBRARY_PATH_SYSTEM_64BIT}},
Jiyong Park56eb1492017-08-04 16:16:13 +0900502 {Arch::IS_32BIT,
503 {HAL_LIBRARY_PATH_ODM_32BIT, HAL_LIBRARY_PATH_VENDOR_32BIT,
Justin Yun1f048102017-12-01 15:30:08 +0900504 halLibPathVndkSp32.c_str(), HAL_LIBRARY_PATH_SYSTEM_32BIT}}};
Yifan Hongbd0d8f72017-05-24 19:43:51 -0700505 std::map<std::string, InstanceDebugInfo> map;
Yifan Hong705e5da2017-03-02 16:59:39 -0800506 for (const auto &pair : sAllPaths) {
507 Arch arch = pair.first;
508 for (const auto &path : pair.second) {
509 std::vector<std::string> libs = search(path, "", ".so");
510 for (const std::string &lib : libs) {
511 std::string matchedName;
Yifan Hongbd0d8f72017-05-24 19:43:51 -0700512 std::string implName;
513 if (matchPackageName(lib, &matchedName, &implName)) {
514 std::string instanceName{"* ("s + path + ")"s};
515 if (!implName.empty()) instanceName += " ("s + implName + ")"s;
516 map.emplace(path + lib, InstanceDebugInfo{.interfaceName = matchedName,
517 .instanceName = instanceName,
518 .clientPids = {},
519 .arch = arch});
Yifan Hong705e5da2017-03-02 16:59:39 -0800520 }
521 }
522 }
523 }
Yifan Hongbd0d8f72017-05-24 19:43:51 -0700524 fetchPidsForPassthroughLibraries(&map);
525 hidl_vec<InstanceDebugInfo> vec;
526 vec.resize(map.size());
527 size_t idx = 0;
528 for (auto&& pair : map) {
529 vec[idx++] = std::move(pair.second);
530 }
Yifan Hong705e5da2017-03-02 16:59:39 -0800531 _hidl_cb(vec);
Yifan Hong7f49f592017-02-03 15:11:44 -0800532 return Void();
533 }
534
Martijn Coenenaf4aba52017-04-27 09:41:13 -0700535 Return<void> registerPassthroughClient(const hidl_string &, const hidl_string &) override {
Yifan Hong7f49f592017-02-03 15:11:44 -0800536 // This makes no sense.
537 LOG(FATAL) << "Cannot call registerPassthroughClient on passthrough service manager. "
538 << "Call it on defaultServiceManager() instead.";
Yifan Hong9a22d1d2017-01-25 14:19:26 -0800539 return Void();
540 }
541
Steven Moreland2a2678e2017-07-21 18:07:38 -0700542 Return<bool> unregisterForNotifications(const hidl_string& /* fqName */,
543 const hidl_string& /* name */,
544 const sp<IServiceNotification>& /* callback */) override {
545 // This makes no sense.
546 LOG(FATAL) << "Cannot unregister for notifications with passthrough service manager.";
547 return false;
548 }
549
Steven Moreland337e6b62017-01-18 17:25:13 -0800550};
551
Steven Moreland2a2678e2017-07-21 18:07:38 -0700552sp<IServiceManager1_0> getPassthroughServiceManager() {
553 return getPassthroughServiceManager1_1();
554}
555sp<IServiceManager1_1> getPassthroughServiceManager1_1() {
Steven Moreland337e6b62017-01-18 17:25:13 -0800556 static sp<PassthroughServiceManager> manager(new PassthroughServiceManager());
557 return manager;
558}
559
Steven Morelandcbefd352017-01-23 20:29:05 -0800560namespace details {
561
Steven Moreland519306f2017-06-06 17:14:12 -0700562void preloadPassthroughService(const std::string &descriptor) {
563 PassthroughServiceManager::openLibs(descriptor,
564 [&](void* /* handle */, const std::string& /* lib */, const std::string& /* sym */) {
565 // do nothing
566 return true; // open all libs
567 });
568}
569
Steven Morelandcbefd352017-01-23 20:29:05 -0800570struct Waiter : IServiceNotification {
Martijn Coenen773609e2017-10-24 09:57:53 +0200571 Waiter(const std::string& interface, const std::string& instanceName,
572 const sp<IServiceManager1_1>& sm) : mInterfaceName(interface),
573 mInstanceName(instanceName), mSm(sm) {
Martijn Coenene6cdfd32017-11-13 14:03:05 +0100574 }
575
576 void onFirstRef() override {
Martijn Coenenb88ae7f2017-10-24 11:45:41 +0200577 // If this process only has one binder thread, and we're calling wait() from
578 // that thread, it will block forever because we hung up the one and only
579 // binder thread on a condition variable that can only be notified by an
580 // incoming binder call.
Tobias Lindskog88e886f2018-01-05 10:32:43 +0100581 if (IPCThreadState::self()->isOnlyBinderThread()) {
Martijn Coenenb88ae7f2017-10-24 11:45:41 +0200582 LOG(WARNING) << "Can't efficiently wait for " << mInterfaceName << "/"
583 << mInstanceName << ", because we are called from "
584 << "the only binder thread in this process.";
585 return;
586 }
587
Martijn Coenene6cdfd32017-11-13 14:03:05 +0100588 Return<bool> ret = mSm->registerForNotifications(mInterfaceName, mInstanceName, this);
Martijn Coenen773609e2017-10-24 09:57:53 +0200589
590 if (!ret.isOk()) {
591 LOG(ERROR) << "Transport error, " << ret.description()
Martijn Coenene6cdfd32017-11-13 14:03:05 +0100592 << ", during notification registration for " << mInterfaceName << "/"
593 << mInstanceName << ".";
Martijn Coenen773609e2017-10-24 09:57:53 +0200594 return;
595 }
596
597 if (!ret) {
Martijn Coenene6cdfd32017-11-13 14:03:05 +0100598 LOG(ERROR) << "Could not register for notifications for " << mInterfaceName << "/"
599 << mInstanceName << ".";
Martijn Coenen773609e2017-10-24 09:57:53 +0200600 return;
601 }
602
603 mRegisteredForNotifications = true;
604 }
605
606 ~Waiter() {
Martijn Coenen3fa15c22018-02-10 11:30:00 +0100607 if (!mDoneCalled) {
608 LOG(FATAL)
609 << "Waiter still registered for notifications, call done() before dropping ref!";
Martijn Coenen773609e2017-10-24 09:57:53 +0200610 }
611 }
612
Steven Morelandcbefd352017-01-23 20:29:05 -0800613 Return<void> onRegistration(const hidl_string& /* fqName */,
614 const hidl_string& /* name */,
615 bool /* preexisting */) override {
616 std::unique_lock<std::mutex> lock(mMutex);
617 if (mRegistered) {
618 return Void();
619 }
620 mRegistered = true;
621 lock.unlock();
622
623 mCondition.notify_one();
624 return Void();
625 }
626
Steven Moreland0771d8a2018-05-09 13:29:14 -0700627 void wait(bool timeout) {
Steven Moreland49605102017-03-28 09:33:06 -0700628 using std::literals::chrono_literals::operator""s;
629
Martijn Coenen773609e2017-10-24 09:57:53 +0200630 if (!mRegisteredForNotifications) {
631 // As an alternative, just sleep for a second and return
632 LOG(WARNING) << "Waiting one second for " << mInterfaceName << "/" << mInstanceName;
633 sleep(1);
634 return;
635 }
636
Steven Morelandcbefd352017-01-23 20:29:05 -0800637 std::unique_lock<std::mutex> lock(mMutex);
Steven Moreland0771d8a2018-05-09 13:29:14 -0700638 do {
Steven Moreland49605102017-03-28 09:33:06 -0700639 mCondition.wait_for(lock, 1s, [this]{
640 return mRegistered;
641 });
642
643 if (mRegistered) {
644 break;
645 }
646
Steven Moreland0771d8a2018-05-09 13:29:14 -0700647 LOG(WARNING) << "Waited one second for " << mInterfaceName << "/" << mInstanceName;
648 } while (!timeout);
Steven Morelandcbefd352017-01-23 20:29:05 -0800649 }
650
Martijn Coenen773609e2017-10-24 09:57:53 +0200651 // Be careful when using this; after calling reset(), you must always try to retrieve
652 // the corresponding service before blocking on the waiter; otherwise, you might run
653 // into a race-condition where the service has just (re-)registered, you clear the state
654 // here, and subsequently calling waiter->wait() will block forever.
655 void reset() {
656 std::unique_lock<std::mutex> lock(mMutex);
657 mRegistered = false;
658 }
Martijn Coenen3fa15c22018-02-10 11:30:00 +0100659
660 // done() must be called before dropping the last strong ref to the Waiter, to make
661 // sure we can properly unregister with hwservicemanager.
662 void done() {
663 if (mRegisteredForNotifications) {
664 if (!mSm->unregisterForNotifications(mInterfaceName, mInstanceName, this)
665 .withDefault(false)) {
666 LOG(ERROR) << "Could not unregister service notification for " << mInterfaceName
667 << "/" << mInstanceName << ".";
668 } else {
669 mRegisteredForNotifications = false;
670 }
671 }
672 mDoneCalled = true;
673 }
674
675 private:
Martijn Coenen773609e2017-10-24 09:57:53 +0200676 const std::string mInterfaceName;
677 const std::string mInstanceName;
Steven Morelandad1f9922018-10-02 19:37:05 -0700678 sp<IServiceManager1_1> mSm;
Steven Morelandcbefd352017-01-23 20:29:05 -0800679 std::mutex mMutex;
680 std::condition_variable mCondition;
681 bool mRegistered = false;
Martijn Coenen773609e2017-10-24 09:57:53 +0200682 bool mRegisteredForNotifications = false;
Martijn Coenen3fa15c22018-02-10 11:30:00 +0100683 bool mDoneCalled = false;
Steven Morelandcbefd352017-01-23 20:29:05 -0800684};
685
686void waitForHwService(
687 const std::string &interface, const std::string &instanceName) {
Martijn Coenen773609e2017-10-24 09:57:53 +0200688 sp<Waiter> waiter = new Waiter(interface, instanceName, defaultServiceManager1_1());
Steven Moreland0771d8a2018-05-09 13:29:14 -0700689 waiter->wait(false /* timeout */);
Martijn Coenen3fa15c22018-02-10 11:30:00 +0100690 waiter->done();
Martijn Coenen773609e2017-10-24 09:57:53 +0200691}
Steven Morelandcbefd352017-01-23 20:29:05 -0800692
Martijn Coenen773609e2017-10-24 09:57:53 +0200693// Prints relevant error/warning messages for error return values from
694// details::canCastInterface(), both transaction errors (!castReturn.isOk())
695// as well as actual cast failures (castReturn.isOk() && castReturn = false).
696// Returns 'true' if the error is non-fatal and it's useful to retry
697bool handleCastError(const Return<bool>& castReturn, const std::string& descriptor,
698 const std::string& instance) {
699 if (castReturn.isOk()) {
700 if (castReturn) {
701 details::logAlwaysFatal("Successful cast value passed into handleCastError.");
702 }
703 // This should never happen, and there's not really a point in retrying.
704 ALOGE("getService: received incompatible service (bug in hwservicemanager?) for "
705 "%s/%s.", descriptor.c_str(), instance.c_str());
706 return false;
Steven Morelandcbefd352017-01-23 20:29:05 -0800707 }
Martijn Coenen773609e2017-10-24 09:57:53 +0200708 if (castReturn.isDeadObject()) {
709 ALOGW("getService: found dead hwbinder service for %s/%s.", descriptor.c_str(),
710 instance.c_str());
711 return true;
Steven Morelandcbefd352017-01-23 20:29:05 -0800712 }
Martijn Coenen773609e2017-10-24 09:57:53 +0200713 // This can happen due to:
714 // 1) No SELinux permissions
715 // 2) Other transaction failure (no buffer space, kernel error)
716 // The first isn't recoverable, but the second is.
717 // Since we can't yet differentiate between the two, and clients depend
718 // on us not blocking in case 1), treat this as a fatal error for now.
719 ALOGW("getService: unable to call into hwbinder service for %s/%s.",
720 descriptor.c_str(), instance.c_str());
721 return false;
Steven Morelandcbefd352017-01-23 20:29:05 -0800722}
723
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200724sp<::android::hidl::base::V1_0::IBase> getRawServiceInternal(const std::string& descriptor,
725 const std::string& instance,
726 bool retry, bool getStub) {
727 using Transport = ::android::hidl::manager::V1_0::IServiceManager::Transport;
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200728 using ::android::hidl::manager::V1_0::IServiceManager;
Martijn Coenend35678f2018-03-07 09:51:01 +0100729 sp<Waiter> waiter;
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200730
Yifan Hongdeacf142018-07-10 17:33:34 -0700731 sp<IServiceManager1_1> sm;
732 Transport transport = Transport::EMPTY;
733 if (kIsRecovery) {
Yifan Hongdeacf142018-07-10 17:33:34 -0700734 transport = Transport::PASSTHROUGH;
Yifan Hongdeacf142018-07-10 17:33:34 -0700735 } else {
736 sm = defaultServiceManager1_1();
737 if (sm == nullptr) {
738 ALOGE("getService: defaultServiceManager() is null");
739 return nullptr;
740 }
741
742 Return<Transport> transportRet = sm->getTransport(descriptor, instance);
743
744 if (!transportRet.isOk()) {
745 ALOGE("getService: defaultServiceManager()->getTransport returns %s",
746 transportRet.description().c_str());
747 return nullptr;
748 }
749 transport = transportRet;
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200750 }
751
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200752 const bool vintfHwbinder = (transport == Transport::HWBINDER);
753 const bool vintfPassthru = (transport == Transport::PASSTHROUGH);
754
Steven Moreland757394b2017-12-13 14:09:24 -0800755#ifdef ENFORCE_VINTF_MANIFEST
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200756
757#ifdef LIBHIDL_TARGET_DEBUGGABLE
758 const char* env = std::getenv("TREBLE_TESTING_OVERRIDE");
759 const bool trebleTestingOverride = env && !strcmp(env, "true");
760 const bool vintfLegacy = (transport == Transport::EMPTY) && trebleTestingOverride;
Steven Moreland757394b2017-12-13 14:09:24 -0800761#else // ENFORCE_VINTF_MANIFEST but not LIBHIDL_TARGET_DEBUGGABLE
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200762 const bool trebleTestingOverride = false;
763 const bool vintfLegacy = false;
764#endif // LIBHIDL_TARGET_DEBUGGABLE
765
Steven Moreland757394b2017-12-13 14:09:24 -0800766#else // not ENFORCE_VINTF_MANIFEST
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200767 const char* env = std::getenv("TREBLE_TESTING_OVERRIDE");
768 const bool trebleTestingOverride = env && !strcmp(env, "true");
769 const bool vintfLegacy = (transport == Transport::EMPTY);
Steven Moreland757394b2017-12-13 14:09:24 -0800770#endif // ENFORCE_VINTF_MANIFEST
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200771
Steven Moreland76371242018-04-19 17:11:39 -0700772 for (int tries = 0; !getStub && (vintfHwbinder || vintfLegacy); tries++) {
773 if (waiter == nullptr && tries > 0) {
Martijn Coenend35678f2018-03-07 09:51:01 +0100774 waiter = new Waiter(descriptor, instance, sm);
775 }
Steven Moreland76371242018-04-19 17:11:39 -0700776 if (waiter != nullptr) {
777 waiter->reset(); // don't reorder this -- see comments on reset()
778 }
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200779 Return<sp<IBase>> ret = sm->get(descriptor, instance);
780 if (!ret.isOk()) {
781 ALOGE("getService: defaultServiceManager()->get returns %s for %s/%s.",
782 ret.description().c_str(), descriptor.c_str(), instance.c_str());
783 break;
784 }
785 sp<IBase> base = ret;
Martijn Coenen773609e2017-10-24 09:57:53 +0200786 if (base != nullptr) {
787 Return<bool> canCastRet =
788 details::canCastInterface(base.get(), descriptor.c_str(), true /* emitError */);
789
790 if (canCastRet.isOk() && canCastRet) {
Steven Moreland76371242018-04-19 17:11:39 -0700791 if (waiter != nullptr) {
792 waiter->done();
793 }
Martijn Coenen773609e2017-10-24 09:57:53 +0200794 return base; // still needs to be wrapped by Bp class.
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200795 }
Martijn Coenen773609e2017-10-24 09:57:53 +0200796
797 if (!handleCastError(canCastRet, descriptor, instance)) break;
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200798 }
799
Martijn Coenen773609e2017-10-24 09:57:53 +0200800 // In case of legacy or we were not asked to retry, don't.
801 if (vintfLegacy || !retry) break;
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200802
Steven Moreland76371242018-04-19 17:11:39 -0700803 if (waiter != nullptr) {
804 ALOGI("getService: Trying again for %s/%s...", descriptor.c_str(), instance.c_str());
Steven Moreland0771d8a2018-05-09 13:29:14 -0700805 waiter->wait(true /* timeout */);
Steven Moreland76371242018-04-19 17:11:39 -0700806 }
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200807 }
808
Martijn Coenend35678f2018-03-07 09:51:01 +0100809 if (waiter != nullptr) {
810 waiter->done();
811 }
Martijn Coenen3fa15c22018-02-10 11:30:00 +0100812
Martijn Coenen86c3abb2017-10-24 09:33:28 +0200813 if (getStub || vintfPassthru || vintfLegacy) {
814 const sp<IServiceManager> pm = getPassthroughServiceManager();
815 if (pm != nullptr) {
816 sp<IBase> base = pm->get(descriptor, instance).withDefault(nullptr);
817 if (!getStub || trebleTestingOverride) {
818 base = wrapPassthrough(base);
819 }
820 return base;
821 }
822 }
823
824 return nullptr;
825}
826
Steven Morelandbb9eb2a2018-10-11 12:10:01 -0700827status_t registerAsServiceInternal(const sp<IBase>& service, const std::string& name) {
828 if (service == nullptr) {
829 return UNEXPECTED_NULL;
830 }
831
832 sp<IServiceManager1_2> sm = defaultServiceManager1_2();
833 if (sm == nullptr) {
834 return INVALID_OPERATION;
835 }
836
837 bool registered = false;
838 Return<void> ret = service->interfaceChain([&](const auto& chain) {
839 registered = sm->addWithChain(name.c_str(), service, chain).withDefault(false);
840 });
841
842 if (!ret.isOk()) {
843 LOG(ERROR) << "Could not retrieve interface chain: " << ret.description();
844 }
845
846 if (registered) {
847 onRegistrationImpl(getDescriptor(service.get()), name);
848 }
849
850 return registered ? OK : UNKNOWN_ERROR;
851}
852
Bernhard Rosenkränzer0c28fd22018-06-04 16:01:47 +0200853} // namespace details
Steven Morelandcbefd352017-01-23 20:29:05 -0800854
Bernhard Rosenkränzer0c28fd22018-06-04 16:01:47 +0200855} // namespace hardware
856} // namespace android