Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 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 | |
| 17 | #include "update_engine/dlcservice_chromeos.h" |
| 18 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame^] | 19 | #include <brillo/errors/error.h> |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 20 | #include <dlcservice/proto_bindings/dlcservice.pb.h> |
Amin Hassani | 3bab177 | 2019-06-21 14:58:25 -0700 | [diff] [blame] | 21 | // NOLINTNEXTLINE(build/include_alpha) "dbus-proxies.h" needs "dlcservice.pb.h" |
| 22 | #include <dlcservice/dbus-proxies.h> |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 23 | |
| 24 | #include "update_engine/dbus_connection.h" |
| 25 | |
Amin Hassani | 3bab177 | 2019-06-21 14:58:25 -0700 | [diff] [blame] | 26 | using dlcservice::DlcModuleList; |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 27 | using std::string; |
| 28 | using std::vector; |
| 29 | |
| 30 | namespace chromeos_update_engine { |
| 31 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame^] | 32 | namespace { |
| 33 | org::chromium::DlcServiceInterfaceProxy GetDlcServiceProxy() { |
| 34 | return {DBusConnection::Get()->GetDBus()}; |
| 35 | } |
| 36 | } // namespace |
| 37 | |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 38 | std::unique_ptr<DlcServiceInterface> CreateDlcService() { |
| 39 | return std::make_unique<DlcServiceChromeOS>(); |
| 40 | } |
| 41 | |
| 42 | bool DlcServiceChromeOS::GetInstalled(vector<string>* dlc_module_ids) { |
| 43 | if (!dlc_module_ids) |
| 44 | return false; |
Jae Hoon Kim | c43f6bb | 2019-07-03 12:56:52 -0700 | [diff] [blame] | 45 | dlc_module_ids->clear(); |
| 46 | |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 47 | dlcservice::DlcModuleList dlc_module_list; |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame^] | 48 | if (!GetDlcServiceProxy().GetInstalled(&dlc_module_list, nullptr)) { |
Amin Hassani | 3bab177 | 2019-06-21 14:58:25 -0700 | [diff] [blame] | 49 | LOG(ERROR) << "dlcservice does not return installed DLC module list."; |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 50 | return false; |
| 51 | } |
| 52 | for (const auto& dlc_module_info : dlc_module_list.dlc_module_infos()) { |
| 53 | dlc_module_ids->emplace_back(dlc_module_info.dlc_id()); |
| 54 | } |
| 55 | return true; |
| 56 | } |
| 57 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame^] | 58 | bool DlcServiceChromeOS::InstallCompleted(const std::vector<std::string>& ids) { |
| 59 | brillo::ErrorPtr err; |
| 60 | if (!GetDlcServiceProxy().InstallCompleted(ids, &err)) { |
| 61 | LOG(ERROR) << "dlcservice failed to complete install. ErrCode=" |
| 62 | << err->GetCode() << ", ErrMsg=" << err->GetMessage(); |
| 63 | return false; |
| 64 | } |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | bool DlcServiceChromeOS::UpdateCompleted(const std::vector<std::string>& ids) { |
| 69 | brillo::ErrorPtr err; |
| 70 | if (!GetDlcServiceProxy().UpdateCompleted(ids, &err)) { |
| 71 | LOG(ERROR) << "dlcservice failed to complete updated. ErrCode=" |
| 72 | << err->GetCode() << ", ErrMsg=" << err->GetMessage(); |
| 73 | return false; |
| 74 | } |
| 75 | return true; |
| 76 | } |
| 77 | |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 78 | } // namespace chromeos_update_engine |