blob: ae4ba456eb0c680f276053de7f1999c52c7d8a1c [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 }
Steven Morelandccfa2132018-10-29 14:53:08 -070035 return vm->getTransport(fqName.package(), fqName.getVersion(), fqName.name(), instanceName);
Steven Morelandf58feb72017-04-06 09:16:42 -070036}
37
38vintf::Transport getTransport(const std::string &interfaceName, const std::string &instanceName) {
Steven Moreland0cd38f02018-03-06 15:09:22 -080039 FQName fqName;
40
41 if (!FQName::parse(interfaceName, &fqName)) {
Steven Moreland6c0ecbe2017-05-23 09:56:53 -070042 LOG(ERROR) << __FUNCTION__ << ": " << interfaceName
Steven Morelandaae4eab2018-10-29 13:00:31 -070043 << " is not a valid fully-qualified name.";
Steven Morelandf58feb72017-04-06 09:16:42 -070044 return vintf::Transport::EMPTY;
45 }
46 if (!fqName.hasVersion()) {
Steven Moreland6c0ecbe2017-05-23 09:56:53 -070047 LOG(ERROR) << __FUNCTION__ << ": " << fqName.string()
48 << " does not specify a version.";
Steven Morelandf58feb72017-04-06 09:16:42 -070049 return vintf::Transport::EMPTY;
50 }
51 if (fqName.name().empty()) {
Steven Moreland6c0ecbe2017-05-23 09:56:53 -070052 LOG(ERROR) << __FUNCTION__ << ": " << fqName.string()
53 << " does not specify an interface name.";
Steven Morelandf58feb72017-04-06 09:16:42 -070054 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 Moreland77344cc2019-02-14 14:49:48 -080068 LOG(INFO) << __FUNCTION__ << ": Cannot find entry " << fqName.string() << "/" << instanceName
69 << " in either framework or device manifest.";
Steven Morelandf58feb72017-04-06 09:16:42 -070070 return vintf::Transport::EMPTY;
71}
72
Steven Morelandaae4eab2018-10-29 13:00:31 -070073std::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 Morelandaae4eab2018-10-29 13:00:31 -070087 std::set<std::string> deviceSet =
Steven Morelandccfa2132018-10-29 14:53:08 -070088 deviceManifest->getInstances(fqName.package(), fqName.getVersion(), fqName.name());
Steven Morelandaae4eab2018-10-29 13:00:31 -070089 std::set<std::string> frameworkSet =
Steven Morelandccfa2132018-10-29 14:53:08 -070090 frameworkManifest->getInstances(fqName.package(), fqName.getVersion(), fqName.name());
Steven Morelandaae4eab2018-10-29 13:00:31 -070091
92 ret.insert(deviceSet.begin(), deviceSet.end());
93 ret.insert(frameworkSet.begin(), frameworkSet.end());
94
95 return ret;
96}
97
98
Steven Morelandf58feb72017-04-06 09:16:42 -070099} // hardware
Yifan Hong469045b2017-04-28 13:56:06 -0700100} // android