Record installation date and include it in every Omaha request.

Introduce a new state variable, install-date-days, to track the the
point in time that OOBE completed and include this value - if set - in
each Omaha request. This state variable tracks the number of PST8PDT
("Pacific Time") calendar weeks since Jan 1st 2007 0:00 PST, times
seven. It is included as an attribute of the <app> element, like this:

 <app appid="{...}" ... delta_okay="true" ... installdate="2590">

If the state variable is not set, the installdate attribute is not
included.

For new installs (e.g. where OOBE is not complete), the
install-date-days variable is set from the "elapsed_days" value in the
Omaha response. In this case - which should be the majority going
forward - we don't rely on the local clock on the device at all.

On the other hand, for existing installs (e.g. where OOBE was
completed in an OS version not including this CL) and also new
installs where the update-check during OOBE failed (e.g. no network
connection), install-date-days is derived from the timestamp of the
/home/chronos/.oobe_completed marker file. This case obviously relies
on the local clock on the device being set correctly.

Also introduce a new metric, Installer.InstallDateProvisioningSource
to track how install-date-days is provisioned. This metric has two
possible values, kProvisionedFromOmahaResponse (0) and
kProvisionedFromOOBEMarker (1).

In addition to new unit tests, I tested this manually by munging the
/home/chronos/.oobe_completed and
/var/lib/update_engine/prefs/install-date-days files. Also, since
devserver does not send the "elapsed_days" value, I had to point
update_engine to the official Omaha server using the -omaha-url option
with the https://tools.google.com/service/update2 value.

BUG=chromium:336838
TEST=New unit tests + unit tests pass + manual testing.

