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