blob: 8f87b3adf74a644a7a15163e58a9f7ad4d8d03a9 [file] [log] [blame]
# Copyright 2021 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
description "Report the powerwash count and days if powerwash happened"
author "chromium-os-dev@chromium.org"
start on started system-services
script
UNENCRYPTED="/mnt/stateful_partition/unencrypted"
POWERWASH_COMPLETE="${UNENCRYPTED}/.powerwash_completed"
POWERWASH_COUNT="${UNENCRYPTED}/preserve/powerwash_count"
POWERWASH_TIME="${UNENCRYPTED}/preserve/last_powerwash_time"
# Report powerwash stats if a powerwash recently occurred.
if [ -f "${POWERWASH_COMPLETE}" -a -f /home/chronos/.oobe_completed ]; then
# Upload the fact powerwash occurred and the number of times this device
# has been powerwashed.
COUNT="$(head -1 "${POWERWASH_COUNT}" | cut -c1-4)"
if [ $(expr "${COUNT}" : "^[0-9][0-9]*$") -ne 0 ]; then
metrics_client Installer.PowerwashCount "${COUNT}" 1 1000 20
fi
# Upload how many calendar days that powerwash occurred before current time.
OCCURRED_TIME="$(head -1 "${POWERWASH_TIME}")"
if [ $(expr "${OCCURRED_TIME}" : "^[0-9][0-9]*$") -ne 0 ]; then
CURRENT_TIME="$(date +%s)"
SECONDS_IN_DAY="86400"
CURRENT_DAYS=""${CURRENT_TIME}" / "${SECONDS_IN_DAY}""
OCCURRED_DAYS=""${OCCURRED_TIME}" / "${SECONDS_IN_DAY}""
# Add 1 to make sure even if UMA metrics save the default value 0 for
# not powerwashed, then we can differentiate this case.
DAYS="$((${CURRENT_DAYS} - ${OCCURRED_DAYS} + 1))"
metrics_client Installer.PowerwashDays "${DAYS}" 1 100 100
fi
rm -f "${POWERWASH_COMPLETE}" "${POWERWASH_TIME}"
fi
end script