Implement powerwash on Android.
Powerwash, the name for the equivalent of a factory reset or /data wipe,
can be triggered in Android by writing the desired command to the
recovery command file and rebooting into recovery.
This patch moves the powerwash scheduling/canceling logic to the
HardwareInterface and implements it on Android.
Bug: 28700985
TEST=Called update_engine_client passing POWERWASH=1, BCB is stored up
to offset 832.
(cherry picked from commit fb905d9b8d49f8fe41297c7aba2dd0942f1be311)
Change-Id: I66f9473c10fbe8f56e9000ce3e605b2bee345db8
diff --git a/common/constants.cc b/common/constants.cc
index f138ce3..fd2b542 100644
--- a/common/constants.cc
+++ b/common/constants.cc
@@ -18,11 +18,6 @@
namespace chromeos_update_engine {
-const char kPowerwashMarkerFile[] =
- "/mnt/stateful_partition/factory_install_reset";
-
-const char kPowerwashCommand[] = "safe fast keepimg reason=update_engine\n";
-
const char kPowerwashSafePrefsSubDirectory[] = "update_engine/prefs";
const char kPrefsSubDirectory[] = "prefs";
@@ -96,5 +91,6 @@
const char kPayloadPropertyMetadataHash[] = "METADATA_HASH";
const char kPayloadPropertyAuthorization[] = "AUTHORIZATION";
const char kPayloadPropertyUserAgent[] = "USER_AGENT";
+const char kPayloadPropertyPowerwash[] = "POWERWASH";
} // namespace chromeos_update_engine
diff --git a/common/constants.h b/common/constants.h
index f0d589d..af57a41 100644
--- a/common/constants.h
+++ b/common/constants.h
@@ -19,13 +19,6 @@
namespace chromeos_update_engine {
-// The name of the marker file used to trigger powerwash when post-install
-// completes successfully so that the device is powerwashed on next reboot.
-extern const char kPowerwashMarkerFile[];
-
-// The contents of the powerwash marker file.
-extern const char kPowerwashCommand[];
-
// Directory for AU prefs that are preserved across powerwash.
extern const char kPowerwashSafePrefsSubDirectory[];
@@ -99,6 +92,7 @@
extern const char kPayloadPropertyMetadataHash[];
extern const char kPayloadPropertyAuthorization[];
extern const char kPayloadPropertyUserAgent[];
+extern const char kPayloadPropertyPowerwash[];
// A download source is any combination of protocol and server (that's of
// interest to us when looking at UMA metrics) using which we may download
diff --git a/common/fake_hardware.h b/common/fake_hardware.h
index 23d6498..0bd297b 100644
--- a/common/fake_hardware.h
+++ b/common/fake_hardware.h
@@ -62,6 +62,18 @@
int GetPowerwashCount() const override { return powerwash_count_; }
+ bool SchedulePowerwash() override {
+ powerwash_scheduled_ = true;
+ return true;
+ }
+
+ bool CancelPowerwash() override {
+ powerwash_scheduled_ = false;
+ return true;
+ }
+
+ bool IsPowerwashScheduled() { return powerwash_scheduled_; }
+
bool GetNonVolatileDirectory(base::FilePath* path) const override {
return false;
}
@@ -115,6 +127,7 @@
std::string firmware_version_;
std::string ec_version_;
int powerwash_count_;
+ bool powerwash_scheduled_{false};
DISALLOW_COPY_AND_ASSIGN(FakeHardware);
};
diff --git a/common/hardware_interface.h b/common/hardware_interface.h
index 17ce694..c2d4296 100644
--- a/common/hardware_interface.h
+++ b/common/hardware_interface.h
@@ -65,6 +65,13 @@
// recovery don't have this value set.
virtual int GetPowerwashCount() const = 0;
+ // Signals that a powerwash (stateful partition wipe) should be performed
+ // after reboot.
+ virtual bool SchedulePowerwash() = 0;
+
+ // Cancel the powerwash operation scheduled to be performed on next boot.
+ virtual bool CancelPowerwash() = 0;
+
// Store in |path| the path to a non-volatile directory (persisted across
// reboots) available for this daemon. In case of an error, such as no
// directory available, returns false.
diff --git a/common/utils.cc b/common/utils.cc
index 5d15da0..19c63c0 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -1055,35 +1055,6 @@
return base_code;
}
-bool CreatePowerwashMarkerFile(const char* file_path) {
- const char* marker_file = file_path ? file_path : kPowerwashMarkerFile;
- bool result = utils::WriteFile(marker_file,
- kPowerwashCommand,
- strlen(kPowerwashCommand));
- if (result) {
- LOG(INFO) << "Created " << marker_file << " to powerwash on next reboot";
- } else {
- PLOG(ERROR) << "Error in creating powerwash marker file: " << marker_file;
- }
-
- return result;
-}
-
-bool DeletePowerwashMarkerFile(const char* file_path) {
- const char* marker_file = file_path ? file_path : kPowerwashMarkerFile;
- const base::FilePath kPowerwashMarkerPath(marker_file);
- bool result = base::DeleteFile(kPowerwashMarkerPath, false);
-
- if (result)
- LOG(INFO) << "Successfully deleted the powerwash marker file : "
- << marker_file;
- else
- PLOG(ERROR) << "Could not delete the powerwash marker file : "
- << marker_file;
-
- return result;
-}
-
Time TimeFromStructTimespec(struct timespec *ts) {
int64_t us = static_cast<int64_t>(ts->tv_sec) * Time::kMicrosecondsPerSecond +
static_cast<int64_t>(ts->tv_nsec) / Time::kNanosecondsPerMicrosecond;
diff --git a/common/utils.h b/common/utils.h
index 88c33b7..63328b6 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -315,16 +315,6 @@
// it'll return the same value again.
ErrorCode GetBaseErrorCode(ErrorCode code);
-// Creates the powerwash marker file with the appropriate commands in it. Uses
-// |file_path| as the path to the marker file if non-null, otherwise uses the
-// global default. Returns true if successfully created. False otherwise.
-bool CreatePowerwashMarkerFile(const char* file_path);
-
-// Deletes the marker file used to trigger Powerwash using clobber-state. Uses
-// |file_path| as the path to the marker file if non-null, otherwise uses the
-// global default. Returns true if successfully deleted. False otherwise.
-bool DeletePowerwashMarkerFile(const char* file_path);
-
// Decodes the data in |base64_encoded| and stores it in a temporary
// file. Returns false if the given data is empty, not well-formed
// base64 or if an error occurred. If true is returned, the decoded