blob: 3c76b2adb2b61981efd5db99909c648b1217b9ed [file] [log] [blame]
Xiaochu Liu8ba486f2018-11-06 11:14:10 -08001//
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 Kim7fdfbf12020-04-10 18:15:50 -070019#include <brillo/errors/error.h>
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080020#include <dlcservice/proto_bindings/dlcservice.pb.h>
Amin Hassani3bab1772019-06-21 14:58:25 -070021// NOLINTNEXTLINE(build/include_alpha) "dbus-proxies.h" needs "dlcservice.pb.h"
22#include <dlcservice/dbus-proxies.h>
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080023
24#include "update_engine/dbus_connection.h"
25
Amin Hassani3bab1772019-06-21 14:58:25 -070026using dlcservice::DlcModuleList;
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080027using std::string;
28using std::vector;
29
30namespace chromeos_update_engine {
31
Jae Hoon Kim7fdfbf12020-04-10 18:15:50 -070032namespace {
33org::chromium::DlcServiceInterfaceProxy GetDlcServiceProxy() {
34 return {DBusConnection::Get()->GetDBus()};
35}
36} // namespace
37
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080038std::unique_ptr<DlcServiceInterface> CreateDlcService() {
39 return std::make_unique<DlcServiceChromeOS>();
40}
41
42bool DlcServiceChromeOS::GetInstalled(vector<string>* dlc_module_ids) {
43 if (!dlc_module_ids)
44 return false;
Jae Hoon Kimc43f6bb2019-07-03 12:56:52 -070045 dlc_module_ids->clear();
46
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080047 dlcservice::DlcModuleList dlc_module_list;
Jae Hoon Kim7fdfbf12020-04-10 18:15:50 -070048 if (!GetDlcServiceProxy().GetInstalled(&dlc_module_list, nullptr)) {
Amin Hassani3bab1772019-06-21 14:58:25 -070049 LOG(ERROR) << "dlcservice does not return installed DLC module list.";
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080050 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 Kim7fdfbf12020-04-10 18:15:50 -070058bool 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
68bool 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 Liu8ba486f2018-11-06 11:14:10 -080078} // namespace chromeos_update_engine