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