Add functions to allow update over cellular (including tethered connection)

- Add an update state NEED_PERMISSION_TO_UPDATE which is broadcasted along
with the update info (version and size) when |OmahaRequestAction| aborts
update due to cellular connection. So the state transition will be:
IDLE->CHECKING_FOR_UPDATE->NEED_PERMISSION_TO_UPDATE->REPORTING_ERROR_EVENT
->IDLE
(The Chrome UI prompts an alert window showing update size and asks user
whether to proceed upon receiving this state.)

- Add a dbus interface to set update over cellular target
(kPrefsUpdateOverCellularTargetVersion and kPrefsUpdateOverCellularTargetSize).
The target is the one received by Chrome UI in NEED_PERMISSION_TO_UPDATE
broadcast. By sending the target back with the dbus call, update engine can
double check the target with the server to make sure there's no new server
push after NEED_PERMISSION_TO_UPDATE is broadcasted to Chrome UI.
(This dbus call is invoked when the user chooses to proceed to update at the
alert window. The dbus call is followed by another dbus call |AttemptUpdate|)

- So, the the decision tree as to whether to allow update over cellular
connection has changed to:
IF (device policy DeviceUpdateAllowedConnectionTypes set)
  follow device policy's decision
ELSE IF (kPrefsUpdateOverCellularPermission set to true)
  allow update
ELSE IF (Either kPrefsUpdateOverCellularTargetVersion or
    kPrefsUpdateOverCellularTargetSize is not set, or they are set but do not
    match the version and size in |OmahaResponse| retrieved by
    |OmahaRequestAction|)
  disallow update, and broadcast NEED_PERMISSION_TO_UPDATE
ELSE
  allow update
ENDIF

- This decision making happens at |OmahaRequestAction| after |OmahaResponse| is
retrieved. Since we want to separate the device policy check with the user
preferences check which depends on |OmahaResponse| during checking for update,
we modify ConnectionManager::IsUpdateAllowedOver by moving the user preferences
check to |OmahaRequestAction|. Thus, the function by default returns true for
cellular connection if device policy is not set.

- Corner case:
Adding kPrefsUpdateOverCellularPermission and
kPrefsUpdateOverCellularTargetSize seems to complicate the logic here. But
they could effectively solve a corner case where the target does not match
|OmahaResponse| due to new server push after broadcasting
NEED_PERMISSION_TO_UPDATE. In that case, we simply broadcast
NEED_PERMISSION_TO_UPDATE again along with new update info.

CQ-DEPEND=CL:481102
BUG=chromium:691108
TEST='FEATURES=test emerge-link update_engine'

(cherry picked from commit 70063d9f7e229db8c5b42443ca96ac23a971a6dd)
Cherry-pick updated to compile on Android.

