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