Vintf.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #define LOG_TAG "hwservicemanager"
  17. //#define LOG_NDEBUG 0
  18. #include "Vintf.h"
  19. #include <android-base/logging.h>
  20. #include <vintf/parse_string.h>
  21. #include <vintf/VintfObject.h>
  22. namespace android {
  23. namespace hardware {
  24. vintf::Transport getTransportFromManifest(
  25. const FQName &fqName, const std::string &instanceName,
  26. const std::shared_ptr<const vintf::HalManifest>& vm) {
  27. if (vm == nullptr) {
  28. return vintf::Transport::EMPTY;
  29. }
  30. return vm->getTransport(fqName.package(), fqName.getVersion(), fqName.name(), instanceName);
  31. }
  32. vintf::Transport getTransport(const std::string &interfaceName, const std::string &instanceName) {
  33. FQName fqName;
  34. if (!FQName::parse(interfaceName, &fqName)) {
  35. LOG(ERROR) << __FUNCTION__ << ": " << interfaceName
  36. << " is not a valid fully-qualified name.";
  37. return vintf::Transport::EMPTY;
  38. }
  39. if (!fqName.hasVersion()) {
  40. LOG(ERROR) << __FUNCTION__ << ": " << fqName.string()
  41. << " does not specify a version.";
  42. return vintf::Transport::EMPTY;
  43. }
  44. if (fqName.name().empty()) {
  45. LOG(ERROR) << __FUNCTION__ << ": " << fqName.string()
  46. << " does not specify an interface name.";
  47. return vintf::Transport::EMPTY;
  48. }
  49. vintf::Transport tr = getTransportFromManifest(fqName, instanceName,
  50. vintf::VintfObject::GetFrameworkHalManifest());
  51. if (tr != vintf::Transport::EMPTY) {
  52. return tr;
  53. }
  54. tr = getTransportFromManifest(fqName, instanceName,
  55. vintf::VintfObject::GetDeviceHalManifest());
  56. if (tr != vintf::Transport::EMPTY) {
  57. return tr;
  58. }
  59. LOG(INFO) << __FUNCTION__ << ": Cannot find entry " << fqName.string() << "/" << instanceName
  60. << " in either framework or device manifest.";
  61. return vintf::Transport::EMPTY;
  62. }
  63. std::set<std::string> getInstances(const std::string& interfaceName) {
  64. FQName fqName;
  65. if (!FQName::parse(interfaceName, &fqName) || !fqName.isFullyQualified() ||
  66. fqName.isValidValueName() || !fqName.isInterfaceName()) {
  67. LOG(ERROR) << __FUNCTION__ << ": " << interfaceName
  68. << " is not a valid fully-qualified name.";
  69. return {};
  70. }
  71. std::set<std::string> ret;
  72. auto deviceManifest = vintf::VintfObject::GetDeviceHalManifest();
  73. auto frameworkManifest = vintf::VintfObject::GetFrameworkHalManifest();
  74. std::set<std::string> deviceSet =
  75. deviceManifest->getInstances(fqName.package(), fqName.getVersion(), fqName.name());
  76. std::set<std::string> frameworkSet =
  77. frameworkManifest->getInstances(fqName.package(), fqName.getVersion(), fqName.name());
  78. ret.insert(deviceSet.begin(), deviceSet.end());
  79. ret.insert(frameworkSet.begin(), frameworkSet.end());
  80. return ret;
  81. }
  82. } // hardware
  83. } // android