blob: 7314a1da00baf24b16adf600b84ca448964c6ae4 [file] [log] [blame]
Alex Deymo5e3ea272016-01-28 13:42:23 -08001//
2// Copyright (C) 2016 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//
16
17#include "update_engine/update_attempter_android.h"
18
19#include <algorithm>
Alex Deymo218397f2016-02-04 23:55:10 -080020#include <map>
Alex Deymo5e3ea272016-01-28 13:42:23 -080021#include <utility>
22
23#include <base/bind.h>
24#include <base/logging.h>
Alex Deymo218397f2016-02-04 23:55:10 -080025#include <base/strings/string_number_conversions.h>
Alex Deymo5e3ea272016-01-28 13:42:23 -080026#include <brillo/bind_lambda.h>
27#include <brillo/message_loops/message_loop.h>
Alex Deymo218397f2016-02-04 23:55:10 -080028#include <brillo/strings/string_utils.h>
Alex Deymo5e3ea272016-01-28 13:42:23 -080029
30#include "update_engine/common/constants.h"
Alex Deymo2c131bb2016-05-26 16:43:13 -070031#include "update_engine/common/file_fetcher.h"
Alex Deymo5e3ea272016-01-28 13:42:23 -080032#include "update_engine/common/libcurl_http_fetcher.h"
33#include "update_engine/common/multi_range_http_fetcher.h"
34#include "update_engine/common/utils.h"
35#include "update_engine/daemon_state_android.h"
36#include "update_engine/payload_consumer/download_action.h"
37#include "update_engine/payload_consumer/filesystem_verifier_action.h"
38#include "update_engine/payload_consumer/postinstall_runner_action.h"
Alex Deymo3b678db2016-02-09 11:50:06 -080039#include "update_engine/update_status_utils.h"
Alex Deymo5e3ea272016-01-28 13:42:23 -080040
41using base::Bind;
42using base::TimeDelta;
43using base::TimeTicks;
44using std::shared_ptr;
45using std::string;
46using std::vector;
47
48namespace chromeos_update_engine {
49
50namespace {
51
Alex Deymo0d298542016-03-30 18:31:49 -070052// Minimum threshold to broadcast an status update in progress and time.
53const double kBroadcastThresholdProgress = 0.01; // 1%
54const int kBroadcastThresholdSeconds = 10;
55
Alex Deymo5e3ea272016-01-28 13:42:23 -080056const char* const kErrorDomain = "update_engine";
57// TODO(deymo): Convert the different errors to a numeric value to report them
58// back on the service error.
59const char* const kGenericError = "generic_error";
60
61// Log and set the error on the passed ErrorPtr.
62bool LogAndSetError(brillo::ErrorPtr* error,
63 const tracked_objects::Location& location,
64 const string& reason) {
65 brillo::Error::AddTo(error, location, kErrorDomain, kGenericError, reason);
66 LOG(ERROR) << "Replying with failure: " << location.ToString() << ": "
67 << reason;
68 return false;
69}
70
71} // namespace
72
73UpdateAttempterAndroid::UpdateAttempterAndroid(
74 DaemonStateAndroid* daemon_state,
75 PrefsInterface* prefs,
76 BootControlInterface* boot_control,
77 HardwareInterface* hardware)
78 : daemon_state_(daemon_state),
79 prefs_(prefs),
80 boot_control_(boot_control),
81 hardware_(hardware),
82 processor_(new ActionProcessor()) {
83}
84
85UpdateAttempterAndroid::~UpdateAttempterAndroid() {
86 // Release ourselves as the ActionProcessor's delegate to prevent
87 // re-scheduling the updates due to the processing stopped.
88 processor_->set_delegate(nullptr);
89}
90
91void UpdateAttempterAndroid::Init() {
92 // In case of update_engine restart without a reboot we need to restore the
93 // reboot needed state.
94 if (UpdateCompletedOnThisBoot())
Alex Deymo0e061ae2016-02-09 17:49:03 -080095 SetStatusAndNotify(UpdateStatus::UPDATED_NEED_REBOOT);
Alex Deymo5e3ea272016-01-28 13:42:23 -080096 else
Alex Deymo0e061ae2016-02-09 17:49:03 -080097 SetStatusAndNotify(UpdateStatus::IDLE);
Alex Deymo5e3ea272016-01-28 13:42:23 -080098}
99
100bool UpdateAttempterAndroid::ApplyPayload(
101 const string& payload_url,
102 int64_t payload_offset,
103 int64_t payload_size,
104 const vector<string>& key_value_pair_headers,
105 brillo::ErrorPtr* error) {
106 if (status_ == UpdateStatus::UPDATED_NEED_REBOOT) {
107 return LogAndSetError(
108 error, FROM_HERE, "An update already applied, waiting for reboot");
109 }
110 if (ongoing_update_) {
111 return LogAndSetError(
112 error, FROM_HERE, "Already processing an update, cancel it first.");
113 }
114 DCHECK(status_ == UpdateStatus::IDLE);
115
Alex Deymo218397f2016-02-04 23:55:10 -0800116 std::map<string, string> headers;
117 for (const string& key_value_pair : key_value_pair_headers) {
118 string key;
119 string value;
120 if (!brillo::string_utils::SplitAtFirst(
121 key_value_pair, "=", &key, &value, false)) {
122 return LogAndSetError(
123 error, FROM_HERE, "Passed invalid header: " + key_value_pair);
124 }
125 if (!headers.emplace(key, value).second)
126 return LogAndSetError(error, FROM_HERE, "Passed repeated key: " + key);
127 }
128
129 // Unique identifier for the payload. An empty string means that the payload
130 // can't be resumed.
131 string payload_id = (headers[kPayloadPropertyFileHash] +
132 headers[kPayloadPropertyMetadataHash]);
Alex Deymo5e3ea272016-01-28 13:42:23 -0800133
134 // Setup the InstallPlan based on the request.
135 install_plan_ = InstallPlan();
136
137 install_plan_.download_url = payload_url;
138 install_plan_.version = "";
Alex Deymo0fd51ff2016-02-03 14:22:43 -0800139 base_offset_ = payload_offset;
Alex Deymo218397f2016-02-04 23:55:10 -0800140 install_plan_.payload_size = payload_size;
141 if (!install_plan_.payload_size) {
142 if (!base::StringToUint64(headers[kPayloadPropertyFileSize],
143 &install_plan_.payload_size)) {
144 install_plan_.payload_size = 0;
145 }
146 }
147 install_plan_.payload_hash = headers[kPayloadPropertyFileHash];
148 if (!base::StringToUint64(headers[kPayloadPropertyMetadataSize],
149 &install_plan_.metadata_size)) {
150 install_plan_.metadata_size = 0;
151 }
Alex Deymo5e3ea272016-01-28 13:42:23 -0800152 install_plan_.metadata_signature = "";
153 // The |public_key_rsa| key would override the public key stored on disk.
154 install_plan_.public_key_rsa = "";
155
156 install_plan_.hash_checks_mandatory = hardware_->IsOfficialBuild();
157 install_plan_.is_resume = !payload_id.empty() &&
158 DeltaPerformer::CanResumeUpdate(prefs_, payload_id);
159 if (!install_plan_.is_resume) {
160 if (!DeltaPerformer::ResetUpdateProgress(prefs_, false)) {
161 LOG(WARNING) << "Unable to reset the update progress.";
162 }
163 if (!prefs_->SetString(kPrefsUpdateCheckResponseHash, payload_id)) {
164 LOG(WARNING) << "Unable to save the update check response hash.";
165 }
166 }
Alex Deymo64d98782016-02-05 18:03:48 -0800167 // The |payload_type| is not used anymore since minor_version 3.
168 install_plan_.payload_type = InstallPayloadType::kUnknown;
Alex Deymo5e3ea272016-01-28 13:42:23 -0800169
170 install_plan_.source_slot = boot_control_->GetCurrentSlot();
171 install_plan_.target_slot = install_plan_.source_slot == 0 ? 1 : 0;
Alex Deymofb905d92016-06-03 19:26:58 -0700172
173 int data_wipe = 0;
174 install_plan_.powerwash_required =
175 base::StringToInt(headers[kPayloadPropertyPowerwash], &data_wipe) &&
176 data_wipe != 0;
Alex Deymo5e3ea272016-01-28 13:42:23 -0800177
178 LOG(INFO) << "Using this install plan:";
179 install_plan_.Dump();
180
Alex Deymo2c131bb2016-05-26 16:43:13 -0700181 BuildUpdateActions(payload_url);
Alex Deymo5e3ea272016-01-28 13:42:23 -0800182 SetupDownload();
Alex Deymofdd6dec2016-03-03 22:35:43 -0800183 // Setup extra headers.
184 HttpFetcher* fetcher = download_action_->http_fetcher();
185 if (!headers[kPayloadPropertyAuthorization].empty())
186 fetcher->SetHeader("Authorization", headers[kPayloadPropertyAuthorization]);
187 if (!headers[kPayloadPropertyUserAgent].empty())
188 fetcher->SetHeader("User-Agent", headers[kPayloadPropertyUserAgent]);
189
Alex Deymo5e3ea272016-01-28 13:42:23 -0800190 cpu_limiter_.StartLimiter();
191 SetStatusAndNotify(UpdateStatus::UPDATE_AVAILABLE);
Alex Deymof2858572016-02-25 11:20:13 -0800192 ongoing_update_ = true;
Alex Deymo5e3ea272016-01-28 13:42:23 -0800193
194 // Just in case we didn't update boot flags yet, make sure they're updated
195 // before any update processing starts. This will start the update process.
196 UpdateBootFlags();
197 return true;
198}
199
200bool UpdateAttempterAndroid::SuspendUpdate(brillo::ErrorPtr* error) {
Alex Deymof2858572016-02-25 11:20:13 -0800201 if (!ongoing_update_)
202 return LogAndSetError(error, FROM_HERE, "No ongoing update to suspend.");
203 processor_->SuspendProcessing();
204 return true;
Alex Deymo5e3ea272016-01-28 13:42:23 -0800205}
206
207bool UpdateAttempterAndroid::ResumeUpdate(brillo::ErrorPtr* error) {
Alex Deymof2858572016-02-25 11:20:13 -0800208 if (!ongoing_update_)
209 return LogAndSetError(error, FROM_HERE, "No ongoing update to resume.");
210 processor_->ResumeProcessing();
211 return true;
Alex Deymo5e3ea272016-01-28 13:42:23 -0800212}
213
214bool UpdateAttempterAndroid::CancelUpdate(brillo::ErrorPtr* error) {
Alex Deymof2858572016-02-25 11:20:13 -0800215 if (!ongoing_update_)
Alex Deymo5e3ea272016-01-28 13:42:23 -0800216 return LogAndSetError(error, FROM_HERE, "No ongoing update to cancel.");
Alex Deymof2858572016-02-25 11:20:13 -0800217 processor_->StopProcessing();
218 return true;
Alex Deymo5e3ea272016-01-28 13:42:23 -0800219}
220
Alex Deymo3b678db2016-02-09 11:50:06 -0800221bool UpdateAttempterAndroid::ResetStatus(brillo::ErrorPtr* error) {
222 LOG(INFO) << "Attempting to reset state from "
223 << UpdateStatusToString(status_) << " to UpdateStatus::IDLE";
224
225 switch (status_) {
226 case UpdateStatus::IDLE:
227 return true;
228
229 case UpdateStatus::UPDATED_NEED_REBOOT: {
230 // Remove the reboot marker so that if the machine is rebooted
231 // after resetting to idle state, it doesn't go back to
232 // UpdateStatus::UPDATED_NEED_REBOOT state.
233 bool ret_value = prefs_->Delete(kPrefsUpdateCompletedOnBootId);
234
235 // Update the boot flags so the current slot has higher priority.
236 if (!boot_control_->SetActiveBootSlot(boot_control_->GetCurrentSlot()))
237 ret_value = false;
238
239 if (!ret_value) {
240 return LogAndSetError(
241 error,
242 FROM_HERE,
243 "Failed to reset the status to ");
244 }
245
246 SetStatusAndNotify(UpdateStatus::IDLE);
247 LOG(INFO) << "Reset status successful";
248 return true;
249 }
250
251 default:
252 return LogAndSetError(
253 error,
254 FROM_HERE,
255 "Reset not allowed in this state. Cancel the ongoing update first");
256 }
257}
258
Alex Deymo5e3ea272016-01-28 13:42:23 -0800259void UpdateAttempterAndroid::ProcessingDone(const ActionProcessor* processor,
260 ErrorCode code) {
261 LOG(INFO) << "Processing Done.";
262
263 if (code == ErrorCode::kSuccess) {
264 // Update succeeded.
265 WriteUpdateCompletedMarker();
266 prefs_->SetInt64(kPrefsDeltaUpdateFailures, 0);
267 DeltaPerformer::ResetUpdateProgress(prefs_, false);
268
269 LOG(INFO) << "Update successfully applied, waiting to reboot.";
270 }
271
272 TerminateUpdateAndNotify(code);
273}
274
275void UpdateAttempterAndroid::ProcessingStopped(
276 const ActionProcessor* processor) {
277 TerminateUpdateAndNotify(ErrorCode::kUserCanceled);
278}
279
280void UpdateAttempterAndroid::ActionCompleted(ActionProcessor* processor,
281 AbstractAction* action,
282 ErrorCode code) {
283 // Reset download progress regardless of whether or not the download
284 // action succeeded.
285 const string type = action->Type();
286 if (type == DownloadAction::StaticType()) {
Alex Deymo0d298542016-03-30 18:31:49 -0700287 download_progress_ = 0;
Alex Deymo5e3ea272016-01-28 13:42:23 -0800288 }
289 if (code != ErrorCode::kSuccess) {
290 // If an action failed, the ActionProcessor will cancel the whole thing.
291 return;
292 }
293 if (type == DownloadAction::StaticType()) {
294 SetStatusAndNotify(UpdateStatus::FINALIZING);
295 }
296}
297
298void UpdateAttempterAndroid::BytesReceived(uint64_t bytes_progressed,
299 uint64_t bytes_received,
300 uint64_t total) {
Alex Deymo0d298542016-03-30 18:31:49 -0700301 double progress = 0;
Alex Deymo5e3ea272016-01-28 13:42:23 -0800302 if (total)
303 progress = static_cast<double>(bytes_received) / static_cast<double>(total);
Alex Deymo0d298542016-03-30 18:31:49 -0700304 if (status_ != UpdateStatus::DOWNLOADING || bytes_received == total) {
Alex Deymo5e3ea272016-01-28 13:42:23 -0800305 download_progress_ = progress;
306 SetStatusAndNotify(UpdateStatus::DOWNLOADING);
Alex Deymo0d298542016-03-30 18:31:49 -0700307 } else {
308 ProgressUpdate(progress);
Alex Deymo5e3ea272016-01-28 13:42:23 -0800309 }
310}
311
312bool UpdateAttempterAndroid::ShouldCancel(ErrorCode* cancel_reason) {
313 // TODO(deymo): Notify the DownloadAction that it should cancel the update
314 // download.
315 return false;
316}
317
318void UpdateAttempterAndroid::DownloadComplete() {
319 // Nothing needs to be done when the download completes.
320}
321
Alex Deymo0d298542016-03-30 18:31:49 -0700322void UpdateAttempterAndroid::ProgressUpdate(double progress) {
323 // Self throttle based on progress. Also send notifications if progress is
324 // too slow.
325 if (progress == 1.0 ||
326 progress - download_progress_ >= kBroadcastThresholdProgress ||
327 TimeTicks::Now() - last_notify_time_ >=
328 TimeDelta::FromSeconds(kBroadcastThresholdSeconds)) {
329 download_progress_ = progress;
330 SetStatusAndNotify(status_);
331 }
332}
333
Alex Deymo5e3ea272016-01-28 13:42:23 -0800334void UpdateAttempterAndroid::UpdateBootFlags() {
335 if (updated_boot_flags_) {
336 LOG(INFO) << "Already updated boot flags. Skipping.";
337 CompleteUpdateBootFlags(true);
338 return;
339 }
340 // This is purely best effort.
341 LOG(INFO) << "Marking booted slot as good.";
342 if (!boot_control_->MarkBootSuccessfulAsync(
343 Bind(&UpdateAttempterAndroid::CompleteUpdateBootFlags,
344 base::Unretained(this)))) {
345 LOG(ERROR) << "Failed to mark current boot as successful.";
346 CompleteUpdateBootFlags(false);
347 }
348}
349
350void UpdateAttempterAndroid::CompleteUpdateBootFlags(bool successful) {
351 updated_boot_flags_ = true;
352 ScheduleProcessingStart();
353}
354
355void UpdateAttempterAndroid::ScheduleProcessingStart() {
356 LOG(INFO) << "Scheduling an action processor start.";
357 brillo::MessageLoop::current()->PostTask(
358 FROM_HERE, Bind([this] { this->processor_->StartProcessing(); }));
359}
360
361void UpdateAttempterAndroid::TerminateUpdateAndNotify(ErrorCode error_code) {
362 if (status_ == UpdateStatus::IDLE) {
363 LOG(ERROR) << "No ongoing update, but TerminatedUpdate() called.";
364 return;
365 }
366
367 // Reset cpu shares back to normal.
368 cpu_limiter_.StopLimiter();
Alex Deymo0d298542016-03-30 18:31:49 -0700369 download_progress_ = 0;
Alex Deymo5e3ea272016-01-28 13:42:23 -0800370 actions_.clear();
371 UpdateStatus new_status =
372 (error_code == ErrorCode::kSuccess ? UpdateStatus::UPDATED_NEED_REBOOT
373 : UpdateStatus::IDLE);
374 SetStatusAndNotify(new_status);
375 ongoing_update_ = false;
376
377 for (auto observer : daemon_state_->service_observers())
378 observer->SendPayloadApplicationComplete(error_code);
379}
380
381void UpdateAttempterAndroid::SetStatusAndNotify(UpdateStatus status) {
382 status_ = status;
383 for (auto observer : daemon_state_->service_observers()) {
384 observer->SendStatusUpdate(
385 0, download_progress_, status_, "", install_plan_.payload_size);
386 }
387 last_notify_time_ = TimeTicks::Now();
388}
389
Alex Deymo2c131bb2016-05-26 16:43:13 -0700390void UpdateAttempterAndroid::BuildUpdateActions(const string& url) {
Alex Deymo5e3ea272016-01-28 13:42:23 -0800391 CHECK(!processor_->IsRunning());
392 processor_->set_delegate(this);
393
394 // Actions:
395 shared_ptr<InstallPlanAction> install_plan_action(
396 new InstallPlanAction(install_plan_));
397
Alex Deymo2c131bb2016-05-26 16:43:13 -0700398 HttpFetcher* download_fetcher = nullptr;
399 if (FileFetcher::SupportedUrl(url)) {
400 DLOG(INFO) << "Using FileFetcher for file URL.";
401 download_fetcher = new FileFetcher();
402 } else {
403 LibcurlHttpFetcher* libcurl_fetcher =
404 new LibcurlHttpFetcher(&proxy_resolver_, hardware_);
405 libcurl_fetcher->set_server_to_check(ServerToCheck::kDownload);
406 download_fetcher = libcurl_fetcher;
407 }
Alex Deymo5e3ea272016-01-28 13:42:23 -0800408 shared_ptr<DownloadAction> download_action(new DownloadAction(
409 prefs_,
410 boot_control_,
411 hardware_,
412 nullptr, // system_state, not used.
413 new MultiRangeHttpFetcher(download_fetcher))); // passes ownership
Sen Jiangfef85fd2016-03-25 15:32:49 -0700414 shared_ptr<FilesystemVerifierAction> filesystem_verifier_action(
Sen Jiange6e4bb92016-04-05 14:59:12 -0700415 new FilesystemVerifierAction());
Alex Deymo5e3ea272016-01-28 13:42:23 -0800416
417 shared_ptr<PostinstallRunnerAction> postinstall_runner_action(
Alex Deymofb905d92016-06-03 19:26:58 -0700418 new PostinstallRunnerAction(boot_control_, hardware_));
Alex Deymo5e3ea272016-01-28 13:42:23 -0800419
420 download_action->set_delegate(this);
421 download_action_ = download_action;
Alex Deymob6eef732016-06-10 12:58:11 -0700422 postinstall_runner_action->set_delegate(this);
Alex Deymo5e3ea272016-01-28 13:42:23 -0800423
424 actions_.push_back(shared_ptr<AbstractAction>(install_plan_action));
425 actions_.push_back(shared_ptr<AbstractAction>(download_action));
Sen Jiangfef85fd2016-03-25 15:32:49 -0700426 actions_.push_back(shared_ptr<AbstractAction>(filesystem_verifier_action));
Alex Deymo5e3ea272016-01-28 13:42:23 -0800427 actions_.push_back(shared_ptr<AbstractAction>(postinstall_runner_action));
428
429 // Bond them together. We have to use the leaf-types when calling
430 // BondActions().
431 BondActions(install_plan_action.get(), download_action.get());
Sen Jiangfef85fd2016-03-25 15:32:49 -0700432 BondActions(download_action.get(), filesystem_verifier_action.get());
433 BondActions(filesystem_verifier_action.get(),
Alex Deymo5e3ea272016-01-28 13:42:23 -0800434 postinstall_runner_action.get());
435
436 // Enqueue the actions.
437 for (const shared_ptr<AbstractAction>& action : actions_)
438 processor_->EnqueueAction(action.get());
439}
440
441void UpdateAttempterAndroid::SetupDownload() {
442 MultiRangeHttpFetcher* fetcher =
443 static_cast<MultiRangeHttpFetcher*>(download_action_->http_fetcher());
444 fetcher->ClearRanges();
445 if (install_plan_.is_resume) {
446 // Resuming an update so fetch the update manifest metadata first.
447 int64_t manifest_metadata_size = 0;
Alex Deymof25eb492016-02-26 00:20:08 -0800448 int64_t manifest_signature_size = 0;
Alex Deymo5e3ea272016-01-28 13:42:23 -0800449 prefs_->GetInt64(kPrefsManifestMetadataSize, &manifest_metadata_size);
Alex Deymof25eb492016-02-26 00:20:08 -0800450 prefs_->GetInt64(kPrefsManifestSignatureSize, &manifest_signature_size);
451 fetcher->AddRange(base_offset_,
452 manifest_metadata_size + manifest_signature_size);
Alex Deymo5e3ea272016-01-28 13:42:23 -0800453 // If there're remaining unprocessed data blobs, fetch them. Be careful not
454 // to request data beyond the end of the payload to avoid 416 HTTP response
455 // error codes.
456 int64_t next_data_offset = 0;
457 prefs_->GetInt64(kPrefsUpdateStateNextDataOffset, &next_data_offset);
Alex Deymof25eb492016-02-26 00:20:08 -0800458 uint64_t resume_offset =
459 manifest_metadata_size + manifest_signature_size + next_data_offset;
Alex Deymo0fd51ff2016-02-03 14:22:43 -0800460 if (!install_plan_.payload_size) {
461 fetcher->AddRange(base_offset_ + resume_offset);
462 } else if (resume_offset < install_plan_.payload_size) {
463 fetcher->AddRange(base_offset_ + resume_offset,
464 install_plan_.payload_size - resume_offset);
Alex Deymo5e3ea272016-01-28 13:42:23 -0800465 }
466 } else {
Alex Deymo0fd51ff2016-02-03 14:22:43 -0800467 if (install_plan_.payload_size) {
468 fetcher->AddRange(base_offset_, install_plan_.payload_size);
469 } else {
470 // If no payload size is passed we assume we read until the end of the
471 // stream.
472 fetcher->AddRange(base_offset_);
473 }
Alex Deymo5e3ea272016-01-28 13:42:23 -0800474 }
475}
476
477bool UpdateAttempterAndroid::WriteUpdateCompletedMarker() {
478 string boot_id;
479 TEST_AND_RETURN_FALSE(utils::GetBootId(&boot_id));
480 prefs_->SetString(kPrefsUpdateCompletedOnBootId, boot_id);
481 return true;
482}
483
484bool UpdateAttempterAndroid::UpdateCompletedOnThisBoot() {
485 // In case of an update_engine restart without a reboot, we stored the boot_id
486 // when the update was completed by setting a pref, so we can check whether
487 // the last update was on this boot or a previous one.
488 string boot_id;
489 TEST_AND_RETURN_FALSE(utils::GetBootId(&boot_id));
490
491 string update_completed_on_boot_id;
492 return (prefs_->Exists(kPrefsUpdateCompletedOnBootId) &&
493 prefs_->GetString(kPrefsUpdateCompletedOnBootId,
494 &update_completed_on_boot_id) &&
495 update_completed_on_boot_id == boot_id);
496}
497
498} // namespace chromeos_update_engine