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 <dlcservice/dbus-proxies.h>
20 #include <dlcservice/proto_bindings/dlcservice.pb.h>
21 
22 #include "update_engine/dbus_connection.h"
23 
24 using std::string;
25 using std::vector;
26 
27 namespace chromeos_update_engine {
28 
29 std::unique_ptr<DlcServiceInterface> CreateDlcService() {
30   return std::make_unique<DlcServiceChromeOS>();
31 }
32 
33 bool DlcServiceChromeOS::GetInstalled(vector<string>* dlc_module_ids) {
34   if (!dlc_module_ids)
35     return false;
36   org::chromium::DlcServiceInterfaceProxy dlcservice_proxy(
37       DBusConnection::Get()->GetDBus());
38   string dlc_module_list_str;
39   if (!dlcservice_proxy.GetInstalled(&dlc_module_list_str, nullptr)) {
40     LOG(ERROR) << "dlcservice does not return installed DLC module list.";
41     return false;
42   }
43   dlcservice::DlcModuleList dlc_module_list;
44   if (!dlc_module_list.ParseFromString(dlc_module_list_str)) {
45     LOG(ERROR) << "Errors parsing DlcModuleList protobuf.";
46     return false;
47   }
48   for (const auto& dlc_module_info : dlc_module_list.dlc_module_infos()) {
49     dlc_module_ids->emplace_back(dlc_module_info.dlc_id());
50   }
51   return true;
52 }
53 
54 }  // namespace chromeos_update_engine
55