Steven Moreland | fe66b73 | 2019-02-01 14:29:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 17 | #define LOG_TAG "hwservicemanager" |
Yifan Hong | 469045b | 2017-04-28 13:56:06 -0700 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 19 | |
| 20 | #include "Vintf.h" |
| 21 | |
| 22 | #include <android-base/logging.h> |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 23 | #include <vintf/parse_string.h> |
| 24 | #include <vintf/VintfObject.h> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | |
| 29 | vintf::Transport getTransportFromManifest( |
| 30 | const FQName &fqName, const std::string &instanceName, |
Yifan Hong | 1fc8ff2 | 2017-08-30 10:07:17 -0700 | [diff] [blame] | 31 | const std::shared_ptr<const vintf::HalManifest>& vm) { |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 32 | if (vm == nullptr) { |
| 33 | return vintf::Transport::EMPTY; |
| 34 | } |
Steven Moreland | ccfa213 | 2018-10-29 14:53:08 -0700 | [diff] [blame] | 35 | return vm->getTransport(fqName.package(), fqName.getVersion(), fqName.name(), instanceName); |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | vintf::Transport getTransport(const std::string &interfaceName, const std::string &instanceName) { |
Steven Moreland | 0cd38f0 | 2018-03-06 15:09:22 -0800 | [diff] [blame] | 39 | FQName fqName; |
| 40 | |
| 41 | if (!FQName::parse(interfaceName, &fqName)) { |
Steven Moreland | 6c0ecbe | 2017-05-23 09:56:53 -0700 | [diff] [blame] | 42 | LOG(ERROR) << __FUNCTION__ << ": " << interfaceName |
Steven Moreland | aae4eab | 2018-10-29 13:00:31 -0700 | [diff] [blame] | 43 | << " is not a valid fully-qualified name."; |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 44 | return vintf::Transport::EMPTY; |
| 45 | } |
| 46 | if (!fqName.hasVersion()) { |
Steven Moreland | 6c0ecbe | 2017-05-23 09:56:53 -0700 | [diff] [blame] | 47 | LOG(ERROR) << __FUNCTION__ << ": " << fqName.string() |
| 48 | << " does not specify a version."; |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 49 | return vintf::Transport::EMPTY; |
| 50 | } |
| 51 | if (fqName.name().empty()) { |
Steven Moreland | 6c0ecbe | 2017-05-23 09:56:53 -0700 | [diff] [blame] | 52 | LOG(ERROR) << __FUNCTION__ << ": " << fqName.string() |
| 53 | << " does not specify an interface name."; |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 54 | return vintf::Transport::EMPTY; |
| 55 | } |
| 56 | |
| 57 | vintf::Transport tr = getTransportFromManifest(fqName, instanceName, |
| 58 | vintf::VintfObject::GetFrameworkHalManifest()); |
| 59 | if (tr != vintf::Transport::EMPTY) { |
| 60 | return tr; |
| 61 | } |
| 62 | tr = getTransportFromManifest(fqName, instanceName, |
| 63 | vintf::VintfObject::GetDeviceHalManifest()); |
| 64 | if (tr != vintf::Transport::EMPTY) { |
| 65 | return tr; |
| 66 | } |
| 67 | |
Steven Moreland | 77344cc | 2019-02-14 14:49:48 -0800 | [diff] [blame] | 68 | LOG(INFO) << __FUNCTION__ << ": Cannot find entry " << fqName.string() << "/" << instanceName |
| 69 | << " in either framework or device manifest."; |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 70 | return vintf::Transport::EMPTY; |
| 71 | } |
| 72 | |
Steven Moreland | aae4eab | 2018-10-29 13:00:31 -0700 | [diff] [blame] | 73 | std::set<std::string> getInstances(const std::string& interfaceName) { |
| 74 | FQName fqName; |
| 75 | if (!FQName::parse(interfaceName, &fqName) || !fqName.isFullyQualified() || |
| 76 | fqName.isValidValueName() || !fqName.isInterfaceName()) { |
| 77 | LOG(ERROR) << __FUNCTION__ << ": " << interfaceName |
| 78 | << " is not a valid fully-qualified name."; |
| 79 | return {}; |
| 80 | } |
| 81 | |
| 82 | std::set<std::string> ret; |
| 83 | |
| 84 | auto deviceManifest = vintf::VintfObject::GetDeviceHalManifest(); |
| 85 | auto frameworkManifest = vintf::VintfObject::GetFrameworkHalManifest(); |
| 86 | |
Steven Moreland | aae4eab | 2018-10-29 13:00:31 -0700 | [diff] [blame] | 87 | std::set<std::string> deviceSet = |
Steven Moreland | ccfa213 | 2018-10-29 14:53:08 -0700 | [diff] [blame] | 88 | deviceManifest->getInstances(fqName.package(), fqName.getVersion(), fqName.name()); |
Steven Moreland | aae4eab | 2018-10-29 13:00:31 -0700 | [diff] [blame] | 89 | std::set<std::string> frameworkSet = |
Steven Moreland | ccfa213 | 2018-10-29 14:53:08 -0700 | [diff] [blame] | 90 | frameworkManifest->getInstances(fqName.package(), fqName.getVersion(), fqName.name()); |
Steven Moreland | aae4eab | 2018-10-29 13:00:31 -0700 | [diff] [blame] | 91 | |
| 92 | ret.insert(deviceSet.begin(), deviceSet.end()); |
| 93 | ret.insert(frameworkSet.begin(), frameworkSet.end()); |
| 94 | |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 99 | } // hardware |
Yifan Hong | 469045b | 2017-04-28 13:56:06 -0700 | [diff] [blame] | 100 | } // android |