• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #include "vintf.hpp"
18 
19 #include <vintf/HalManifest.h>
20 #include <vintf/VintfObject.h>
21 
22 // Converts a set<string> into a C-style array of C strings.
convert(const std::set<std::string> & names)23 static char** convert(const std::set<std::string>& names) {
24     char** ret = new char*[names.size()];
25     char** ptr = ret;
26     for (const auto& name : names) {
27         *(ptr++) = strdup(name.c_str());
28     }
29     return ret;
30 }
31 
getHalNames(size_t * len)32 char** getHalNames(size_t* len) {
33     auto manifest = android::vintf::VintfObject::GetDeviceHalManifest();
34     const auto names = manifest->getHalNames();
35     *len = names.size();
36     return convert(names);
37 }
38 
getHalNamesAndVersions(size_t * len)39 char** getHalNamesAndVersions(size_t* len) {
40     auto manifest = android::vintf::VintfObject::GetDeviceHalManifest();
41     const auto names = manifest->getHalNamesAndVersions();
42     *len = names.size();
43     return convert(names);
44 }
45 
getHidlInstances(size_t * len,const char * package,size_t major_version,size_t minor_version,const char * interfaceName)46 char** getHidlInstances(size_t* len, const char* package, size_t major_version,
47                         size_t minor_version, const char* interfaceName) {
48     android::vintf::Version version(major_version, minor_version);
49     auto manifest = android::vintf::VintfObject::GetDeviceHalManifest();
50     const auto names = manifest->getHidlInstances(package, version, interfaceName);
51     *len = names.size();
52     return convert(names);
53 }
54 
getAidlInstances(size_t * len,const char * package,size_t version,const char * interfaceName)55 char** getAidlInstances(size_t* len, const char* package, size_t version,
56                         const char* interfaceName) {
57     auto manifest = android::vintf::VintfObject::GetDeviceHalManifest();
58     const auto names = manifest->getAidlInstances(package, version, interfaceName);
59     *len = names.size();
60     return convert(names);
61 }
62 
freeNames(char ** names,size_t len)63 void freeNames(char** names, size_t len) {
64     for (int i = 0; i < len; i++) {
65         free(names[i]);
66     }
67     delete[] names;
68 }
69