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 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #include "update_engine/cros/dlcservice_chromeos.h" |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 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 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 24 | #include "update_engine/cros/dbus_connection.h" |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 25 | |
| 26 | using std::string; |
| 27 | using std::vector; |
| 28 | |
| 29 | namespace chromeos_update_engine { |
| 30 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 31 | namespace { |
| 32 | org::chromium::DlcServiceInterfaceProxy GetDlcServiceProxy() { |
| 33 | return {DBusConnection::Get()->GetDBus()}; |
| 34 | } |
| 35 | } // namespace |
| 36 | |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 37 | std::unique_ptr<DlcServiceInterface> CreateDlcService() { |
| 38 | return std::make_unique<DlcServiceChromeOS>(); |
| 39 | } |
| 40 | |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 41 | bool DlcServiceChromeOS::GetDlcsToUpdate(vector<string>* dlc_ids) { |
| 42 | if (!dlc_ids) |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 43 | return false; |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 44 | dlc_ids->clear(); |
Jae Hoon Kim | c43f6bb | 2019-07-03 12:56:52 -0700 | [diff] [blame] | 45 | |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 46 | brillo::ErrorPtr err; |
| 47 | if (!GetDlcServiceProxy().GetDlcsToUpdate(dlc_ids, &err)) { |
| 48 | LOG(ERROR) << "dlcservice failed to return DLCs that need to be updated. " |
| 49 | << "ErrorCode=" << err->GetCode() |
| 50 | << ", ErrMsg=" << err->GetMessage(); |
| 51 | dlc_ids->clear(); |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 52 | return false; |
| 53 | } |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 54 | return true; |
| 55 | } |
| 56 | |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 57 | bool DlcServiceChromeOS::InstallCompleted(const vector<string>& dlc_ids) { |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 58 | brillo::ErrorPtr err; |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 59 | if (!GetDlcServiceProxy().InstallCompleted(dlc_ids, &err)) { |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 60 | LOG(ERROR) << "dlcservice failed to complete install. ErrCode=" |
| 61 | << err->GetCode() << ", ErrMsg=" << err->GetMessage(); |
| 62 | return false; |
| 63 | } |
| 64 | return true; |
| 65 | } |
| 66 | |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 67 | bool DlcServiceChromeOS::UpdateCompleted(const vector<string>& dlc_ids) { |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 68 | brillo::ErrorPtr err; |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 69 | if (!GetDlcServiceProxy().UpdateCompleted(dlc_ids, &err)) { |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 70 | LOG(ERROR) << "dlcservice failed to complete updated. ErrCode=" |
| 71 | << err->GetCode() << ", ErrMsg=" << err->GetMessage(); |
| 72 | return false; |
| 73 | } |
| 74 | return true; |
| 75 | } |
| 76 | |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 77 | } // namespace chromeos_update_engine |