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> |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 11 | #include <policy/device_policy.h> |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 12 | |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 13 | #include "update_engine/clock_interface.h" |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 14 | #include "update_engine/connection_manager.h" |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 15 | #include "update_engine/dbus_constants.h" |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 16 | #include "update_engine/hardware_interface.h" |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 17 | #include "update_engine/marshal.glibmarshal.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 |
| 103 | update_engine_VOID__INT64_DOUBLE_STRING_STRING_INT64, |
| 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 | |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 196 | gboolean update_engine_service_reset_status(UpdateEngineService* self, |
| 197 | GError **error) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 198 | if (!self->system_state_->update_attempter()->ResetStatus()) { |
| 199 | // TODO(dgarrett): Give a more specific error code/reason. |
| 200 | log_and_set_response_error(error, |
| 201 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 202 | "ResetStatus failed."); |
| 203 | return FALSE; |
| 204 | } |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 205 | |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 206 | return TRUE; |
| 207 | } |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 208 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 209 | gboolean update_engine_service_get_status(UpdateEngineService* self, |
| 210 | int64_t* last_checked_time, |
| 211 | double* progress, |
| 212 | gchar** current_operation, |
| 213 | gchar** new_version, |
| 214 | int64_t* new_size, |
| 215 | GError **error) { |
| 216 | string current_op; |
| 217 | string new_version_str; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 218 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 219 | CHECK(self->system_state_->update_attempter()->GetStatus(last_checked_time, |
| 220 | progress, |
| 221 | ¤t_op, |
| 222 | &new_version_str, |
| 223 | new_size)); |
Satoru Takabayashi | d698231 | 2010-11-29 12:54:12 +0900 | [diff] [blame] | 224 | *current_operation = g_strdup(current_op.c_str()); |
| 225 | *new_version = g_strdup(new_version_str.c_str()); |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 226 | |
| 227 | if (!*current_operation) { |
| 228 | log_and_set_response_error(error, |
| 229 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 230 | "Unable to find current_operation."); |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 231 | return FALSE; |
| 232 | } |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 233 | |
| 234 | if (!*new_version) { |
| 235 | log_and_set_response_error(error, |
| 236 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 237 | "Unable to find vew_version."); |
| 238 | return FALSE; |
| 239 | } |
| 240 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 241 | return TRUE; |
| 242 | } |
| 243 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 244 | gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self, |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 245 | GError **error) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 246 | if (!self->system_state_->update_attempter()->RebootIfNeeded()) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 247 | // TODO(dgarrett): Give a more specific error code/reason. |
| 248 | log_and_set_response_error(error, |
| 249 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 250 | "Reboot not needed, or attempt failed."); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 251 | return FALSE; |
| 252 | } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 253 | return TRUE; |
| 254 | } |
| 255 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 256 | gboolean update_engine_service_set_channel(UpdateEngineService* self, |
| 257 | gchar* target_channel, |
Alex Deymo | ad92373 | 2013-08-29 16:13:49 -0700 | [diff] [blame] | 258 | gboolean is_powerwash_allowed, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 259 | GError **error) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 260 | if (!target_channel) { |
| 261 | log_and_set_response_error(error, |
| 262 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 263 | "Target channel to set not specified."); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 264 | return FALSE; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 265 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 266 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 267 | const policy::DevicePolicy* device_policy = |
| 268 | self->system_state_->device_policy(); |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 269 | |
| 270 | // The device_policy is loaded in a lazy way before an update check. Load it |
| 271 | // now from the libchromeos cache if it wasn't already loaded. |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 272 | if (!device_policy) { |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 273 | chromeos_update_engine::UpdateAttempter* update_attempter = |
| 274 | self->system_state_->update_attempter(); |
| 275 | if (update_attempter) { |
| 276 | update_attempter->RefreshDevicePolicy(); |
| 277 | device_policy = self->system_state_->device_policy(); |
| 278 | } |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 279 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 280 | |
| 281 | bool delegated = false; |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 282 | if (device_policy && |
| 283 | device_policy->GetReleaseChannelDelegated(&delegated) && !delegated) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 284 | log_and_set_response_error( |
| 285 | error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 286 | "Cannot set target channel explicitly when channel " |
| 287 | "policy/settings is not delegated"); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 288 | return FALSE; |
| 289 | } |
| 290 | |
| 291 | LOG(INFO) << "Setting destination channel to: " << target_channel; |
| 292 | if (!self->system_state_->request_params()->SetTargetChannel( |
| 293 | target_channel, is_powerwash_allowed)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 294 | // TODO(dgarrett): Give a more specific error code/reason. |
| 295 | log_and_set_response_error(error, |
| 296 | UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 297 | "Setting channel failed."); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 298 | return FALSE; |
| 299 | } |
| 300 | |
| 301 | return TRUE; |
| 302 | } |
| 303 | |
| 304 | gboolean update_engine_service_get_channel(UpdateEngineService* self, |
Alex Deymo | ad92373 | 2013-08-29 16:13:49 -0700 | [diff] [blame] | 305 | gboolean get_current_channel, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 306 | gchar** channel, |
| 307 | GError **error) { |
| 308 | chromeos_update_engine::OmahaRequestParams* rp = |
| 309 | self->system_state_->request_params(); |
| 310 | |
| 311 | string channel_str = get_current_channel ? |
| 312 | rp->current_channel() : rp->target_channel(); |
| 313 | |
| 314 | *channel = g_strdup(channel_str.c_str()); |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 315 | return TRUE; |
| 316 | } |
| 317 | |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 318 | gboolean update_engine_service_set_p2p_update_permission( |
| 319 | UpdateEngineService* self, |
| 320 | gboolean enabled, |
| 321 | GError **error) { |
| 322 | chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs(); |
| 323 | chromeos_update_engine::P2PManager* p2p_manager = |
| 324 | self->system_state_->p2p_manager(); |
| 325 | |
| 326 | bool p2p_was_enabled = p2p_manager && p2p_manager->IsP2PEnabled(); |
| 327 | |
| 328 | if (!prefs->SetBoolean(chromeos_update_engine::kPrefsP2PEnabled, enabled)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 329 | log_and_set_response_error( |
| 330 | error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 331 | string("Error setting the update over cellular to ") + |
| 332 | (enabled ? "true." : "false.")); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 333 | return FALSE; |
| 334 | } |
| 335 | |
| 336 | // If P2P is being effectively disabled (IsP2PEnabled() reports the change) |
| 337 | // then we need to shutdown the service. |
| 338 | if (p2p_was_enabled && !p2p_manager->IsP2PEnabled()) |
| 339 | p2p_manager->EnsureP2PNotRunning(); |
| 340 | |
| 341 | return TRUE; |
| 342 | } |
| 343 | |
| 344 | gboolean update_engine_service_get_p2p_update_permission( |
| 345 | UpdateEngineService* self, |
| 346 | gboolean* enabled, |
| 347 | GError **error) { |
| 348 | chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs(); |
| 349 | |
| 350 | // The default for not present setting is false. |
| 351 | if (!prefs->Exists(chromeos_update_engine::kPrefsP2PEnabled)) { |
| 352 | *enabled = false; |
| 353 | return TRUE; |
| 354 | } |
| 355 | |
| 356 | bool p2p_pref = false; |
| 357 | if (!prefs->GetBoolean(chromeos_update_engine::kPrefsP2PEnabled, &p2p_pref)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 358 | log_and_set_response_error(error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 359 | "Error getting the P2PEnabled setting."); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 360 | return FALSE; |
| 361 | } |
| 362 | |
| 363 | *enabled = p2p_pref; |
| 364 | return TRUE; |
| 365 | } |
| 366 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 367 | gboolean update_engine_service_set_update_over_cellular_permission( |
| 368 | UpdateEngineService* self, |
Alex Deymo | ad92373 | 2013-08-29 16:13:49 -0700 | [diff] [blame] | 369 | gboolean allowed, |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 370 | GError **error) { |
| 371 | set<string> allowed_types; |
| 372 | const policy::DevicePolicy* device_policy = |
| 373 | self->system_state_->device_policy(); |
| 374 | |
| 375 | // The device_policy is loaded in a lazy way before an update check. Load it |
| 376 | // now from the libchromeos cache if it wasn't already loaded. |
| 377 | if (!device_policy) { |
| 378 | chromeos_update_engine::UpdateAttempter* update_attempter = |
| 379 | self->system_state_->update_attempter(); |
| 380 | if (update_attempter) { |
| 381 | update_attempter->RefreshDevicePolicy(); |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 382 | device_policy = self->system_state_->device_policy(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
| 386 | // Check if this setting is allowed by the device policy. |
| 387 | if (device_policy && |
| 388 | device_policy->GetAllowedConnectionTypesForUpdate(&allowed_types)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 389 | log_and_set_response_error( |
| 390 | error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 391 | "Ignoring the update over cellular setting since there's " |
| 392 | "a device policy enforcing this setting."); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 393 | return FALSE; |
| 394 | } |
| 395 | |
| 396 | // If the policy wasn't loaded yet, then it is still OK to change the local |
| 397 | // setting because the policy will be checked again during the update check. |
| 398 | |
| 399 | chromeos_update_engine::PrefsInterface* prefs = self->system_state_->prefs(); |
| 400 | |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 401 | if (!prefs->SetBoolean( |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 402 | chromeos_update_engine::kPrefsUpdateOverCellularPermission, |
Alex Deymo | efb7c4c | 2013-07-09 14:34:00 -0700 | [diff] [blame] | 403 | allowed)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 404 | log_and_set_response_error( |
| 405 | error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 406 | string("Error setting the update over cellular to ") + |
| 407 | (allowed ? "true" : "false")); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 408 | return FALSE; |
| 409 | } |
| 410 | |
| 411 | return TRUE; |
| 412 | } |
| 413 | |
| 414 | gboolean update_engine_service_get_update_over_cellular_permission( |
| 415 | UpdateEngineService* self, |
Alex Deymo | ad92373 | 2013-08-29 16:13:49 -0700 | [diff] [blame] | 416 | gboolean* allowed, |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 417 | GError **error) { |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 418 | chromeos_update_engine::ConnectionManager* cm = |
| 419 | self->system_state_->connection_manager(); |
| 420 | |
| 421 | // The device_policy is loaded in a lazy way before an update check and is |
| 422 | // used to determine if an update is allowed over cellular. Load the device |
| 423 | // policy now from the libchromeos cache if it wasn't already loaded. |
| 424 | if (!self->system_state_->device_policy()) { |
| 425 | chromeos_update_engine::UpdateAttempter* update_attempter = |
| 426 | self->system_state_->update_attempter(); |
| 427 | if (update_attempter) |
| 428 | update_attempter->RefreshDevicePolicy(); |
| 429 | } |
| 430 | |
| 431 | // Return the current setting based on the same logic used while checking for |
| 432 | // updates. A log message could be printed as the result of this test. |
| 433 | LOG(INFO) << "Checking if updates over cellular networks are allowed:"; |
| 434 | *allowed = cm->IsUpdateAllowedOver(chromeos_update_engine::kNetCellular); |
| 435 | |
| 436 | return TRUE; |
| 437 | } |
| 438 | |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 439 | gboolean update_engine_service_get_duration_since_update( |
| 440 | UpdateEngineService* self, |
| 441 | gint64* out_usec_wallclock, |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 442 | GError **error) { |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 443 | |
| 444 | base::Time time; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 445 | if (!self->system_state_->update_attempter()->GetBootTimeAtUpdate(&time)) { |
| 446 | log_and_set_response_error(error, UPDATE_ENGINE_SERVICE_ERROR_FAILED, |
| 447 | "No pending update."); |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 448 | return FALSE; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame^] | 449 | } |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 450 | |
| 451 | chromeos_update_engine::ClockInterface *clock = self->system_state_->clock(); |
| 452 | *out_usec_wallclock = (clock->GetBootTime() - time).InMicroseconds(); |
| 453 | return TRUE; |
| 454 | } |
| 455 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 456 | gboolean update_engine_service_emit_status_update( |
| 457 | UpdateEngineService* self, |
| 458 | gint64 last_checked_time, |
| 459 | gdouble progress, |
| 460 | const gchar* current_operation, |
| 461 | const gchar* new_version, |
| 462 | gint64 new_size) { |
| 463 | g_signal_emit(self, |
| 464 | status_update_signal, |
| 465 | 0, |
| 466 | last_checked_time, |
| 467 | progress, |
| 468 | current_operation, |
| 469 | new_version, |
| 470 | new_size); |
| 471 | return TRUE; |
| 472 | } |