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 | |
| 10 | #include <base/logging.h> |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame^] | 11 | #include <base/strings/stringprintf.h> |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 12 | #include <policy/device_policy.h> |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 13 | |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 14 | #include "update_engine/clock_interface.h" |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 15 | #include "update_engine/connection_manager.h" |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 16 | #include "update_engine/dbus_constants.h" |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 17 | #include "update_engine/hardware_interface.h" |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 18 | #include "update_engine/omaha_request_params.h" |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 19 | #include "update_engine/p2p_manager.h" |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 20 | #include "update_engine/prefs.h" |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 21 | #include "update_engine/update_attempter.h" |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 22 | #include "update_engine/utils.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 23 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 24 | using std::set; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 25 | using std::string; |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 26 | using chromeos_update_engine::AttemptUpdateFlags; |
| 27 | using chromeos_update_engine::kAttemptUpdateFlagNonInteractive; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 28 | |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 29 | #define UPDATE_ENGINE_SERVICE_ERROR update_engine_service_error_quark () |
| 30 | #define UPDATE_ENGINE_SERVICE_TYPE_ERROR \ |
| 31 | (update_engine_service_error_get_type()) |
| 32 | |
| 33 | typedef enum |
| 34 | { |
| 35 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 36 | UPDATE_ENGINE_SERVICE_NUM_ERRORS |
| 37 | } UpdateEngineServiceError; |
| 38 | |
| 39 | static GQuark update_engine_service_error_quark(void) { |
| 40 | static GQuark ret = 0; |
| 41 | |
| 42 | if (ret == 0) |
| 43 | ret = g_quark_from_static_string("update_engine_service_error"); |
| 44 | |
| 45 | return ret; |
| 46 | } |
| 47 | |
| 48 | #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } |
| 49 | |
| 50 | static GType update_engine_service_error_get_type(void) { |
| 51 | static GType etype = 0; |
| 52 | |
| 53 | if (etype == 0) { |
| 54 | static const GEnumValue values[] = { |
| 55 | ENUM_ENTRY(UPDATE_ENGINE_SERVICE_ERROR_FAILED, "Failed"), |
| 56 | { 0, 0, 0 } |
| 57 | }; |
| 58 | G_STATIC_ASSERT(UPDATE_ENGINE_SERVICE_NUM_ERRORS == |
| 59 | G_N_ELEMENTS (values) - 1); |
| 60 | etype = g_enum_register_static("UpdateEngineServiceError", values); |
| 61 | } |
| 62 | |
| 63 | return etype; |
| 64 | } |
| 65 | |
Darin Petkov | 820a77b | 2011-04-27 16:48:58 -0700 | [diff] [blame] | 66 | static const char kAUTestURLRequest[] = "autest"; |
Jay Srinivasan | e73acab | 2012-07-10 14:34:03 -0700 | [diff] [blame] | 67 | // By default autest bypasses scattering. If we want to test scattering, |
| 68 | // we should use autest-scheduled. The Url used is same in both cases, but |
| 69 | // different params are passed to CheckForUpdate method. |
| 70 | static const char kScheduledAUTestURLRequest[] = "autest-scheduled"; |
| 71 | |
Darin Petkov | 820a77b | 2011-04-27 16:48:58 -0700 | [diff] [blame] | 72 | static const char kAUTestURL[] = |
Darin Petkov | 5445e16 | 2011-11-04 10:10:27 +0100 | [diff] [blame] | 73 | "https://omaha.sandbox.google.com/service/update2"; |
Darin Petkov | 820a77b | 2011-04-27 16:48:58 -0700 | [diff] [blame] | 74 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 75 | G_DEFINE_TYPE(UpdateEngineService, update_engine_service, G_TYPE_OBJECT) |
| 76 | |
| 77 | static void update_engine_service_finalize(GObject* object) { |
| 78 | G_OBJECT_CLASS(update_engine_service_parent_class)->finalize(object); |
| 79 | } |
| 80 | |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 81 | static void log_and_set_response_error(GError** error, |
| 82 | UpdateEngineServiceError error_code, |
| 83 | const string& reason) { |
| 84 | LOG(ERROR) << "Sending DBus Failure: " << reason; |
| 85 | g_set_error_literal(error, UPDATE_ENGINE_SERVICE_ERROR, |
| 86 | error_code, reason.c_str()); |
| 87 | } |
| 88 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 89 | static guint status_update_signal = 0; |
| 90 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 91 | static void update_engine_service_class_init(UpdateEngineServiceClass* klass) { |
| 92 | GObjectClass *object_class; |
| 93 | object_class = G_OBJECT_CLASS(klass); |
| 94 | object_class->finalize = update_engine_service_finalize; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 95 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 96 | status_update_signal = g_signal_new( |
| 97 | "status_update", |
| 98 | G_OBJECT_CLASS_TYPE(klass), |
| 99 | G_SIGNAL_RUN_LAST, |
| 100 | 0, // 0 == no class method associated |
| 101 | NULL, // Accumulator |
| 102 | NULL, // Accumulator data |
Alex Deymo | 3d41c4d | 2014-02-13 23:26:33 -0800 | [diff] [blame] | 103 | NULL, // Marshaller |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 104 | G_TYPE_NONE, // Return type |
| 105 | 5, // param count: |
| 106 | G_TYPE_INT64, |
| 107 | G_TYPE_DOUBLE, |
| 108 | G_TYPE_STRING, |
| 109 | G_TYPE_STRING, |
| 110 | G_TYPE_INT64); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static void update_engine_service_init(UpdateEngineService* object) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 114 | dbus_g_error_domain_register (UPDATE_ENGINE_SERVICE_ERROR, |
| 115 | "org.chromium.UpdateEngine.Error", |
| 116 | UPDATE_ENGINE_SERVICE_TYPE_ERROR); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | UpdateEngineService* update_engine_service_new(void) { |
| 120 | return reinterpret_cast<UpdateEngineService*>( |
| 121 | g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); |
| 122 | } |
| 123 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 124 | gboolean update_engine_service_attempt_update(UpdateEngineService* self, |
| 125 | gchar* app_version, |
| 126 | gchar* omaha_url, |
| 127 | GError **error) { |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 128 | return update_engine_service_attempt_update_with_flags(self, |
| 129 | app_version, |
| 130 | omaha_url, |
| 131 | 0, // No flags set. |
| 132 | error); |
| 133 | } |
| 134 | |
| 135 | gboolean update_engine_service_attempt_update_with_flags( |
| 136 | UpdateEngineService* self, |
| 137 | gchar* app_version, |
| 138 | gchar* omaha_url, |
| 139 | gint flags_as_int, |
| 140 | GError **error) { |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 141 | string update_app_version; |
| 142 | string update_omaha_url; |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 143 | AttemptUpdateFlags flags = static_cast<AttemptUpdateFlags>(flags_as_int); |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 144 | bool interactive = true; |
Jay Srinivasan | e73acab | 2012-07-10 14:34:03 -0700 | [diff] [blame] | 145 | |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 146 | // Only non-official (e.g., dev and test) builds can override the current |
Darin Petkov | 820a77b | 2011-04-27 16:48:58 -0700 | [diff] [blame] | 147 | // version and update server URL over D-Bus. However, pointing to the |
| 148 | // hardcoded test update server URL is always allowed. |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 149 | if (!self->system_state_->hardware()->IsOfficialBuild()) { |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 150 | if (app_version) { |
| 151 | update_app_version = app_version; |
| 152 | } |
| 153 | if (omaha_url) { |
| 154 | update_omaha_url = omaha_url; |
| 155 | } |
| 156 | } |
Jay Srinivasan | e73acab | 2012-07-10 14:34:03 -0700 | [diff] [blame] | 157 | if (omaha_url) { |
| 158 | if (strcmp(omaha_url, kScheduledAUTestURLRequest) == 0) { |
| 159 | update_omaha_url = kAUTestURL; |
| 160 | // pretend that it's not user-initiated even though it is, |
| 161 | // so as to test scattering logic, etc. which get kicked off |
| 162 | // only in scheduled update checks. |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 163 | interactive = false; |
Jay Srinivasan | e73acab | 2012-07-10 14:34:03 -0700 | [diff] [blame] | 164 | } else if (strcmp(omaha_url, kAUTestURLRequest) == 0) { |
| 165 | update_omaha_url = kAUTestURL; |
| 166 | } |
Darin Petkov | 820a77b | 2011-04-27 16:48:58 -0700 | [diff] [blame] | 167 | } |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 168 | if (flags & kAttemptUpdateFlagNonInteractive) |
| 169 | interactive = false; |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 170 | LOG(INFO) << "Attempt update: app_version=\"" << update_app_version << "\" " |
Jay Srinivasan | e73acab | 2012-07-10 14:34:03 -0700 | [diff] [blame] | 171 | << "omaha_url=\"" << update_omaha_url << "\" " |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 172 | << "flags=0x" << std::hex << flags << " " |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 173 | << "interactive=" << (interactive? "yes" : "no"); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 174 | self->system_state_->update_attempter()->CheckForUpdate(update_app_version, |
| 175 | update_omaha_url, |
| 176 | interactive); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 177 | return TRUE; |
| 178 | } |
| 179 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 180 | gboolean update_engine_service_attempt_rollback(UpdateEngineService* self, |
Alex Deymo | ad92373 | 2013-08-29 16:13:49 -0700 | [diff] [blame] | 181 | gboolean powerwash, |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 182 | GError **error) { |
| 183 | LOG(INFO) << "Attempting rollback to non-active partitions."; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 184 | |
| 185 | if (!self->system_state_->update_attempter()->Rollback(powerwash, NULL)) { |
| 186 | // TODO(dgarrett): Give a more specific error code/reason. |
| 187 | log_and_set_response_error(error, |
| 188 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 189 | "Rollback attempt failed."); |
| 190 | return FALSE; |
| 191 | } |
| 192 | |
| 193 | return TRUE; |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 196 | gboolean update_engine_service_can_rollback(UpdateEngineService* self, |
| 197 | gboolean* out_can_rollback, |
| 198 | GError **error) |
| 199 | { |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame^] | 200 | bool can_rollback = self->system_state_->update_attempter()->CanRollback(); |
| 201 | LOG(INFO) << "Checking for a rollback partition. Result: " << can_rollback; |
| 202 | *out_can_rollback = can_rollback; |
| 203 | return TRUE; |
| 204 | } |
| 205 | |
| 206 | gboolean update_engine_service_get_rollback_partition( |
| 207 | UpdateEngineService* self, |
| 208 | gchar** out_rollback_partition_name, |
| 209 | GError **error) { |
| 210 | auto name = self->system_state_->update_attempter()->GetRollbackPartition(); |
| 211 | LOG(INFO) << "Getting rollback partition name. Result: " << name; |
| 212 | *out_rollback_partition_name = g_strdup(name.c_str()); |
| 213 | return TRUE; |
| 214 | } |
| 215 | |
| 216 | gboolean update_engine_service_get_kernel_devices(UpdateEngineService* self, |
| 217 | gchar** out_kernel_devices, |
| 218 | GError **error) { |
| 219 | auto devices = self->system_state_->update_attempter()->GetKernelDevices(); |
| 220 | std::string info; |
| 221 | for (auto&& device : devices) { |
| 222 | base::StringAppendF(&info, "%d:%s\n", |
| 223 | device.second ? 1 : 0, device.first.c_str()); |
| 224 | } |
| 225 | LOG(INFO) << "Available kernel devices: " << info; |
| 226 | *out_kernel_devices = g_strdup(info.c_str()); |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 227 | return TRUE; |
| 228 | } |
| 229 | |
| 230 | |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 231 | gboolean update_engine_service_reset_status(UpdateEngineService* self, |
| 232 | GError **error) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 233 | if (!self->system_state_->update_attempter()->ResetStatus()) { |
| 234 | // TODO(dgarrett): Give a more specific error code/reason. |
| 235 | log_and_set_response_error(error, |
| 236 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 237 | "ResetStatus failed."); |
| 238 | return FALSE; |
| 239 | } |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 240 | |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 241 | return TRUE; |
| 242 | } |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 243 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 244 | gboolean update_engine_service_get_status(UpdateEngineService* self, |
| 245 | int64_t* last_checked_time, |
| 246 | double* progress, |
| 247 | gchar** current_operation, |
| 248 | gchar** new_version, |
| 249 | int64_t* new_size, |
| 250 | GError **error) { |
| 251 | string current_op; |
| 252 | string new_version_str; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 253 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 254 | CHECK(self->system_state_->update_attempter()->GetStatus(last_checked_time, |
| 255 | progress, |
| 256 | ¤t_op, |
| 257 | &new_version_str, |
| 258 | new_size)); |
Satoru Takabayashi | d698231 | 2010-11-29 12:54:12 +0900 | [diff] [blame] | 259 | *current_operation = g_strdup(current_op.c_str()); |
| 260 | *new_version = g_strdup(new_version_str.c_str()); |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 261 | |
| 262 | if (!*current_operation) { |
| 263 | log_and_set_response_error(error, |
| 264 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 265 | "Unable to find current_operation."); |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 266 | return FALSE; |
| 267 | } |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 268 | |
| 269 | if (!*new_version) { |
| 270 | log_and_set_response_error(error, |
| 271 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 272 | "Unable to find vew_version."); |
| 273 | return FALSE; |
| 274 | } |
| 275 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 276 | return TRUE; |
| 277 | } |
| 278 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 279 | gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self, |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 280 | GError **error) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 281 | if (!self->system_state_->update_attempter()->RebootIfNeeded()) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 282 | // TODO(dgarrett): Give a more specific error code/reason. |
| 283 | log_and_set_response_error(error, |
| 284 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 285 | "Reboot not needed, or attempt failed."); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 286 | return FALSE; |
| 287 | } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 288 | return TRUE; |
| 289 | } |
| 290 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 291 | gboolean update_engine_service_set_channel(UpdateEngineService* self, |
| 292 | gchar* target_channel, |
Alex Deymo | ad92373 | 2013-08-29 16:13:49 -0700 | [diff] [blame] | 293 | gboolean is_powerwash_allowed, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 294 | GError **error) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 295 | if (!target_channel) { |
| 296 | log_and_set_response_error(error, |
| 297 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 298 | "Target channel to set not specified."); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 299 | return FALSE; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 300 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 301 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 302 | const policy::DevicePolicy* device_policy = |
| 303 | self->system_state_->device_policy(); |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 304 | |
| 305 | // The device_policy is loaded in a lazy way before an update check. Load it |
| 306 | // now from the libchromeos cache if it wasn't already loaded. |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 307 | if (!device_policy) { |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 308 | chromeos_update_engine::UpdateAttempter* update_attempter = |
| 309 | self->system_state_->update_attempter(); |
| 310 | if (update_attempter) { |
| 311 | update_attempter->RefreshDevicePolicy(); |
| 312 | device_policy = self->system_state_->device_policy(); |
| 313 | } |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 314 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 315 | |
| 316 | bool delegated = false; |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 317 | if (device_policy && |
| 318 | device_policy->GetReleaseChannelDelegated(&delegated) && !delegated) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 319 | log_and_set_response_error( |
| 320 | error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 321 | "Cannot set target channel explicitly when channel " |
| 322 | "policy/settings is not delegated"); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 323 | return FALSE; |
| 324 | } |
| 325 | |
| 326 | LOG(INFO) << "Setting destination channel to: " << target_channel; |
| 327 | if (!self->system_state_->request_params()->SetTargetChannel( |
| 328 | target_channel, is_powerwash_allowed)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 329 | // TODO(dgarrett): Give a more specific error code/reason. |
| 330 | log_and_set_response_error(error, |
| 331 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 332 | "Setting channel failed."); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 333 | return FALSE; |
| 334 | } |
| 335 | |
| 336 | return TRUE; |
| 337 | } |
| 338 | |
| 339 | gboolean update_engine_service_get_channel(UpdateEngineService* self, |
Alex Deymo | ad92373 | 2013-08-29 16:13:49 -0700 | [diff] [blame] | 340 | gboolean get_current_channel, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 341 | gchar** channel, |
| 342 | GError **error) { |
| 343 | chromeos_update_engine::OmahaRequestParams* rp = |
| 344 | self->system_state_->request_params(); |
| 345 | |
| 346 | string channel_str = get_current_channel ? |
| 347 | rp->current_channel() : rp->target_channel(); |
| 348 | |
| 349 | *channel = g_strdup(channel_str.c_str()); |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 350 | return TRUE; |
| 351 | } |
| 352 | |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 353 | gboolean update_engine_service_set_p2p_update_permission( |
| 354 | UpdateEngineService* self, |
| 355 | gboolean enabled, |
| 356 | GError **error) { |
| 357 | chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs(); |
| 358 | chromeos_update_engine::P2PManager* p2p_manager = |
| 359 | self->system_state_->p2p_manager(); |
| 360 | |
| 361 | bool p2p_was_enabled = p2p_manager && p2p_manager->IsP2PEnabled(); |
| 362 | |
| 363 | if (!prefs->SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, enabled)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 364 | log_and_set_response_error( |
| 365 | error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 366 | string("Error setting the update over cellular to ") + |
| 367 | (enabled ? "true." : "false.")); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 368 | return FALSE; |
| 369 | } |
| 370 | |
| 371 | // If P2P is being effectively disabled (IsP2PEnabled() reports the change) |
| 372 | // then we need to shutdown the service. |
| 373 | if (p2p_was_enabled && !p2p_manager->IsP2PEnabled()) |
| 374 | p2p_manager->EnsureP2PNotRunning(); |
| 375 | |
| 376 | return TRUE; |
| 377 | } |
| 378 | |
| 379 | gboolean update_engine_service_get_p2p_update_permission( |
| 380 | UpdateEngineService* self, |
| 381 | gboolean* enabled, |
| 382 | GError **error) { |
| 383 | chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs(); |
| 384 | |
| 385 | // The default for not present setting is false. |
| 386 | if (!prefs->Exists(chromeos_update_engine::kPrefsP2PEnabled)) { |
| 387 | *enabled = false; |
| 388 | return TRUE; |
| 389 | } |
| 390 | |
| 391 | bool p2p_pref = false; |
| 392 | if (!prefs->GetBoolean(chromeos_update_engine::kPrefsP2PEnabled, &p2p_pref)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 393 | log_and_set_response_error(error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 394 | "Error getting the P2PEnabled setting."); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 395 | return FALSE; |
| 396 | } |
| 397 | |
| 398 | *enabled = p2p_pref; |
| 399 | return TRUE; |
| 400 | } |
| 401 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 402 | gboolean update_engine_service_set_update_over_cellular_permission( |
| 403 | UpdateEngineService* self, |
Alex Deymo | ad92373 | 2013-08-29 16:13:49 -0700 | [diff] [blame] | 404 | gboolean allowed, |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 405 | GError **error) { |
| 406 | set<string> allowed_types; |
| 407 | const policy::DevicePolicy* device_policy = |
| 408 | self->system_state_->device_policy(); |
| 409 | |
| 410 | // The device_policy is loaded in a lazy way before an update check. Load it |
| 411 | // now from the libchromeos cache if it wasn't already loaded. |
| 412 | if (!device_policy) { |
| 413 | chromeos_update_engine::UpdateAttempter* update_attempter = |
| 414 | self->system_state_->update_attempter(); |
| 415 | if (update_attempter) { |
| 416 | update_attempter->RefreshDevicePolicy(); |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 417 | device_policy = self->system_state_->device_policy(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
| 421 | // Check if this setting is allowed by the device policy. |
| 422 | if (device_policy && |
| 423 | device_policy->GetAllowedConnectionTypesForUpdate(&allowed_types)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 424 | log_and_set_response_error( |
| 425 | error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 426 | "Ignoring the update over cellular setting since there's " |
| 427 | "a device policy enforcing this setting."); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 428 | return FALSE; |
| 429 | } |
| 430 | |
| 431 | // If the policy wasn't loaded yet, then it is still OK to change the local |
| 432 | // setting because the policy will be checked again during the update check. |
| 433 | |
| 434 | chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs(); |
| 435 | |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 436 | if (!prefs->SetBoolean( |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 437 | chromeos_update_engine::kPrefsUpdateOverCellularPermission, |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 438 | allowed)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 439 | log_and_set_response_error( |
| 440 | error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 441 | string("Error setting the update over cellular to ") + |
| 442 | (allowed ? "true" : "false")); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 443 | return FALSE; |
| 444 | } |
| 445 | |
| 446 | return TRUE; |
| 447 | } |
| 448 | |
| 449 | gboolean update_engine_service_get_update_over_cellular_permission( |
| 450 | UpdateEngineService* self, |
Alex Deymo | ad92373 | 2013-08-29 16:13:49 -0700 | [diff] [blame] | 451 | gboolean* allowed, |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 452 | GError **error) { |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 453 | chromeos_update_engine::ConnectionManager* cm = |
| 454 | self->system_state_->connection_manager(); |
| 455 | |
| 456 | // The device_policy is loaded in a lazy way before an update check and is |
| 457 | // used to determine if an update is allowed over cellular. Load the device |
| 458 | // policy now from the libchromeos cache if it wasn't already loaded. |
| 459 | if (!self->system_state_->device_policy()) { |
| 460 | chromeos_update_engine::UpdateAttempter* update_attempter = |
| 461 | self->system_state_->update_attempter(); |
| 462 | if (update_attempter) |
| 463 | update_attempter->RefreshDevicePolicy(); |
| 464 | } |
| 465 | |
| 466 | // Return the current setting based on the same logic used while checking for |
| 467 | // updates. A log message could be printed as the result of this test. |
| 468 | LOG(INFO) << "Checking if updates over cellular networks are allowed:"; |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 469 | *allowed = cm->IsUpdateAllowedOver( |
| 470 | chromeos_update_engine::kNetCellular, |
| 471 | chromeos_update_engine::NetworkTethering::kUnknown); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 472 | |
| 473 | return TRUE; |
| 474 | } |
| 475 | |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 476 | gboolean update_engine_service_get_duration_since_update( |
| 477 | UpdateEngineService* self, |
| 478 | gint64* out_usec_wallclock, |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 479 | GError **error) { |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 480 | |
| 481 | base::Time time; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 482 | if (!self->system_state_->update_attempter()->GetBootTimeAtUpdate(&time)) { |
| 483 | log_and_set_response_error(error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 484 | "No pending update."); |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 485 | return FALSE; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 486 | } |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 487 | |
| 488 | chromeos_update_engine::ClockInterface *clock = self->system_state_->clock(); |
| 489 | *out_usec_wallclock = (clock->GetBootTime() - time).InMicroseconds(); |
| 490 | return TRUE; |
| 491 | } |
| 492 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 493 | gboolean update_engine_service_emit_status_update( |
| 494 | UpdateEngineService* self, |
| 495 | gint64 last_checked_time, |
| 496 | gdouble progress, |
| 497 | const gchar* current_operation, |
| 498 | const gchar* new_version, |
| 499 | gint64 new_size) { |
| 500 | g_signal_emit(self, |
| 501 | status_update_signal, |
| 502 | 0, |
| 503 | last_checked_time, |
| 504 | progress, |
| 505 | current_operation, |
| 506 | new_version, |
| 507 | new_size); |
| 508 | return TRUE; |
| 509 | } |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 510 | |
| 511 | gboolean update_engine_service_get_prev_version( |
| 512 | UpdateEngineService* self, |
| 513 | gchar** prev_version, |
| 514 | GError **error) { |
| 515 | std::string ver = self->system_state_->update_attempter()->GetPrevVersion(); |
| 516 | *prev_version = g_strdup(ver.c_str()); |
| 517 | return TRUE; |
| 518 | } |