• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #define LOG_TAG "hwservicemanager"
18 //#define LOG_NDEBUG 0
19 
20 #include "Vintf.h"
21 
22 #include <android-base/logging.h>
23 #include <vintf/parse_string.h>
24 #include <vintf/VintfObject.h>
25 
26 namespace android {
27 namespace hardware {
28 
getTransportFromManifest(const FQName & fqName,const std::string & instanceName,const std::shared_ptr<const vintf::HalManifest> & vm)29 vintf::Transport getTransportFromManifest(
30         const FQName &fqName, const std::string &instanceName,
31         const std::shared_ptr<const vintf::HalManifest>& vm) {
32     if (vm == nullptr) {
33         return vintf::Transport::EMPTY;
34     }
35     return vm->getTransport(fqName.package(), fqName.getVersion(), fqName.name(), instanceName);
36 }
37 
getTransport(const std::string & interfaceName,const std::string & instanceName)38 vintf::Transport getTransport(const std::string &interfaceName, const std::string &instanceName) {
39     FQName fqName;
40 
41     if (!FQName::parse(interfaceName, &fqName)) {
42         LOG(ERROR) << __FUNCTION__ << ": " << interfaceName
43                    << " is not a valid fully-qualified name.";
44         return vintf::Transport::EMPTY;
45     }
46     if (!fqName.hasVersion()) {
47         LOG(ERROR) << __FUNCTION__ << ": " << fqName.string()
48                    << " does not specify a version.";
49         return vintf::Transport::EMPTY;
50     }
51     if (fqName.name().empty()) {
52         LOG(ERROR) << __FUNCTION__ << ": " << fqName.string()
53                    << " does not specify an interface name.";
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 
68     LOG(INFO) << __FUNCTION__ << ": Cannot find entry " << fqName.string() << "/" << instanceName
69               << " in either framework or device manifest.";
70     return vintf::Transport::EMPTY;
71 }
72 
getInstances(const std::string & interfaceName)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 
87     std::set<std::string> deviceSet =
88         deviceManifest->getInstances(fqName.package(), fqName.getVersion(), fqName.name());
89     std::set<std::string> frameworkSet =
90         frameworkManifest->getInstances(fqName.package(), fqName.getVersion(), fqName.name());
91 
92     ret.insert(deviceSet.begin(), deviceSet.end());
93     ret.insert(frameworkSet.begin(), frameworkSet.end());
94 
95     return ret;
96 }
97 
98 
99 }  // hardware
100 }  // android
101