update_engine: Don't sent <ping a=-1 r=-1> once the device was powerwashed.

When a device is first activated, a <ping a=-1 r=-1> is sent to Omaha
indicating this is a new device activation. After that point, the
active days count will be positive since Omaha sends back the daystart
tag which will be used in the future to compute the non-negative
"a=" and "r=" values.

Nevertheless, when a device is powerwashed, the daystart data is lost
and the first login will trigger a "new device" activation, counting
the same device as two activations in the Omaha side.

This patch uses the powerwash_count file stored in stateful partition
to detect if the new device activation is performed on a device that
was powerwashed at some point and thus doesn't send the a=-1 and r=-1
ping to Omaha. The powerwash_count is generated or incremented
whenever a "safe" powerwash is performed (such as the one that
update_engine triggers on some channel changes). Going to dev mode
and back, going through recovery with an USB key or doing a
"factory" powerwash (done in the factory) *will* wipe this powerwash
count and send the device back to a factory state.

BUG=chromium:428792
TEST=Manual test.

Manual test procude:
1. Run recovery. Check /mnt/stateful_partition/unencrypted/preserve/powerwash_count
   is not present.
2. Login for the first time.
3. Check /var/log/update_engine.log shows a '<ping' with 'a="-1" r="-1"' being sent.
4. Powerwash ( echo "safe fast keepimg" > /mnt/stateful_partition/factory_install_reset )
5. Reboot
6. Login for the first time again.
7. Check /var/log/update_engine.log shows doesn't show a '<ping' with 'a="-1" r="-1"'

Change-Id: I1a823040d2da43b93f14241bc521087ce2a2d4f2
Reviewed-on: https://chromium-review.googlesource.com/226716
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/fake_hardware.h b/fake_hardware.h
index ff80009..13c3341 100644
--- a/fake_hardware.h
+++ b/fake_hardware.h
@@ -18,6 +18,11 @@
 // Implements a fake hardware interface used for testing.
 class FakeHardware : public HardwareInterface {
  public:
+  // Value used to signal that the powerwash_count file is not present. When
+  // this value is used in SetPowerwashCount(), GetPowerwashCount() will return
+  // false.
+  static const int kPowerwashCountNotSet = -1;
+
   FakeHardware()
     : kernel_device_("/dev/sdz4"),
       boot_device_("/dev/sdz5"),
@@ -28,7 +33,8 @@
       is_oobe_complete_(false),
       hardware_class_("Fake HWID BLAH-1234"),
       firmware_version_("Fake Firmware v1.0.1"),
-      ec_version_("Fake EC v1.0a") {}
+      ec_version_("Fake EC v1.0a"),
+      powerwash_count_(kPowerwashCountNotSet) {}
 
   // HardwareInterface methods.
   std::string BootKernelDevice() const override { return kernel_device_; }
@@ -71,6 +77,8 @@
 
   std::string GetECVersion() const override { return ec_version_; }
 
+  int GetPowerwashCount() const override { return powerwash_count_; }
+
   // Setters
   void SetBootDevice(const std::string& boot_device) {
     boot_device_ = boot_device;
@@ -111,6 +119,10 @@
     ec_version_ = ec_version;
   }
 
+  void SetPowerwashCount(int powerwash_count) {
+    powerwash_count_ = powerwash_count;
+  }
+
  private:
   std::string kernel_device_;
   std::string boot_device_;
@@ -124,6 +136,7 @@
   std::string hardware_class_;
   std::string firmware_version_;
   std::string ec_version_;
+  int powerwash_count_;
 
   DISALLOW_COPY_AND_ASSIGN(FakeHardware);
 };