Change-Id: Id901059c4ab0f9184d1f4ddce72273d739e58224
Reviewed-on: https://chromium-review.googlesource.com/184907
Tested-by: David Zeuthen <zeuthen@chromium.org>
Reviewed-by: David Zeuthen <zeuthen@chromium.org>
Commit-Queue: David Zeuthen <zeuthen@chromium.org>
18 files changed
tree: 041984e487a3124bc997a90f1573e34e0d865ef9
  1. policy_manager/
  2. .gitignore
  3. 99-gpio-dutflag.rules
  4. action.h
  5. action_mock.h
  6. action_pipe.h
  7. action_pipe_unittest.cc
  8. action_processor.cc
  9. action_processor.h
  10. action_processor_mock.h
  11. action_processor_unittest.cc
  12. action_unittest.cc
  13. build
  14. bzip.cc
  15. bzip.h
  16. bzip_extent_writer.cc
  17. bzip_extent_writer.h
  18. bzip_extent_writer_unittest.cc
  19. certificate_checker.cc
  20. certificate_checker.h
  21. certificate_checker_mock.h
  22. certificate_checker_unittest.cc
  23. chrome_browser_proxy_resolver.cc
  24. chrome_browser_proxy_resolver.h
  25. chrome_browser_proxy_resolver_unittest.cc
  26. clock.cc
  27. clock.h
  28. clock_interface.h
  29. connection_manager.cc
  30. connection_manager.h
  31. connection_manager_unittest.cc
  32. constants.cc
  33. constants.h
  34. cycle_breaker.cc
  35. cycle_breaker.h
  36. cycle_breaker_unittest.cc
  37. dbus_constants.h
  38. dbus_interface.h
  39. dbus_service.cc
  40. dbus_service.h
  41. delta_diff_generator.cc
  42. delta_diff_generator.h
  43. delta_diff_generator_unittest.cc
  44. delta_performer.cc
  45. delta_performer.h
  46. delta_performer_unittest.cc
  47. download_action.cc
  48. download_action.h
  49. download_action_unittest.cc
  50. error_code.h
  51. extent_mapper.cc
  52. extent_mapper.h
  53. extent_mapper_unittest.cc
  54. extent_ranges.cc
  55. extent_ranges.h
  56. extent_ranges_unittest.cc
  57. extent_writer.cc
  58. extent_writer.h
  59. extent_writer_unittest.cc
  60. fake_clock.h
  61. fake_hardware.h
  62. fake_p2p_manager.h
  63. fake_p2p_manager_configuration.h
  64. file_descriptor.cc
  65. file_descriptor.h
  66. file_writer.cc
  67. file_writer.h
  68. file_writer_mock.h
  69. file_writer_unittest.cc
  70. filesystem_copier_action.cc
  71. filesystem_copier_action.h
  72. filesystem_copier_action_unittest.cc
  73. filesystem_iterator.cc
  74. filesystem_iterator.h
  75. filesystem_iterator_unittest.cc
  76. full_update_generator.cc
  77. full_update_generator.h
  78. full_update_generator_unittest.cc
  79. gen_coverage_html
  80. generate_delta_main.cc
  81. gpio_handler.cc
  82. gpio_handler.h
  83. gpio_handler_unittest.cc
  84. gpio_handler_unittest.h
  85. gpio_mock_file_descriptor.cc
  86. gpio_mock_file_descriptor.h
  87. gpio_mock_udev_interface.cc
  88. gpio_mock_udev_interface.h
  89. graph_types.h
  90. graph_utils.cc
  91. graph_utils.h
  92. graph_utils_unittest.cc
  93. hardware.cc
  94. hardware.h
  95. hardware_interface.h
  96. http_common.cc
  97. http_common.h
  98. http_fetcher.cc
  99. http_fetcher.h
  100. http_fetcher_unittest.cc
  101. inherit-review-settings-ok
  102. install_plan.cc
  103. install_plan.h
  104. libcurl_http_fetcher.cc
  105. libcurl_http_fetcher.h
  106. LICENSE
  107. local_coverage_rate
  108. main.cc
  109. marshal.list
  110. metadata.cc
  111. metadata.h
  112. metadata_unittest.cc
  113. mock_connection_manager.h
  114. mock_dbus_interface.h
  115. mock_file_writer.h
  116. mock_gpio_handler.h
  117. mock_hardware.h
  118. mock_http_fetcher.cc
  119. mock_http_fetcher.h
  120. mock_p2p_manager.h
  121. mock_payload_state.h
  122. mock_system_state.cc
  123. mock_system_state.h
  124. multi_range_http_fetcher.cc
  125. multi_range_http_fetcher.h
  126. omaha_hash_calculator.cc
  127. omaha_hash_calculator.h
  128. omaha_hash_calculator_unittest.cc
  129. omaha_request_action.cc
  130. omaha_request_action.h
  131. omaha_request_action_unittest.cc
  132. omaha_request_params.cc
  133. omaha_request_params.h
  134. omaha_request_params_unittest.cc
  135. omaha_response.h
  136. omaha_response_handler_action.cc
  137. omaha_response_handler_action.h
  138. omaha_response_handler_action_unittest.cc
  139. p2p_manager.cc
  140. p2p_manager.h
  141. p2p_manager_unittest.cc
  142. payload_signer.cc
  143. payload_signer.h
  144. payload_signer_unittest.cc
  145. payload_state.cc
  146. payload_state.h
  147. payload_state_interface.h
  148. payload_state_unittest.cc
  149. postinstall_runner_action.cc
  150. postinstall_runner_action.h
  151. postinstall_runner_action_unittest.cc
  152. prefs.cc
  153. prefs.h
  154. prefs_interface.h
  155. prefs_mock.h
  156. prefs_unittest.cc
  157. proxy_resolver.cc
  158. proxy_resolver.h
  159. real_system_state.h
  160. run_unittests
  161. sample_omaha_v3_response.xml
  162. SConstruct
  163. setup_dev_packages
  164. simple_key_value_store.cc
  165. simple_key_value_store.h
  166. simple_key_value_store_unittest.cc
  167. subprocess.cc
  168. subprocess.h
  169. subprocess_unittest.cc
  170. system_state.cc
  171. system_state.h
  172. tarjan.cc
  173. tarjan.h
  174. tarjan_unittest.cc
  175. terminator.cc
  176. terminator.h
  177. terminator_unittest.cc
  178. test_http_server.cc
  179. test_utils.cc
  180. test_utils.h
  181. testrunner.cc
  182. topological_sort.cc
  183. topological_sort.h
  184. topological_sort_unittest.cc
  185. udev_interface.h
  186. unittest_key.pem
  187. unittest_key2.pem
  188. update_attempter.cc
  189. update_attempter.h
  190. update_attempter_mock.h
  191. update_attempter_unittest.cc
  192. update_check_scheduler.cc
  193. update_check_scheduler.h
  194. update_check_scheduler_unittest.cc
  195. update_engine.xml
  196. update_engine_client.cc
  197. update_metadata.proto
  198. UpdateEngine.conf
  199. utils.cc
  200. utils.h
  201. utils_unittest.cc
  202. WATCHLISTS
  203. zip_unittest.cc