blob: e510c1d1e14f292b80e10e1bfd4c8129a296e7e0 [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
Amin Hassaniec7bc112020-10-29 16:47:58 -070017#include "update_engine/cros/dlcservice_chromeos.h"
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080018
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
Amin Hassaniec7bc112020-10-29 16:47:58 -070024#include "update_engine/cros/dbus_connection.h"
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080025
26using std::string;
27using std::vector;
28
29namespace chromeos_update_engine {
30
Jae Hoon Kim7fdfbf12020-04-10 18:15:50 -070031namespace {
32org::chromium::DlcServiceInterfaceProxy GetDlcServiceProxy() {
33 return {DBusConnection::Get()->GetDBus()};
34}
35} // namespace
36
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080037std::unique_ptr<DlcServiceInterface> CreateDlcService() {
38 return std::make_unique<DlcServiceChromeOS>();
39}
40
Amin Hassani2b68e6b2020-04-17 10:49:12 -070041bool DlcServiceChromeOS::GetDlcsToUpdate(vector<string>* dlc_ids) {
42 if (!dlc_ids)
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080043 return false;
Amin Hassani2b68e6b2020-04-17 10:49:12 -070044 dlc_ids->clear();
Jae Hoon Kimc43f6bb2019-07-03 12:56:52 -070045
Amin Hassani2b68e6b2020-04-17 10:49:12 -070046 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 Liu8ba486f2018-11-06 11:14:10 -080052 return false;
53 }
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080054 return true;
55}
56
Amin Hassani2b68e6b2020-04-17 10:49:12 -070057bool DlcServiceChromeOS::InstallCompleted(const vector<string>& dlc_ids) {
Jae Hoon Kim7fdfbf12020-04-10 18:15:50 -070058 brillo::ErrorPtr err;
Amin Hassani2b68e6b2020-04-17 10:49:12 -070059 if (!GetDlcServiceProxy().InstallCompleted(dlc_ids, &err)) {
Jae Hoon Kim7fdfbf12020-04-10 18:15:50 -070060 LOG(ERROR) << "dlcservice failed to complete install. ErrCode="
61 << err->GetCode() << ", ErrMsg=" << err->GetMessage();
62 return false;
63 }
64 return true;
65}
66
Amin Hassani2b68e6b2020-04-17 10:49:12 -070067bool DlcServiceChromeOS::UpdateCompleted(const vector<string>& dlc_ids) {
Jae Hoon Kim7fdfbf12020-04-10 18:15:50 -070068 brillo::ErrorPtr err;
Amin Hassani2b68e6b2020-04-17 10:49:12 -070069 if (!GetDlcServiceProxy().UpdateCompleted(dlc_ids, &err)) {
Jae Hoon Kim7fdfbf12020-04-10 18:15:50 -070070 LOG(ERROR) << "dlcservice failed to complete updated. ErrCode="
71 << err->GetCode() << ", ErrMsg=" << err->GetMessage();
72 return false;
73 }
74 return true;
75}
76
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080077} // namespace chromeos_update_engine