Reviewed-on: https://chromium-review.googlesource.com/479467
Commit-Ready: Weidong Guo <weidongg@chromium.org>
Tested-by: Weidong Guo <weidongg@chromium.org>
Reviewed-by: Weidong Guo <weidongg@chromium.org>
Reviewed-by: Andrew de los Reyes <adlr@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
29 files changed
tree: aa79f951ea4f50fcd33d613aa1991b6c30b00869
  1. binder_bindings/
  2. client_library/
  3. common/
  4. dbus_bindings/
  5. init/
  6. payload_consumer/
  7. payload_generator/
  8. sample_images/
  9. scripts/
  10. update_manager/
  11. update_payload_key/
  12. .gitignore
  13. Android.mk
  14. binder_service_android.cc
  15. binder_service_android.h
  16. binder_service_brillo.cc
  17. binder_service_brillo.h
  18. boot_control_android.cc
  19. boot_control_android.h
  20. boot_control_chromeos.cc
  21. boot_control_chromeos.h
  22. boot_control_chromeos_unittest.cc
  23. boot_control_recovery.cc
  24. boot_control_recovery.h
  25. boot_control_recovery_stub.cc
  26. certificate_checker.cc
  27. certificate_checker.h
  28. certificate_checker_unittest.cc
  29. chrome_browser_proxy_resolver.cc
  30. chrome_browser_proxy_resolver.h
  31. chrome_browser_proxy_resolver_unittest.cc
  32. common_service.cc
  33. common_service.h
  34. common_service_unittest.cc
  35. connection_manager.cc
  36. connection_manager.h
  37. connection_manager_android.cc
  38. connection_manager_android.h
  39. connection_manager_interface.h
  40. connection_manager_unittest.cc
  41. connection_utils.cc
  42. connection_utils.h
  43. daemon.cc
  44. daemon.h
  45. daemon_state_android.cc
  46. daemon_state_android.h
  47. daemon_state_interface.h
  48. dbus_connection.cc
  49. dbus_connection.h
  50. dbus_service.cc
  51. dbus_service.h
  52. dbus_test_utils.h
  53. fake_file_writer.h
  54. fake_p2p_manager.h
  55. fake_p2p_manager_configuration.h
  56. fake_shill_proxy.cc
  57. fake_shill_proxy.h
  58. fake_system_state.cc
  59. fake_system_state.h
  60. generate_pc_file.sh
  61. hardware_android.cc
  62. hardware_android.h
  63. hardware_chromeos.cc
  64. hardware_chromeos.h
  65. hardware_chromeos_unittest.cc
  66. image_properties.h
  67. image_properties_android.cc
  68. image_properties_chromeos.cc
  69. image_properties_chromeos_unittest.cc
  70. libcros_proxy.cc
  71. libcros_proxy.h
  72. libcurl_http_fetcher.cc
  73. libcurl_http_fetcher.h
  74. libupdate_engine-client-test.pc.in
  75. libupdate_engine-client.pc.in
  76. local_coverage_rate
  77. main.cc
  78. metrics.cc
  79. metrics.h
  80. metrics_utils.cc
  81. metrics_utils.h
  82. metrics_utils_unittest.cc
  83. mock_certificate_checker.h
  84. mock_connection_manager.h
  85. mock_file_writer.h
  86. mock_omaha_request_params.h
  87. mock_p2p_manager.h
  88. mock_payload_state.h
  89. mock_power_manager.h
  90. mock_proxy_resolver.h
  91. mock_update_attempter.h
  92. MODULE_LICENSE_APACHE2
  93. network_selector.h
  94. network_selector_android.cc
  95. network_selector_android.h
  96. network_selector_interface.h
  97. network_selector_stub.cc
  98. network_selector_stub.h
  99. NOTICE
  100. omaha_request_action.cc
  101. omaha_request_action.h
  102. omaha_request_action_unittest.cc
  103. omaha_request_params.cc
  104. omaha_request_params.h
  105. omaha_request_params_unittest.cc
  106. omaha_response.h
  107. omaha_response_handler_action.cc
  108. omaha_response_handler_action.h
  109. omaha_response_handler_action_unittest.cc
  110. omaha_utils.cc
  111. omaha_utils.h
  112. omaha_utils_unittest.cc
  113. OWNERS
  114. p2p_manager.cc
  115. p2p_manager.h
  116. p2p_manager_unittest.cc
  117. parcelable_update_engine_status.cc
  118. parcelable_update_engine_status.h
  119. payload_state.cc
  120. payload_state.h
  121. payload_state_interface.h
  122. payload_state_unittest.cc
  123. power_manager_android.cc
  124. power_manager_android.h
  125. power_manager_chromeos.cc
  126. power_manager_chromeos.h
  127. power_manager_interface.h
  128. PRESUBMIT.cfg
  129. PREUPLOAD.cfg
  130. proxy_resolver.cc
  131. proxy_resolver.h
  132. proxy_resolver_unittest.cc
  133. pylintrc
  134. real_system_state.cc
  135. real_system_state.h
  136. run_unittests
  137. sample_omaha_v3_response.xml
  138. service_delegate_android_interface.h
  139. service_observer_interface.h
  140. shill_proxy.cc
  141. shill_proxy.h
  142. shill_proxy_interface.h
  143. sideload_main.cc
  144. system_state.h
  145. tar_bunzip2.gypi
  146. test_http_server.cc
  147. test_subprocess.cc
  148. testrunner.cc
  149. unittest_key.pem
  150. unittest_key2.pem
  151. update_attempter.cc
  152. update_attempter.h
  153. update_attempter_android.cc
  154. update_attempter_android.h
  155. update_attempter_unittest.cc
  156. update_engine-client.gyp
  157. update_engine.conf
  158. update_engine.gyp
  159. update_engine.rc
  160. update_engine_client.cc
  161. update_engine_client_android.cc
  162. update_metadata.proto
  163. update_status_utils.cc
  164. update_status_utils.h
  165. UpdateEngine.conf
  166. utils_android.cc
  167. utils_android.h
  168. WATCHLISTS