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
19 #include <brillo/errors/error.h>
20 #include <dlcservice/proto_bindings/dlcservice.pb.h>
21 // NOLINTNEXTLINE(build/include_alpha) "dbus-proxies.h" needs "dlcservice.pb.h"
22 #include <dlcservice/dbus-proxies.h>
23
24 #include "update_engine/dbus_connection.h"
25
26 using std::string;
27 using std::vector;
28
29 namespace chromeos_update_engine {
30
31 namespace {
GetDlcServiceProxy()32 org::chromium::DlcServiceInterfaceProxy GetDlcServiceProxy() {
33 return {DBusConnection::Get()->GetDBus()};
34 }
35 } // namespace
36
CreateDlcService()37 std::unique_ptr<DlcServiceInterface> CreateDlcService() {
38 return std::make_unique<DlcServiceChromeOS>();
39 }
40
GetDlcsToUpdate(vector<string> * dlc_ids)41 bool DlcServiceChromeOS::GetDlcsToUpdate(vector<string>* dlc_ids) {
42 if (!dlc_ids)
43 return false;
44 dlc_ids->clear();
45
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();
52 return false;
53 }
54 return true;
55 }
56
InstallCompleted(const vector<string> & dlc_ids)57 bool DlcServiceChromeOS::InstallCompleted(const vector<string>& dlc_ids) {
58 brillo::ErrorPtr err;
59 if (!GetDlcServiceProxy().InstallCompleted(dlc_ids, &err)) {
60 LOG(ERROR) << "dlcservice failed to complete install. ErrCode="
61 << err->GetCode() << ", ErrMsg=" << err->GetMessage();
62 return false;
63 }
64 return true;
65 }
66
UpdateCompleted(const vector<string> & dlc_ids)67 bool DlcServiceChromeOS::UpdateCompleted(const vector<string>& dlc_ids) {
68 brillo::ErrorPtr err;
69 if (!GetDlcServiceProxy().UpdateCompleted(dlc_ids, &err)) {
70 LOG(ERROR) << "dlcservice failed to complete updated. ErrCode="
71 << err->GetCode() << ", ErrMsg=" << err->GetMessage();
72 return false;
73 }
74 return true;
75 }
76
77 } // namespace chromeos_update_engine
78