dlcservice_chromeos.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // Copyright (C) 2018 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. #include "update_engine/dlcservice_chromeos.h"
  17. #include <dlcservice/dbus-proxies.h>
  18. #include <dlcservice/proto_bindings/dlcservice.pb.h>
  19. #include "update_engine/dbus_connection.h"
  20. using std::string;
  21. using std::vector;
  22. namespace chromeos_update_engine {
  23. std::unique_ptr<DlcServiceInterface> CreateDlcService() {
  24. return std::make_unique<DlcServiceChromeOS>();
  25. }
  26. bool DlcServiceChromeOS::GetInstalled(vector<string>* dlc_module_ids) {
  27. if (!dlc_module_ids)
  28. return false;
  29. org::chromium::DlcServiceInterfaceProxy dlcservice_proxy(
  30. DBusConnection::Get()->GetDBus());
  31. string dlc_module_list_str;
  32. if (!dlcservice_proxy.GetInstalled(&dlc_module_list_str, nullptr)) {
  33. LOG(ERROR) << "dlcservice does not return installed DLC module list.";
  34. return false;
  35. }
  36. dlcservice::DlcModuleList dlc_module_list;
  37. if (!dlc_module_list.ParseFromString(dlc_module_list_str)) {
  38. LOG(ERROR) << "Errors parsing DlcModuleList protobuf.";
  39. return false;
  40. }
  41. for (const auto& dlc_module_info : dlc_module_list.dlc_module_infos()) {
  42. dlc_module_ids->emplace_back(dlc_module_info.dlc_id());
  43. }
  44. return true;
  45. }
  46. } // namespace chromeos_update_engine