Jay Srinivasan | e73acab | 2012-07-10 14:34:03 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/dbus_service.h" |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 6 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 7 | #include <set> |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 8 | #include <string> |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 9 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 10 | #include <base/location.h> |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 11 | #include <base/logging.h> |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 12 | #include <base/strings/stringprintf.h> |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 13 | #include <chromeos/bind_lambda.h> |
| 14 | #include <chromeos/message_loops/message_loop.h> |
Gilad Arnold | ccd0957 | 2014-10-27 13:37:50 -0700 | [diff] [blame] | 15 | #include <chromeos/strings/string_utils.h> |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 16 | #include <policy/device_policy.h> |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 17 | |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 18 | #include "update_engine/clock_interface.h" |
Alex Deymo | f6ee016 | 2015-07-31 12:35:22 -0700 | [diff] [blame] | 19 | #include "update_engine/connection_manager_interface.h" |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 20 | #include "update_engine/dbus_constants.h" |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 21 | #include "update_engine/hardware_interface.h" |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 22 | #include "update_engine/omaha_request_params.h" |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 23 | #include "update_engine/p2p_manager.h" |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 24 | #include "update_engine/prefs.h" |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 25 | #include "update_engine/update_attempter.h" |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 26 | #include "update_engine/utils.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 27 | |
Gilad Arnold | ccd0957 | 2014-10-27 13:37:50 -0700 | [diff] [blame] | 28 | using base::StringPrintf; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 29 | using chromeos::ErrorPtr; |
Gilad Arnold | ccd0957 | 2014-10-27 13:37:50 -0700 | [diff] [blame] | 30 | using chromeos::string_utils::ToString; |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 31 | using chromeos_update_engine::AttemptUpdateFlags; |
| 32 | using chromeos_update_engine::kAttemptUpdateFlagNonInteractive; |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 33 | using std::set; |
| 34 | using std::string; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 35 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 36 | namespace { |
| 37 | // Log and set the error on the passed ErrorPtr. |
| 38 | void LogAndSetError(ErrorPtr *error, |
| 39 | const tracked_objects::Location& location, |
| 40 | const string& reason) { |
| 41 | chromeos::Error::AddTo( |
| 42 | error, location, |
| 43 | chromeos::errors::dbus::kDomain, |
| 44 | chromeos_update_engine::kUpdateEngineServiceErrorFailed, reason); |
| 45 | LOG(ERROR) << "Sending DBus Failure: " << location.ToString() << ": " |
| 46 | << reason; |
| 47 | } |
| 48 | } // namespace |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 49 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 50 | namespace chromeos_update_engine { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 51 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 52 | UpdateEngineService::UpdateEngineService(SystemState* system_state) |
| 53 | : system_state_(system_state) {} |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 54 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 55 | // org::chromium::UpdateEngineInterfaceInterface methods implementation. |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 56 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 57 | bool UpdateEngineService::AttemptUpdate(ErrorPtr* error, |
| 58 | const string& in_app_version, |
| 59 | const string& in_omaha_url) { |
| 60 | return AttemptUpdateWithFlags( |
| 61 | error, in_app_version, in_omaha_url, 0 /* no flags */); |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 64 | bool UpdateEngineService::AttemptUpdateWithFlags(ErrorPtr* /* error */, |
| 65 | const string& in_app_version, |
| 66 | const string& in_omaha_url, |
| 67 | int32_t in_flags_as_int) { |
| 68 | AttemptUpdateFlags flags = static_cast<AttemptUpdateFlags>(in_flags_as_int); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 69 | bool interactive = !(flags & kAttemptUpdateFlagNonInteractive); |
Jay Srinivasan | e73acab | 2012-07-10 14:34:03 -0700 | [diff] [blame] | 70 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 71 | LOG(INFO) << "Attempt update: app_version=\"" << in_app_version << "\" " |
| 72 | << "omaha_url=\"" << in_omaha_url << "\" " |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 73 | << "flags=0x" << std::hex << flags << " " |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 74 | << "interactive=" << (interactive? "yes" : "no"); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 75 | system_state_->update_attempter()->CheckForUpdate( |
| 76 | in_app_version, in_omaha_url, interactive); |
| 77 | return true; |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 80 | bool UpdateEngineService::AttemptRollback(ErrorPtr* error, |
| 81 | bool in_powerwash) { |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 82 | LOG(INFO) << "Attempting rollback to non-active partitions."; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 83 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 84 | if (!system_state_->update_attempter()->Rollback(in_powerwash)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 85 | // TODO(dgarrett): Give a more specific error code/reason. |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 86 | LogAndSetError(error, FROM_HERE, "Rollback attempt failed."); |
| 87 | return false; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 88 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 89 | return true; |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 92 | bool UpdateEngineService::CanRollback(ErrorPtr* /* error */, |
| 93 | bool* out_can_rollback) { |
| 94 | bool can_rollback = system_state_->update_attempter()->CanRollback(); |
Chris Sosa | 44b9b7e | 2014-04-02 13:53:46 -0700 | [diff] [blame] | 95 | LOG(INFO) << "Checking to see if we can rollback . Result: " << can_rollback; |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 96 | *out_can_rollback = can_rollback; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 97 | return true; |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 100 | bool UpdateEngineService::ResetStatus(ErrorPtr* error) { |
| 101 | if (!system_state_->update_attempter()->ResetStatus()) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 102 | // TODO(dgarrett): Give a more specific error code/reason. |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 103 | LogAndSetError(error, FROM_HERE, "ResetStatus failed."); |
| 104 | return false; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 105 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 106 | return true; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 107 | } |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 108 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 109 | bool UpdateEngineService::GetStatus(ErrorPtr* error, |
| 110 | int64_t* out_last_checked_time, |
| 111 | double* out_progress, |
| 112 | string* out_current_operation, |
| 113 | string* out_new_version, |
| 114 | int64_t* out_new_size) { |
| 115 | if (!system_state_->update_attempter()->GetStatus(out_last_checked_time, |
| 116 | out_progress, |
| 117 | out_current_operation, |
| 118 | out_new_version, |
| 119 | out_new_size)) { |
| 120 | LogAndSetError(error, FROM_HERE, "GetStatus failed."); |
| 121 | return false; |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 122 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 123 | return true; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 126 | bool UpdateEngineService::RebootIfNeeded(ErrorPtr* error) { |
| 127 | if (!system_state_->update_attempter()->RebootIfNeeded()) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 128 | // TODO(dgarrett): Give a more specific error code/reason. |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 129 | LogAndSetError(error, FROM_HERE, "Reboot not needed, or attempt failed."); |
| 130 | return false; |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 131 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 132 | return true; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 135 | bool UpdateEngineService::SetChannel(ErrorPtr* error, |
| 136 | const string& in_target_channel, |
| 137 | bool in_is_powerwash_allowed) { |
| 138 | const policy::DevicePolicy* device_policy = system_state_->device_policy(); |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 139 | |
| 140 | // The device_policy is loaded in a lazy way before an update check. Load it |
| 141 | // now from the libchromeos cache if it wasn't already loaded. |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 142 | if (!device_policy) { |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 143 | UpdateAttempter* update_attempter = system_state_->update_attempter(); |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 144 | if (update_attempter) { |
| 145 | update_attempter->RefreshDevicePolicy(); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 146 | device_policy = system_state_->device_policy(); |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 147 | } |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 148 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 149 | |
| 150 | bool delegated = false; |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 151 | if (device_policy && |
| 152 | device_policy->GetReleaseChannelDelegated(&delegated) && !delegated) { |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 153 | LogAndSetError( |
| 154 | error, FROM_HERE, |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 155 | "Cannot set target channel explicitly when channel " |
| 156 | "policy/settings is not delegated"); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 157 | return false; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 160 | LOG(INFO) << "Setting destination channel to: " << in_target_channel; |
| 161 | if (!system_state_->request_params()->SetTargetChannel( |
| 162 | in_target_channel, in_is_powerwash_allowed)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 163 | // TODO(dgarrett): Give a more specific error code/reason. |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 164 | LogAndSetError(error, FROM_HERE, "Setting channel failed."); |
| 165 | return false; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 166 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 167 | return true; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 170 | bool UpdateEngineService::GetChannel(ErrorPtr* /* error */, |
| 171 | bool in_get_current_channel, |
| 172 | string* out_channel) { |
| 173 | OmahaRequestParams* rp = system_state_->request_params(); |
| 174 | *out_channel = (in_get_current_channel ? |
| 175 | rp->current_channel() : rp->target_channel()); |
| 176 | return true; |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 179 | bool UpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error, |
| 180 | bool in_enabled) { |
| 181 | PrefsInterface* prefs = system_state_->prefs(); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 182 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 183 | if (!prefs->SetBoolean(kPrefsP2PEnabled, in_enabled)) { |
| 184 | LogAndSetError( |
| 185 | error, FROM_HERE, |
Gilad Arnold | ccd0957 | 2014-10-27 13:37:50 -0700 | [diff] [blame] | 186 | StringPrintf("Error setting the update via p2p permission to %s.", |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 187 | ToString(in_enabled).c_str())); |
| 188 | return false; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 189 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 190 | return true; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 193 | bool UpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error, |
| 194 | bool* out_enabled) { |
| 195 | PrefsInterface* prefs = system_state_->prefs(); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 196 | |
Gilad Arnold | 367a3ad | 2014-10-23 16:00:17 -0700 | [diff] [blame] | 197 | bool p2p_pref = false; // Default if no setting is present. |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 198 | if (prefs->Exists(kPrefsP2PEnabled) && |
| 199 | !prefs->GetBoolean(kPrefsP2PEnabled, &p2p_pref)) { |
| 200 | LogAndSetError(error, FROM_HERE, "Error getting the P2PEnabled setting."); |
| 201 | return false; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 204 | *out_enabled = p2p_pref; |
| 205 | return true; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 208 | bool UpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error, |
| 209 | bool in_allowed) { |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 210 | set<string> allowed_types; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 211 | const policy::DevicePolicy* device_policy = system_state_->device_policy(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 212 | |
| 213 | // The device_policy is loaded in a lazy way before an update check. Load it |
| 214 | // now from the libchromeos cache if it wasn't already loaded. |
| 215 | if (!device_policy) { |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 216 | UpdateAttempter* update_attempter = system_state_->update_attempter(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 217 | if (update_attempter) { |
| 218 | update_attempter->RefreshDevicePolicy(); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 219 | device_policy = system_state_->device_policy(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
| 223 | // Check if this setting is allowed by the device policy. |
| 224 | if (device_policy && |
| 225 | device_policy->GetAllowedConnectionTypesForUpdate(&allowed_types)) { |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 226 | LogAndSetError(error, FROM_HERE, |
| 227 | "Ignoring the update over cellular setting since there's " |
| 228 | "a device policy enforcing this setting."); |
| 229 | return false; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | // If the policy wasn't loaded yet, then it is still OK to change the local |
| 233 | // setting because the policy will be checked again during the update check. |
| 234 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 235 | PrefsInterface* prefs = system_state_->prefs(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 236 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 237 | if (!prefs->SetBoolean(kPrefsUpdateOverCellularPermission, in_allowed)) { |
| 238 | LogAndSetError(error, FROM_HERE, |
| 239 | string("Error setting the update over cellular to ") + |
| 240 | (in_allowed ? "true" : "false")); |
| 241 | return false; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 242 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 243 | return true; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 246 | bool UpdateEngineService::GetUpdateOverCellularPermission(ErrorPtr* /* error */, |
| 247 | bool* out_allowed) { |
| 248 | ConnectionManagerInterface* cm = system_state_->connection_manager(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 249 | |
| 250 | // The device_policy is loaded in a lazy way before an update check and is |
| 251 | // used to determine if an update is allowed over cellular. Load the device |
| 252 | // policy now from the libchromeos cache if it wasn't already loaded. |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 253 | if (!system_state_->device_policy()) { |
| 254 | UpdateAttempter* update_attempter = system_state_->update_attempter(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 255 | if (update_attempter) |
| 256 | update_attempter->RefreshDevicePolicy(); |
| 257 | } |
| 258 | |
| 259 | // Return the current setting based on the same logic used while checking for |
| 260 | // updates. A log message could be printed as the result of this test. |
| 261 | LOG(INFO) << "Checking if updates over cellular networks are allowed:"; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 262 | *out_allowed = cm->IsUpdateAllowedOver( |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 263 | chromeos_update_engine::NetworkConnectionType::kCellular, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 264 | chromeos_update_engine::NetworkTethering::kUnknown); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 265 | return true; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 268 | bool UpdateEngineService::GetDurationSinceUpdate(ErrorPtr* error, |
| 269 | int64_t* out_usec_wallclock) { |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 270 | base::Time time; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 271 | if (!system_state_->update_attempter()->GetBootTimeAtUpdate(&time)) { |
| 272 | LogAndSetError(error, FROM_HERE, "No pending update."); |
| 273 | return false; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 274 | } |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 275 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 276 | ClockInterface* clock = system_state_->clock(); |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 277 | *out_usec_wallclock = (clock->GetBootTime() - time).InMicroseconds(); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 278 | return true; |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 281 | bool UpdateEngineService::GetPrevVersion(ErrorPtr* /* error */, |
| 282 | string* out_prev_version) { |
| 283 | *out_prev_version = system_state_->update_attempter()->GetPrevVersion(); |
| 284 | return true; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 285 | } |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 286 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 287 | bool UpdateEngineService::GetKernelDevices(ErrorPtr* /* error */, |
| 288 | string* out_kernel_devices) { |
| 289 | auto devices = system_state_->update_attempter()->GetKernelDevices(); |
| 290 | string info; |
| 291 | for (const auto& device : devices) { |
| 292 | base::StringAppendF(&info, "%d:%s\n", |
| 293 | device.second ? 1 : 0, device.first.c_str()); |
| 294 | } |
| 295 | LOG(INFO) << "Available kernel devices: " << info; |
| 296 | *out_kernel_devices = info; |
| 297 | return true; |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 298 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame^] | 299 | |
| 300 | bool UpdateEngineService::GetRollbackPartition( |
| 301 | ErrorPtr* /* error */, |
| 302 | string* out_rollback_partition_name) { |
| 303 | string name = system_state_->update_attempter()->GetRollbackPartition(); |
| 304 | LOG(INFO) << "Getting rollback partition name. Result: " << name; |
| 305 | *out_rollback_partition_name = name; |
| 306 | return true; |
| 307 | } |
| 308 | |
| 309 | |
| 310 | UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state, |
| 311 | const scoped_refptr<dbus::Bus>& bus) |
| 312 | : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_), |
| 313 | bus_(bus), |
| 314 | dbus_service_(system_state), |
| 315 | dbus_object_(nullptr, bus, dbus::ObjectPath(kUpdateEngineServicePath)) {} |
| 316 | |
| 317 | void UpdateEngineAdaptor::RegisterAsync( |
| 318 | const base::Callback<void(bool)>& completion_callback) { |
| 319 | RegisterWithDBusObject(&dbus_object_); |
| 320 | dbus_object_.RegisterAsync(completion_callback); |
| 321 | } |
| 322 | |
| 323 | bool UpdateEngineAdaptor::RequestOwnership() { |
| 324 | return bus_->RequestOwnershipAndBlock(kUpdateEngineServiceName, |
| 325 | dbus::Bus::REQUIRE_PRIMARY); |
| 326 | } |
| 327 | |
| 328 | } // namespace chromeos_update_engine |