blob: 68954f6fec7cfade4e0f2b768fb4bd65d02f3c77 [file] [log] [blame]
Yifan Hongdad0af82020-02-19 17:19:49 -08001//
2// Copyright (C) 2020 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//
Amin Hassaniec7bc112020-10-29 16:47:58 -070016#include "update_engine/aosp/cleanup_previous_update_action.h"
Yifan Hongdad0af82020-02-19 17:19:49 -080017
Yifan Hongd976cc52020-02-25 14:51:42 -080018#include <chrono> // NOLINT(build/c++11) -- for merge times
Yifan Hongdad0af82020-02-19 17:19:49 -080019#include <functional>
20#include <string>
Yifan Hong24031712020-03-19 19:25:38 -070021#include <type_traits>
Yifan Hongdad0af82020-02-19 17:19:49 -080022
David Anderson0c37f622021-03-11 18:40:25 -080023#include <android-base/chrono_utils.h>
Yifan Hongdad0af82020-02-19 17:19:49 -080024#include <android-base/properties.h>
25#include <base/bind.h>
26
Yifan Hongd976cc52020-02-25 14:51:42 -080027#ifndef __ANDROID_RECOVERY__
28#include <statslog.h>
29#endif
30
Yifan Hongdad0af82020-02-19 17:19:49 -080031#include "update_engine/common/utils.h"
32#include "update_engine/payload_consumer/delta_performer.h"
33
Howard Chen224aed92020-04-17 11:22:13 +080034using android::base::GetBoolProperty;
Yifan Hongf9cb4492020-04-15 13:00:20 -070035using android::snapshot::ISnapshotManager;
Yifan Hongd976cc52020-02-25 14:51:42 -080036using android::snapshot::SnapshotMergeStats;
Yifan Hongdad0af82020-02-19 17:19:49 -080037using android::snapshot::UpdateState;
38using brillo::MessageLoop;
39
40constexpr char kBootCompletedProp[] = "sys.boot_completed";
41// Interval to check sys.boot_completed.
42constexpr auto kCheckBootCompletedInterval = base::TimeDelta::FromSeconds(2);
43// Interval to check IBootControl::isSlotMarkedSuccessful
44constexpr auto kCheckSlotMarkedSuccessfulInterval =
45 base::TimeDelta::FromSeconds(2);
46// Interval to call SnapshotManager::ProcessUpdateState
47constexpr auto kWaitForMergeInterval = base::TimeDelta::FromSeconds(2);
48
Yifan Hong5cd63fa2020-03-16 12:31:16 -070049#ifdef __ANDROID_RECOVERY__
50static constexpr bool kIsRecovery = true;
51#else
52static constexpr bool kIsRecovery = false;
53#endif
54
Yifan Hongdad0af82020-02-19 17:19:49 -080055namespace chromeos_update_engine {
56
57CleanupPreviousUpdateAction::CleanupPreviousUpdateAction(
58 PrefsInterface* prefs,
59 BootControlInterface* boot_control,
Yifan Hongf9cb4492020-04-15 13:00:20 -070060 android::snapshot::ISnapshotManager* snapshot,
Yifan Hongdad0af82020-02-19 17:19:49 -080061 CleanupPreviousUpdateActionDelegateInterface* delegate)
62 : prefs_(prefs),
63 boot_control_(boot_control),
64 snapshot_(snapshot),
65 delegate_(delegate),
66 running_(false),
67 cancel_failed_(false),
Yifan Hongd976cc52020-02-25 14:51:42 -080068 last_percentage_(0),
Yifan Hongf9cb4492020-04-15 13:00:20 -070069 merge_stats_(nullptr) {}
Yifan Hongdad0af82020-02-19 17:19:49 -080070
Yifan Hongd1d52a02020-09-25 15:09:07 -070071CleanupPreviousUpdateAction::~CleanupPreviousUpdateAction() {
72 StopActionInternal();
73}
74
Yifan Hongdad0af82020-02-19 17:19:49 -080075void CleanupPreviousUpdateAction::PerformAction() {
Yifan Hongd506dee2020-09-25 15:08:19 -070076 StartActionInternal();
Yifan Hongdad0af82020-02-19 17:19:49 -080077}
78
79void CleanupPreviousUpdateAction::TerminateProcessing() {
Yifan Hongd506dee2020-09-25 15:08:19 -070080 StopActionInternal();
Yifan Hongdad0af82020-02-19 17:19:49 -080081}
82
83void CleanupPreviousUpdateAction::ResumeAction() {
Yifan Hongdad0af82020-02-19 17:19:49 -080084 StartActionInternal();
85}
86
87void CleanupPreviousUpdateAction::SuspendAction() {
Yifan Hongd506dee2020-09-25 15:08:19 -070088 StopActionInternal();
Yifan Hongdad0af82020-02-19 17:19:49 -080089}
90
91void CleanupPreviousUpdateAction::ActionCompleted(ErrorCode error_code) {
Yifan Hongd506dee2020-09-25 15:08:19 -070092 StopActionInternal();
Yifan Hongd976cc52020-02-25 14:51:42 -080093 ReportMergeStats();
Yifan Hong5cd63fa2020-03-16 12:31:16 -070094 metadata_device_ = nullptr;
Yifan Hongdad0af82020-02-19 17:19:49 -080095}
96
97std::string CleanupPreviousUpdateAction::Type() const {
98 return StaticType();
99}
100
101std::string CleanupPreviousUpdateAction::StaticType() {
102 return "CleanupPreviousUpdateAction";
103}
104
Yifan Hongd1d52a02020-09-25 15:09:07 -0700105// This function is called at the beginning of all delayed functions. By
106// resetting |scheduled_task_|, the delayed function acknowledges that the task
107// has already been executed, therefore there's no need to cancel it in the
108// future. This avoids StopActionInternal() from resetting task IDs in an
109// unexpected way because task IDs could be reused.
110void CleanupPreviousUpdateAction::AcknowledgeTaskExecuted() {
111 if (scheduled_task_ != MessageLoop::kTaskIdNull) {
112 LOG(INFO) << "Executing task " << scheduled_task_;
113 }
114 scheduled_task_ = MessageLoop::kTaskIdNull;
115}
116
117// Check that scheduled_task_ is a valid task ID. Otherwise, terminate the
118// action.
119void CleanupPreviousUpdateAction::CheckTaskScheduled(std::string_view name) {
120 if (scheduled_task_ == MessageLoop::kTaskIdNull) {
121 LOG(ERROR) << "Unable to schedule " << name;
122 processor_->ActionComplete(this, ErrorCode::kError);
123 } else {
124 LOG(INFO) << "CleanupPreviousUpdateAction scheduled task ID "
125 << scheduled_task_ << " for " << name;
126 }
127}
128
Yifan Hongd506dee2020-09-25 15:08:19 -0700129void CleanupPreviousUpdateAction::StopActionInternal() {
130 LOG(INFO) << "Stopping/suspending/completing CleanupPreviousUpdateAction";
131 running_ = false;
Yifan Hongd1d52a02020-09-25 15:09:07 -0700132
133 if (scheduled_task_ != MessageLoop::kTaskIdNull) {
134 if (MessageLoop::current()->CancelTask(scheduled_task_)) {
135 LOG(INFO) << "CleanupPreviousUpdateAction cancelled pending task ID "
136 << scheduled_task_;
137 } else {
138 LOG(ERROR) << "CleanupPreviousUpdateAction unable to cancel task ID "
139 << scheduled_task_;
140 }
141 }
142 scheduled_task_ = MessageLoop::kTaskIdNull;
Yifan Hongd506dee2020-09-25 15:08:19 -0700143}
144
Yifan Hongdad0af82020-02-19 17:19:49 -0800145void CleanupPreviousUpdateAction::StartActionInternal() {
Yifan Hongd506dee2020-09-25 15:08:19 -0700146 CHECK(prefs_);
147 CHECK(boot_control_);
148
149 LOG(INFO) << "Starting/resuming CleanupPreviousUpdateAction";
150 running_ = true;
Yifan Hongdad0af82020-02-19 17:19:49 -0800151 // Do nothing on non-VAB device.
152 if (!boot_control_->GetDynamicPartitionControl()
153 ->GetVirtualAbFeatureFlag()
154 .IsEnabled()) {
155 processor_->ActionComplete(this, ErrorCode::kSuccess);
156 return;
157 }
Yifan Hongf9cb4492020-04-15 13:00:20 -0700158 // SnapshotManager must be available on VAB devices.
159 CHECK(snapshot_ != nullptr);
160 merge_stats_ = snapshot_->GetSnapshotMergeStatsInstance();
161 CHECK(merge_stats_ != nullptr);
Yifan Hongdad0af82020-02-19 17:19:49 -0800162 WaitBootCompletedOrSchedule();
163}
164
165void CleanupPreviousUpdateAction::ScheduleWaitBootCompleted() {
166 TEST_AND_RETURN(running_);
Yifan Hongd1d52a02020-09-25 15:09:07 -0700167 scheduled_task_ = MessageLoop::current()->PostDelayedTask(
Yifan Hongdad0af82020-02-19 17:19:49 -0800168 FROM_HERE,
169 base::Bind(&CleanupPreviousUpdateAction::WaitBootCompletedOrSchedule,
170 base::Unretained(this)),
171 kCheckBootCompletedInterval);
Yifan Hongd1d52a02020-09-25 15:09:07 -0700172 CheckTaskScheduled("WaitBootCompleted");
Yifan Hongdad0af82020-02-19 17:19:49 -0800173}
174
175void CleanupPreviousUpdateAction::WaitBootCompletedOrSchedule() {
Yifan Hongd1d52a02020-09-25 15:09:07 -0700176 AcknowledgeTaskExecuted();
Yifan Hongdad0af82020-02-19 17:19:49 -0800177 TEST_AND_RETURN(running_);
Yifan Hong5cd63fa2020-03-16 12:31:16 -0700178 if (!kIsRecovery &&
179 !android::base::GetBoolProperty(kBootCompletedProp, false)) {
Yifan Hongdad0af82020-02-19 17:19:49 -0800180 // repeat
181 ScheduleWaitBootCompleted();
182 return;
183 }
184
David Anderson0c37f622021-03-11 18:40:25 -0800185 auto boot_time = std::chrono::duration_cast<std::chrono::milliseconds>(
186 android::base::boot_clock::now().time_since_epoch());
187 merge_stats_->set_boot_complete_time_ms(boot_time.count());
188
Yifan Hongdad0af82020-02-19 17:19:49 -0800189 LOG(INFO) << "Boot completed, waiting on markBootSuccessful()";
190 CheckSlotMarkedSuccessfulOrSchedule();
191}
192
193void CleanupPreviousUpdateAction::ScheduleWaitMarkBootSuccessful() {
194 TEST_AND_RETURN(running_);
Yifan Hongd1d52a02020-09-25 15:09:07 -0700195 scheduled_task_ = MessageLoop::current()->PostDelayedTask(
Yifan Hongdad0af82020-02-19 17:19:49 -0800196 FROM_HERE,
197 base::Bind(
198 &CleanupPreviousUpdateAction::CheckSlotMarkedSuccessfulOrSchedule,
199 base::Unretained(this)),
200 kCheckSlotMarkedSuccessfulInterval);
Yifan Hongd1d52a02020-09-25 15:09:07 -0700201 CheckTaskScheduled("WaitMarkBootSuccessful");
Yifan Hongdad0af82020-02-19 17:19:49 -0800202}
203
204void CleanupPreviousUpdateAction::CheckSlotMarkedSuccessfulOrSchedule() {
Yifan Hongd1d52a02020-09-25 15:09:07 -0700205 AcknowledgeTaskExecuted();
Yifan Hongdad0af82020-02-19 17:19:49 -0800206 TEST_AND_RETURN(running_);
Yifan Hong5cd63fa2020-03-16 12:31:16 -0700207 if (!kIsRecovery &&
208 !boot_control_->IsSlotMarkedSuccessful(boot_control_->GetCurrentSlot())) {
Yifan Hongdad0af82020-02-19 17:19:49 -0800209 ScheduleWaitMarkBootSuccessful();
Kelvin Zhang65e8b6c2021-04-02 13:19:40 -0400210 return;
Yifan Hongdad0af82020-02-19 17:19:49 -0800211 }
Yifan Hong5cd63fa2020-03-16 12:31:16 -0700212
213 if (metadata_device_ == nullptr) {
214 metadata_device_ = snapshot_->EnsureMetadataMounted();
215 }
216
217 if (metadata_device_ == nullptr) {
218 LOG(ERROR) << "Failed to mount /metadata.";
Yifan Hong4d7c5eb2020-04-03 11:31:50 -0700219 // If metadata is erased but not formatted, it is possible to not mount
220 // it in recovery. It is safe to skip CleanupPreviousUpdateAction.
221 processor_->ActionComplete(
222 this, kIsRecovery ? ErrorCode::kSuccess : ErrorCode::kError);
Yifan Hong5cd63fa2020-03-16 12:31:16 -0700223 return;
224 }
225
Yifan Hong24031712020-03-19 19:25:38 -0700226 if (kIsRecovery) {
227 auto snapshots_created =
228 snapshot_->RecoveryCreateSnapshotDevices(metadata_device_);
229 switch (snapshots_created) {
230 case android::snapshot::CreateResult::CREATED: {
231 // If previous update has not finished merging, snapshots exists and are
232 // created here so that ProcessUpdateState can proceed.
233 LOG(INFO) << "Snapshot devices are created";
234 break;
235 }
236 case android::snapshot::CreateResult::NOT_CREATED: {
237 // If there is no previous update, no snapshot devices are created and
238 // ProcessUpdateState will return immediately. Hence, NOT_CREATED is not
239 // considered an error.
240 LOG(INFO) << "Snapshot devices are not created";
241 break;
242 }
243 case android::snapshot::CreateResult::ERROR:
244 default: {
245 LOG(ERROR)
246 << "Failed to create snapshot devices (CreateResult = "
247 << static_cast<
248 std::underlying_type_t<android::snapshot::CreateResult>>(
249 snapshots_created);
250 processor_->ActionComplete(this, ErrorCode::kError);
251 return;
252 }
253 }
254 }
255
Yifan Hongd976cc52020-02-25 14:51:42 -0800256 if (!merge_stats_->Start()) {
257 // Not an error because CleanupPreviousUpdateAction may be paused and
258 // resumed while kernel continues merging snapshots in the background.
259 LOG(WARNING) << "SnapshotMergeStats::Start failed.";
260 }
Yifan Hongdad0af82020-02-19 17:19:49 -0800261 LOG(INFO) << "Waiting for any previous merge request to complete. "
262 << "This can take up to several minutes.";
263 WaitForMergeOrSchedule();
264}
265
266void CleanupPreviousUpdateAction::ScheduleWaitForMerge() {
267 TEST_AND_RETURN(running_);
Yifan Hongd1d52a02020-09-25 15:09:07 -0700268 scheduled_task_ = MessageLoop::current()->PostDelayedTask(
Yifan Hongdad0af82020-02-19 17:19:49 -0800269 FROM_HERE,
270 base::Bind(&CleanupPreviousUpdateAction::WaitForMergeOrSchedule,
271 base::Unretained(this)),
272 kWaitForMergeInterval);
Yifan Hongd1d52a02020-09-25 15:09:07 -0700273 CheckTaskScheduled("WaitForMerge");
Yifan Hongdad0af82020-02-19 17:19:49 -0800274}
275
276void CleanupPreviousUpdateAction::WaitForMergeOrSchedule() {
Yifan Hongd1d52a02020-09-25 15:09:07 -0700277 AcknowledgeTaskExecuted();
Yifan Hongdad0af82020-02-19 17:19:49 -0800278 TEST_AND_RETURN(running_);
David Anderson9661fb32021-02-04 17:58:51 -0800279 auto update_uses_compression = snapshot_->UpdateUsesCompression();
Yifan Hongdad0af82020-02-19 17:19:49 -0800280 auto state = snapshot_->ProcessUpdateState(
281 std::bind(&CleanupPreviousUpdateAction::OnMergePercentageUpdate, this),
282 std::bind(&CleanupPreviousUpdateAction::BeforeCancel, this));
David Anderson9661fb32021-02-04 17:58:51 -0800283 merge_stats_->set_state(state, update_uses_compression);
Yifan Hongdad0af82020-02-19 17:19:49 -0800284
Yifan Hongdad0af82020-02-19 17:19:49 -0800285 switch (state) {
286 case UpdateState::None: {
287 LOG(INFO) << "Can't find any snapshot to merge.";
Yifan Hong16b594a2020-03-05 21:02:36 -0800288 ErrorCode error_code = ErrorCode::kSuccess;
289 if (!snapshot_->CancelUpdate()) {
290 error_code = ErrorCode::kError;
291 LOG(INFO) << "Failed to call SnapshotManager::CancelUpdate().";
292 }
293 processor_->ActionComplete(this, error_code);
Yifan Hongdad0af82020-02-19 17:19:49 -0800294 return;
295 }
296
297 case UpdateState::Initiated: {
298 LOG(ERROR) << "Previous update has not been completed, not cleaning up";
299 processor_->ActionComplete(this, ErrorCode::kSuccess);
300 return;
301 }
302
303 case UpdateState::Unverified: {
304 InitiateMergeAndWait();
305 return;
306 }
307
308 case UpdateState::Merging: {
309 ScheduleWaitForMerge();
310 return;
311 }
312
313 case UpdateState::MergeNeedsReboot: {
314 LOG(ERROR) << "Need reboot to finish merging.";
315 processor_->ActionComplete(this, ErrorCode::kError);
316 return;
317 }
318
319 case UpdateState::MergeCompleted: {
320 LOG(INFO) << "Merge finished with state MergeCompleted.";
321 processor_->ActionComplete(this, ErrorCode::kSuccess);
322 return;
323 }
324
325 case UpdateState::MergeFailed: {
326 LOG(ERROR) << "Merge failed. Device may be corrupted.";
327 processor_->ActionComplete(this, ErrorCode::kDeviceCorrupted);
328 return;
329 }
330
331 case UpdateState::Cancelled: {
332 // DeltaPerformer::ResetUpdateProgress failed, hence snapshots are
333 // not deleted to avoid inconsistency.
334 // Nothing can be done here; just try next time.
335 ErrorCode error_code =
336 cancel_failed_ ? ErrorCode::kError : ErrorCode::kSuccess;
337 processor_->ActionComplete(this, error_code);
338 return;
339 }
340
341 default: {
342 // Protobuf has some reserved enum values, so a default case is needed.
343 LOG(FATAL) << "SnapshotManager::ProcessUpdateState returns "
344 << static_cast<int32_t>(state);
345 }
346 }
347}
348
349bool CleanupPreviousUpdateAction::OnMergePercentageUpdate() {
350 double percentage = 0.0;
351 snapshot_->GetUpdateState(&percentage);
352 if (delegate_) {
353 // libsnapshot uses [0, 100] percentage but update_engine uses [0, 1].
354 delegate_->OnCleanupProgressUpdate(percentage / 100);
355 }
356
357 // Log if percentage increments by at least 1.
358 if (last_percentage_ < static_cast<unsigned int>(percentage)) {
359 last_percentage_ = percentage;
360 LOG(INFO) << "Waiting for merge to complete: " << last_percentage_ << "%.";
361 }
362
363 // Do not continue to wait for merge. Instead, let ProcessUpdateState
364 // return Merging directly so that we can ScheduleWaitForMerge() in
365 // MessageLoop.
366 return false;
367}
368
369bool CleanupPreviousUpdateAction::BeforeCancel() {
370 if (DeltaPerformer::ResetUpdateProgress(
371 prefs_,
372 false /* quick */,
373 false /* skip dynamic partitions metadata*/)) {
374 return true;
375 }
376
377 // ResetUpdateProgress might not work on stub prefs. Do additional checks.
378 LOG(WARNING) << "ProcessUpdateState returns Cancelled but cleanup failed.";
379
380 std::string val;
381 ignore_result(prefs_->GetString(kPrefsDynamicPartitionMetadataUpdated, &val));
382 if (val.empty()) {
383 LOG(INFO) << kPrefsDynamicPartitionMetadataUpdated
384 << " is empty, assuming successful cleanup";
385 return true;
386 }
387 LOG(WARNING)
388 << kPrefsDynamicPartitionMetadataUpdated << " is " << val
389 << ", not deleting snapshots even though UpdateState is Cancelled.";
390 cancel_failed_ = true;
391 return false;
392}
393
394void CleanupPreviousUpdateAction::InitiateMergeAndWait() {
395 TEST_AND_RETURN(running_);
396 LOG(INFO) << "Attempting to initiate merge.";
Howard Chen224aed92020-04-17 11:22:13 +0800397 // suspend the VAB merge when running a DSU
398 if (GetBoolProperty("ro.gsid.image_running", false)) {
399 LOG(WARNING) << "Suspend the VAB merge when running a DSU.";
400 processor_->ActionComplete(this, ErrorCode::kError);
401 return;
402 }
Yifan Hongdad0af82020-02-19 17:19:49 -0800403
David Anderson8bda8212021-03-03 18:33:38 -0800404 snapshot_->UpdateCowStats(merge_stats_);
405
David Anderson0c37f622021-03-11 18:40:25 -0800406 auto merge_start_time = std::chrono::duration_cast<std::chrono::milliseconds>(
407 android::base::boot_clock::now().time_since_epoch());
408 merge_stats_->set_boot_complete_to_merge_start_time_ms(
409 merge_start_time.count() - merge_stats_->boot_complete_time_ms());
410
David Anderson8bda8212021-03-03 18:33:38 -0800411 if (snapshot_->InitiateMerge()) {
Yifan Hongdad0af82020-02-19 17:19:49 -0800412 WaitForMergeOrSchedule();
413 return;
414 }
415
416 LOG(WARNING) << "InitiateMerge failed.";
417 auto state = snapshot_->GetUpdateState();
David Anderson9661fb32021-02-04 17:58:51 -0800418 merge_stats_->set_state(state, snapshot_->UpdateUsesCompression());
Yifan Hongdad0af82020-02-19 17:19:49 -0800419 if (state == UpdateState::Unverified) {
420 // We are stuck at unverified state. This can happen if the update has
421 // been applied, but it has not even been attempted yet (in libsnapshot,
422 // rollback indicator does not exist); for example, if update_engine
423 // restarts before the device reboots, then this state may be reached.
424 // Nothing should be done here.
425 LOG(WARNING) << "InitiateMerge leaves the device at "
426 << "UpdateState::Unverified. (Did update_engine "
427 << "restarted?)";
428 processor_->ActionComplete(this, ErrorCode::kSuccess);
429 return;
430 }
431
432 // State does seems to be advanced.
433 // It is possibly racy. For example, on a userdebug build, the user may
434 // manually initiate a merge with snapshotctl between last time
435 // update_engine checks UpdateState. Hence, just call
436 // WaitForMergeOrSchedule one more time.
437 LOG(WARNING) << "IniitateMerge failed but GetUpdateState returned "
438 << android::snapshot::UpdateState_Name(state)
439 << ", try to wait for merge again.";
440 WaitForMergeOrSchedule();
441 return;
442}
443
Yifan Hongd976cc52020-02-25 14:51:42 -0800444void CleanupPreviousUpdateAction::ReportMergeStats() {
445 auto result = merge_stats_->Finish();
446 if (result == nullptr) {
447 LOG(WARNING) << "Not reporting merge stats because "
448 "SnapshotMergeStats::Finish failed.";
449 return;
450 }
451
452#ifdef __ANDROID_RECOVERY__
453 LOG(INFO) << "Skip reporting merge stats in recovery.";
454#else
455 const auto& report = result->report();
456
457 if (report.state() == UpdateState::None ||
458 report.state() == UpdateState::Initiated ||
459 report.state() == UpdateState::Unverified) {
460 LOG(INFO) << "Not reporting merge stats because state is "
461 << android::snapshot::UpdateState_Name(report.state());
462 return;
463 }
464
465 auto passed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
466 result->merge_time());
Alessio Balsini4ed05122020-05-26 22:17:03 +0100467
468 bool vab_retrofit = boot_control_->GetDynamicPartitionControl()
469 ->GetVirtualAbFeatureFlag()
470 .IsRetrofit();
Yifan Hongbab11c52021-02-03 15:05:05 -0800471 bool vab_compression_enabled = boot_control_->GetDynamicPartitionControl()
472 ->GetVirtualAbCompressionFeatureFlag()
473 .IsEnabled();
474 // The snapshot has been merged, so we can no longer call
475 // DynamicPartitionControlInterface::UpdateUsesSnapshotCompression.
476 // However, we have saved the flag in the snapshot report.
477 bool vab_compression_used = report.compression_enabled();
Alessio Balsini4ed05122020-05-26 22:17:03 +0100478
Yifan Hongd976cc52020-02-25 14:51:42 -0800479 LOG(INFO) << "Reporting merge stats: "
480 << android::snapshot::UpdateState_Name(report.state()) << " in "
481 << passed_ms.count() << "ms (resumed " << report.resume_count()
Alessio Balsini4ed05122020-05-26 22:17:03 +0100482 << " times), using " << report.cow_file_size()
483 << " bytes of COW image.";
Yifan Hongbe59a002020-03-02 15:45:14 -0800484 android::util::stats_write(android::util::SNAPSHOT_MERGE_REPORTED,
485 static_cast<int32_t>(report.state()),
486 static_cast<int64_t>(passed_ms.count()),
Alessio Balsini4ed05122020-05-26 22:17:03 +0100487 static_cast<int32_t>(report.resume_count()),
488 vab_retrofit,
Yifan Hongbab11c52021-02-03 15:05:05 -0800489 static_cast<int64_t>(report.cow_file_size()),
490 vab_compression_enabled,
David Andersonb7e6ce52021-03-16 17:23:38 -0700491 vab_compression_used,
492 report.total_cow_size_bytes(),
493 report.estimated_cow_size_bytes(),
494 report.boot_complete_time_ms(),
495 report.boot_complete_to_merge_start_time_ms());
Yifan Hongd976cc52020-02-25 14:51:42 -0800496#endif
497}
498
Yifan Hongdad0af82020-02-19 17:19:49 -0800499} // namespace chromeos_update_engine