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 | } |
Yifan Hong | 3fbad90 | 2019-09-10 18:24:07 -0700 | [diff] [blame] | 35 | return vm->getHidlTransport(fqName.package(), fqName.getVersion(), |
| 36 | fqName.name(), instanceName); |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | vintf::Transport getTransport(const std::string &interfaceName, const std::string &instanceName) { |
Steven Moreland | 0cd38f0 | 2018-03-06 15:09:22 -0800 | [diff] [blame] | 40 | FQName fqName; |
| 41 | |
| 42 | if (!FQName::parse(interfaceName, &fqName)) { |
Steven Moreland | 6c0ecbe | 2017-05-23 09:56:53 -0700 | [diff] [blame] | 43 | LOG(ERROR) << __FUNCTION__ << ": " << interfaceName |
Steven Moreland | aae4eab | 2018-10-29 13:00:31 -0700 | [diff] [blame] | 44 | << " is not a valid fully-qualified name."; |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 45 | return vintf::Transport::EMPTY; |
| 46 | } |
| 47 | if (!fqName.hasVersion()) { |
Steven Moreland | 6c0ecbe | 2017-05-23 09:56:53 -0700 | [diff] [blame] | 48 | LOG(ERROR) << __FUNCTION__ << ": " << fqName.string() |
| 49 | << " does not specify a version."; |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 50 | return vintf::Transport::EMPTY; |
| 51 | } |
| 52 | if (fqName.name().empty()) { |
Steven Moreland | 6c0ecbe | 2017-05-23 09:56:53 -0700 | [diff] [blame] | 53 | LOG(ERROR) << __FUNCTION__ << ": " << fqName.string() |
| 54 | << " does not specify an interface name."; |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 55 | return vintf::Transport::EMPTY; |
| 56 | } |
| 57 | |
| 58 | vintf::Transport tr = getTransportFromManifest(fqName, instanceName, |
| 59 | vintf::VintfObject::GetFrameworkHalManifest()); |
| 60 | if (tr != vintf::Transport::EMPTY) { |
| 61 | return tr; |
| 62 | } |
| 63 | tr = getTransportFromManifest(fqName, instanceName, |
| 64 | vintf::VintfObject::GetDeviceHalManifest()); |
| 65 | if (tr != vintf::Transport::EMPTY) { |
| 66 | return tr; |
| 67 | } |
| 68 | |
Steven Moreland | 77344cc | 2019-02-14 14:49:48 -0800 | [diff] [blame] | 69 | LOG(INFO) << __FUNCTION__ << ": Cannot find entry " << fqName.string() << "/" << instanceName |
Steven Moreland | 8a75336 | 2020-04-30 15:39:10 -0700 | [diff] [blame] | 70 | << " in either framework or device VINTF manifest."; |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 71 | return vintf::Transport::EMPTY; |
| 72 | } |
| 73 | |
Steven Moreland | 11d34e2 | 2019-11-01 09:59:10 -0700 | [diff] [blame] | 74 | static void insertManifestInstances(const FQName& fqName, |
| 75 | const std::shared_ptr<const vintf::HalManifest>& manifest, |
| 76 | const std::string& manifestType, |
| 77 | std::set<std::string>* toSet) { |
| 78 | if (manifest == nullptr) { |
| 79 | LOG(ERROR) << "Device is missing " << manifestType << " manifest."; |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | std::set<std::string> manifestSet = manifest->getHidlInstances( |
| 84 | fqName.package(), fqName.getVersion(), fqName.name()); |
| 85 | |
| 86 | toSet->insert(manifestSet.begin(), manifestSet.end()); |
| 87 | } |
| 88 | |
Steven Moreland | aae4eab | 2018-10-29 13:00:31 -0700 | [diff] [blame] | 89 | std::set<std::string> getInstances(const std::string& interfaceName) { |
| 90 | FQName fqName; |
| 91 | if (!FQName::parse(interfaceName, &fqName) || !fqName.isFullyQualified() || |
| 92 | fqName.isValidValueName() || !fqName.isInterfaceName()) { |
| 93 | LOG(ERROR) << __FUNCTION__ << ": " << interfaceName |
| 94 | << " is not a valid fully-qualified name."; |
| 95 | return {}; |
| 96 | } |
| 97 | |
| 98 | std::set<std::string> ret; |
| 99 | |
Steven Moreland | 11d34e2 | 2019-11-01 09:59:10 -0700 | [diff] [blame] | 100 | insertManifestInstances( |
| 101 | fqName, vintf::VintfObject::GetDeviceHalManifest(), "device", &ret); |
| 102 | insertManifestInstances( |
| 103 | fqName, vintf::VintfObject::GetFrameworkHalManifest(), "framework", &ret); |
Steven Moreland | aae4eab | 2018-10-29 13:00:31 -0700 | [diff] [blame] | 104 | |
| 105 | return ret; |
| 106 | } |
| 107 | |
| 108 | |
Steven Moreland | f58feb7 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 109 | } // hardware |
Yifan Hong | 469045b | 2017-04-28 13:56:06 -0700 | [diff] [blame] | 110 | } // android |