blob: 164eb4247f9f28e7d19698441980f77e36f24116 [file] [log] [blame]
Steven Morelandfe66b732019-02-01 14:29:45 -08001/*
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 Morelandf58feb72017-04-06 09:16:42 -070017#define LOG_TAG "hwservicemanager"
Yifan Hong469045b2017-04-28 13:56:06 -070018//#define LOG_NDEBUG 0
Steven Morelandf58feb72017-04-06 09:16:42 -070019
20#include "Vintf.h"
21
22#include <android-base/logging.h>
Steven Morelandf58feb72017-04-06 09:16:42 -070023#include <vintf/parse_string.h>
24#include <vintf/VintfObject.h>
25
26namespace android {
27namespace hardware {
28
29vintf::Transport getTransportFromManifest(
30 const FQName &fqName, const std::string &instanceName,
Yifan Hong1fc8ff22017-08-30 10:07:17 -070031 const std::shared_ptr<const vintf::HalManifest>& vm) {
Steven Morelandf58feb72017-04-06 09:16:42 -070032 if (vm == nullptr) {
33 return vintf::Transport::EMPTY;
34 }
Yifan Hong3fbad902019-09-10 18:24:07 -070035 return vm->getHidlTransport(fqName.package(), fqName.getVersion(),
36 fqName.name(), instanceName);
Steven Morelandf58feb72017-04-06 09:16:42 -070037}
38
39vintf::Transport getTransport(const std::string &interfaceName, const std::string &instanceName) {
Steven Moreland0cd38f02018-03-06 15:09:22 -080040 FQName fqName;
41
42 if (!FQName::parse(interfaceName, &fqName)) {
Steven Moreland6c0ecbe2017-05-23 09:56:53 -070043 LOG(ERROR) << __FUNCTION__ << ": " << interfaceName
Steven Morelandaae4eab2018-10-29 13:00:31 -070044 << " is not a valid fully-qualified name.";
Steven Morelandf58feb72017-04-06 09:16:42 -070045 return vintf::Transport::EMPTY;
46 }
47 if (!fqName.hasVersion()) {
Steven Moreland6c0ecbe2017-05-23 09:56:53 -070048 LOG(ERROR) << __FUNCTION__ << ": " << fqName.string()
49 << " does not specify a version.";
Steven Morelandf58feb72017-04-06 09:16:42 -070050 return vintf::Transport::EMPTY;
51 }
52 if (fqName.name().empty()) {
Steven Moreland6c0ecbe2017-05-23 09:56:53 -070053 LOG(ERROR) << __FUNCTION__ << ": " << fqName.string()
54 << " does not specify an interface name.";
Steven Morelandf58feb72017-04-06 09:16:42 -070055 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 Moreland77344cc2019-02-14 14:49:48 -080069 LOG(INFO) << __FUNCTION__ << ": Cannot find entry " << fqName.string() << "/" << instanceName
70 << " in either framework or device manifest.";
Steven Morelandf58feb72017-04-06 09:16:42 -070071 return vintf::Transport::EMPTY;
72}
73
Steven Moreland11d34e22019-11-01 09:59:10 -070074static 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 Morelandaae4eab2018-10-29 13:00:31 -070089std::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 Moreland11d34e22019-11-01 09:59:10 -0700100 insertManifestInstances(
101 fqName, vintf::VintfObject::GetDeviceHalManifest(), "device", &ret);
102 insertManifestInstances(
103 fqName, vintf::VintfObject::GetFrameworkHalManifest(), "framework", &ret);
Steven Morelandaae4eab2018-10-29 13:00:31 -0700104
105 return ret;
106}
107
108
Steven Morelandf58feb72017-04-06 09:16:42 -0700109} // hardware
Yifan Hong469045b2017-04-28 13:56:06 -0700110} // android