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 Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 25 | #include <chromeos/bind_lambda.h> |
| 26 | #include <chromeos/message_loops/message_loop.h> |
Gilad Arnold | ccd0957 | 2014-10-27 13:37:50 -0700 | [diff] [blame] | 27 | #include <chromeos/strings/string_utils.h> |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 28 | #include <policy/device_policy.h> |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 29 | |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 30 | #include "update_engine/clock_interface.h" |
Alex Deymo | f6ee016 | 2015-07-31 12:35:22 -0700 | [diff] [blame] | 31 | #include "update_engine/connection_manager_interface.h" |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 32 | #include "update_engine/dbus_constants.h" |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 33 | #include "update_engine/hardware_interface.h" |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 34 | #include "update_engine/omaha_request_params.h" |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 35 | #include "update_engine/p2p_manager.h" |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 36 | #include "update_engine/prefs.h" |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 37 | #include "update_engine/update_attempter.h" |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame] | 38 | #include "update_engine/utils.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 Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 41 | using chromeos::ErrorPtr; |
Gilad Arnold | ccd0957 | 2014-10-27 13:37:50 -0700 | [diff] [blame] | 42 | using chromeos::string_utils::ToString; |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 43 | using chromeos_update_engine::AttemptUpdateFlags; |
| 44 | using chromeos_update_engine::kAttemptUpdateFlagNonInteractive; |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 45 | using std::set; |
| 46 | using std::string; |
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) { |
| 53 | chromeos::Error::AddTo( |
| 54 | error, location, |
| 55 | chromeos::errors::dbus::kDomain, |
| 56 | chromeos_update_engine::kUpdateEngineServiceErrorFailed, reason); |
| 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 |
| 153 | // now from the libchromeos 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; |
| 173 | if (!system_state_->request_params()->SetTargetChannel( |
| 174 | in_target_channel, in_is_powerwash_allowed)) { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 175 | // TODO(dgarrett): Give a more specific error code/reason. |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 176 | LogAndSetError(error, FROM_HERE, "Setting channel failed."); |
| 177 | return false; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 178 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 179 | return true; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 182 | bool UpdateEngineService::GetChannel(ErrorPtr* /* error */, |
| 183 | bool in_get_current_channel, |
| 184 | string* out_channel) { |
| 185 | OmahaRequestParams* rp = system_state_->request_params(); |
| 186 | *out_channel = (in_get_current_channel ? |
| 187 | rp->current_channel() : rp->target_channel()); |
| 188 | return true; |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 191 | bool UpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error, |
| 192 | bool in_enabled) { |
| 193 | PrefsInterface* prefs = system_state_->prefs(); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 194 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 195 | if (!prefs->SetBoolean(kPrefsP2PEnabled, in_enabled)) { |
| 196 | LogAndSetError( |
| 197 | error, FROM_HERE, |
Gilad Arnold | ccd0957 | 2014-10-27 13:37:50 -0700 | [diff] [blame] | 198 | StringPrintf("Error setting the update via p2p permission to %s.", |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 199 | ToString(in_enabled).c_str())); |
| 200 | return false; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 201 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 202 | return true; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 205 | bool UpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error, |
| 206 | bool* out_enabled) { |
| 207 | PrefsInterface* prefs = system_state_->prefs(); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 208 | |
Gilad Arnold | 367a3ad | 2014-10-23 16:00:17 -0700 | [diff] [blame] | 209 | bool p2p_pref = false; // Default if no setting is present. |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 210 | if (prefs->Exists(kPrefsP2PEnabled) && |
| 211 | !prefs->GetBoolean(kPrefsP2PEnabled, &p2p_pref)) { |
| 212 | LogAndSetError(error, FROM_HERE, "Error getting the P2PEnabled setting."); |
| 213 | return false; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 216 | *out_enabled = p2p_pref; |
| 217 | return true; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 220 | bool UpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error, |
| 221 | bool in_allowed) { |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 222 | set<string> allowed_types; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 223 | const policy::DevicePolicy* device_policy = system_state_->device_policy(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 224 | |
| 225 | // The device_policy is loaded in a lazy way before an update check. Load it |
| 226 | // now from the libchromeos cache if it wasn't already loaded. |
| 227 | if (!device_policy) { |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 228 | UpdateAttempter* update_attempter = system_state_->update_attempter(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 229 | if (update_attempter) { |
| 230 | update_attempter->RefreshDevicePolicy(); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 231 | device_policy = system_state_->device_policy(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
| 235 | // Check if this setting is allowed by the device policy. |
| 236 | if (device_policy && |
| 237 | device_policy->GetAllowedConnectionTypesForUpdate(&allowed_types)) { |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 238 | LogAndSetError(error, FROM_HERE, |
| 239 | "Ignoring the update over cellular setting since there's " |
| 240 | "a device policy enforcing this setting."); |
| 241 | return false; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | // If the policy wasn't loaded yet, then it is still OK to change the local |
| 245 | // setting because the policy will be checked again during the update check. |
| 246 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 247 | PrefsInterface* prefs = system_state_->prefs(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 248 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 249 | if (!prefs->SetBoolean(kPrefsUpdateOverCellularPermission, in_allowed)) { |
| 250 | LogAndSetError(error, FROM_HERE, |
| 251 | string("Error setting the update over cellular to ") + |
| 252 | (in_allowed ? "true" : "false")); |
| 253 | return false; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 254 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 255 | return true; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 258 | bool UpdateEngineService::GetUpdateOverCellularPermission(ErrorPtr* /* error */, |
| 259 | bool* out_allowed) { |
| 260 | ConnectionManagerInterface* cm = system_state_->connection_manager(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 261 | |
| 262 | // The device_policy is loaded in a lazy way before an update check and is |
| 263 | // used to determine if an update is allowed over cellular. Load the device |
| 264 | // policy now from the libchromeos cache if it wasn't already loaded. |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 265 | if (!system_state_->device_policy()) { |
| 266 | UpdateAttempter* update_attempter = system_state_->update_attempter(); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 267 | if (update_attempter) |
| 268 | update_attempter->RefreshDevicePolicy(); |
| 269 | } |
| 270 | |
| 271 | // Return the current setting based on the same logic used while checking for |
| 272 | // updates. A log message could be printed as the result of this test. |
| 273 | LOG(INFO) << "Checking if updates over cellular networks are allowed:"; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 274 | *out_allowed = cm->IsUpdateAllowedOver( |
Alex Deymo | 75eac7e | 2015-07-29 13:39:14 -0700 | [diff] [blame] | 275 | chromeos_update_engine::NetworkConnectionType::kCellular, |
Alex Deymo | 6ae9120 | 2014-03-10 19:21:25 -0700 | [diff] [blame] | 276 | chromeos_update_engine::NetworkTethering::kUnknown); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 277 | return true; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 280 | bool UpdateEngineService::GetDurationSinceUpdate(ErrorPtr* error, |
| 281 | int64_t* out_usec_wallclock) { |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 282 | base::Time time; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 283 | if (!system_state_->update_attempter()->GetBootTimeAtUpdate(&time)) { |
| 284 | LogAndSetError(error, FROM_HERE, "No pending update."); |
| 285 | return false; |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 286 | } |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 287 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 288 | ClockInterface* clock = system_state_->clock(); |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 289 | *out_usec_wallclock = (clock->GetBootTime() - time).InMicroseconds(); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 290 | return true; |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 293 | bool UpdateEngineService::GetPrevVersion(ErrorPtr* /* error */, |
| 294 | string* out_prev_version) { |
| 295 | *out_prev_version = system_state_->update_attempter()->GetPrevVersion(); |
| 296 | return true; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 297 | } |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 298 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 299 | bool UpdateEngineService::GetKernelDevices(ErrorPtr* /* error */, |
| 300 | string* out_kernel_devices) { |
| 301 | auto devices = system_state_->update_attempter()->GetKernelDevices(); |
| 302 | string info; |
| 303 | for (const auto& device : devices) { |
| 304 | base::StringAppendF(&info, "%d:%s\n", |
| 305 | device.second ? 1 : 0, device.first.c_str()); |
| 306 | } |
| 307 | LOG(INFO) << "Available kernel devices: " << info; |
| 308 | *out_kernel_devices = info; |
| 309 | return true; |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 310 | } |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 311 | |
| 312 | bool UpdateEngineService::GetRollbackPartition( |
| 313 | ErrorPtr* /* error */, |
| 314 | string* out_rollback_partition_name) { |
| 315 | string name = system_state_->update_attempter()->GetRollbackPartition(); |
| 316 | LOG(INFO) << "Getting rollback partition name. Result: " << name; |
| 317 | *out_rollback_partition_name = name; |
| 318 | return true; |
| 319 | } |
| 320 | |
| 321 | |
| 322 | UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state, |
| 323 | const scoped_refptr<dbus::Bus>& bus) |
| 324 | : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_), |
| 325 | bus_(bus), |
| 326 | dbus_service_(system_state), |
| 327 | dbus_object_(nullptr, bus, dbus::ObjectPath(kUpdateEngineServicePath)) {} |
| 328 | |
| 329 | void UpdateEngineAdaptor::RegisterAsync( |
| 330 | const base::Callback<void(bool)>& completion_callback) { |
| 331 | RegisterWithDBusObject(&dbus_object_); |
| 332 | dbus_object_.RegisterAsync(completion_callback); |
| 333 | } |
| 334 | |
| 335 | bool UpdateEngineAdaptor::RequestOwnership() { |
| 336 | return bus_->RequestOwnershipAndBlock(kUpdateEngineServiceName, |
| 337 | dbus::Bus::REQUIRE_PRIMARY); |
| 338 | } |
| 339 | |
| 340 | } // namespace chromeos_update_engine |