Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (C) 2012 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 16 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H_ |
| 18 | #define UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H_ |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 19 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 22 | #include <string> |
| 23 | |
Ben Chan | 05735a1 | 2014-09-03 07:48:22 -0700 | [diff] [blame] | 24 | #include <base/macros.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 25 | #include <base/time/time.h> |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 26 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 27 | |
| 28 | // This gathers local system information and prepares info used by the |
| 29 | // Omaha request action. |
| 30 | |
| 31 | namespace chromeos_update_engine { |
| 32 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 33 | // The default "official" Omaha update URL. |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 34 | extern const char kProductionOmahaUrl[]; |
| 35 | |
| 36 | // The autoupdate test Omaha update URL. |
| 37 | extern const char kAUTestOmahaUrl[]; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 38 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 39 | class SystemState; |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 40 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 41 | // This class encapsulates the data Omaha gets for the request, along with |
| 42 | // essential state needed for the processing of the request/response. The |
| 43 | // strings in this struct should not be XML escaped. |
| 44 | // |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 45 | // TODO(jaysri): chromium-os:39752 tracks the need to rename this class to |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 46 | // reflect its lifetime more appropriately. |
| 47 | class OmahaRequestParams { |
| 48 | public: |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 49 | explicit OmahaRequestParams(SystemState* system_state) |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 50 | : system_state_(system_state), |
| 51 | os_platform_(kOsPlatform), |
| 52 | os_version_(kOsVersion), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 53 | board_app_id_(kAppId), |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 54 | canary_app_id_(kAppId), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 55 | delta_okay_(true), |
| 56 | interactive_(false), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 57 | wall_clock_based_wait_enabled_(false), |
| 58 | update_check_count_wait_enabled_(false), |
| 59 | min_update_checks_needed_(kDefaultMinUpdateChecks), |
| 60 | max_update_checks_allowed_(kDefaultMaxUpdateChecks), |
| 61 | is_powerwash_allowed_(false), |
| 62 | force_lock_down_(false), |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 63 | forced_lock_down_(false) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 64 | InitFromLsbValue(); |
| 65 | } |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 66 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 67 | OmahaRequestParams(SystemState* system_state, |
| 68 | const std::string& in_os_platform, |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 69 | const std::string& in_os_version, |
| 70 | const std::string& in_os_sp, |
| 71 | const std::string& in_os_board, |
| 72 | const std::string& in_app_id, |
| 73 | const std::string& in_app_version, |
| 74 | const std::string& in_app_lang, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 75 | const std::string& in_target_channel, |
| 76 | const std::string& in_hwid, |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 77 | const std::string& in_fw_version, |
| 78 | const std::string& in_ec_version, |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 79 | bool in_delta_okay, |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 80 | bool in_interactive, |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 81 | const std::string& in_update_url, |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 82 | const std::string& in_target_version_prefix) |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 83 | : system_state_(system_state), |
| 84 | os_platform_(in_os_platform), |
| 85 | os_version_(in_os_version), |
| 86 | os_sp_(in_os_sp), |
| 87 | os_board_(in_os_board), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 88 | board_app_id_(in_app_id), |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 89 | canary_app_id_(in_app_id), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 90 | app_version_(in_app_version), |
| 91 | app_lang_(in_app_lang), |
| 92 | current_channel_(in_target_channel), |
| 93 | target_channel_(in_target_channel), |
| 94 | hwid_(in_hwid), |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 95 | fw_version_(in_fw_version), |
| 96 | ec_version_(in_ec_version), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 97 | delta_okay_(in_delta_okay), |
| 98 | interactive_(in_interactive), |
| 99 | update_url_(in_update_url), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 100 | target_version_prefix_(in_target_version_prefix), |
| 101 | wall_clock_based_wait_enabled_(false), |
| 102 | update_check_count_wait_enabled_(false), |
| 103 | min_update_checks_needed_(kDefaultMinUpdateChecks), |
| 104 | max_update_checks_allowed_(kDefaultMaxUpdateChecks), |
| 105 | is_powerwash_allowed_(false), |
| 106 | force_lock_down_(false), |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 107 | forced_lock_down_(false) {} |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 108 | |
Alex Deymo | e894870 | 2014-11-11 21:44:45 -0800 | [diff] [blame] | 109 | virtual ~OmahaRequestParams() = default; |
| 110 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 111 | // Setters and getters for the various properties. |
| 112 | inline std::string os_platform() const { return os_platform_; } |
| 113 | inline std::string os_version() const { return os_version_; } |
| 114 | inline std::string os_sp() const { return os_sp_; } |
| 115 | inline std::string os_board() const { return os_board_; } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 116 | inline std::string board_app_id() const { return board_app_id_; } |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 117 | inline std::string canary_app_id() const { return canary_app_id_; } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 118 | inline std::string app_lang() const { return app_lang_; } |
| 119 | inline std::string hwid() const { return hwid_; } |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 120 | inline std::string fw_version() const { return fw_version_; } |
| 121 | inline std::string ec_version() const { return ec_version_; } |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 122 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 123 | inline void set_app_version(const std::string& version) { |
| 124 | app_version_ = version; |
| 125 | } |
| 126 | inline std::string app_version() const { return app_version_; } |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 127 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 128 | inline std::string current_channel() const { return current_channel_; } |
| 129 | inline std::string target_channel() const { return target_channel_; } |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 130 | inline std::string download_channel() const { return download_channel_; } |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 131 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 132 | // Can client accept a delta ? |
| 133 | inline void set_delta_okay(bool ok) { delta_okay_ = ok; } |
| 134 | inline bool delta_okay() const { return delta_okay_; } |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 135 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 136 | // True if this is a user-initiated update check. |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 137 | inline void set_interactive(bool interactive) { interactive_ = interactive; } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 138 | inline bool interactive() const { return interactive_; } |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 139 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 140 | inline void set_update_url(const std::string& url) { update_url_ = url; } |
| 141 | inline std::string update_url() const { return update_url_; } |
| 142 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 143 | inline void set_target_version_prefix(const std::string& prefix) { |
| 144 | target_version_prefix_ = prefix; |
| 145 | } |
| 146 | |
| 147 | inline std::string target_version_prefix() const { |
| 148 | return target_version_prefix_; |
| 149 | } |
| 150 | |
| 151 | inline void set_wall_clock_based_wait_enabled(bool enabled) { |
| 152 | wall_clock_based_wait_enabled_ = enabled; |
| 153 | } |
| 154 | inline bool wall_clock_based_wait_enabled() const { |
| 155 | return wall_clock_based_wait_enabled_; |
| 156 | } |
| 157 | |
| 158 | inline void set_waiting_period(base::TimeDelta period) { |
| 159 | waiting_period_ = period; |
| 160 | } |
| 161 | base::TimeDelta waiting_period() const { return waiting_period_; } |
| 162 | |
| 163 | inline void set_update_check_count_wait_enabled(bool enabled) { |
| 164 | update_check_count_wait_enabled_ = enabled; |
| 165 | } |
| 166 | |
| 167 | inline bool update_check_count_wait_enabled() const { |
| 168 | return update_check_count_wait_enabled_; |
| 169 | } |
| 170 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 171 | inline void set_min_update_checks_needed(int64_t min) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 172 | min_update_checks_needed_ = min; |
| 173 | } |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 174 | inline int64_t min_update_checks_needed() const { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 175 | return min_update_checks_needed_; |
| 176 | } |
| 177 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 178 | inline void set_max_update_checks_allowed(int64_t max) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 179 | max_update_checks_allowed_ = max; |
| 180 | } |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 181 | inline int64_t max_update_checks_allowed() const { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 182 | return max_update_checks_allowed_; |
| 183 | } |
| 184 | |
| 185 | // True if we're trying to update to a more stable channel. |
| 186 | // i.e. index(target_channel) > index(current_channel). |
Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 187 | virtual bool to_more_stable_channel() const; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 188 | |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 189 | // Returns the app id corresponding to the current value of the |
| 190 | // download channel. |
Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 191 | virtual std::string GetAppId() const; |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 192 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 193 | // Suggested defaults |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 194 | static const char kAppId[]; |
| 195 | static const char kOsPlatform[]; |
| 196 | static const char kOsVersion[]; |
| 197 | static const char kUpdateUrl[]; |
| 198 | static const char kUpdateChannelKey[]; |
| 199 | static const char kIsPowerwashAllowedKey[]; |
| 200 | static const char kAutoUpdateServerKey[]; |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 201 | static const int64_t kDefaultMinUpdateChecks = 0; |
| 202 | static const int64_t kDefaultMaxUpdateChecks = 8; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 203 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 204 | // Initializes all the data in the object. Non-empty |
| 205 | // |in_app_version| or |in_update_url| prevents automatic detection |
| 206 | // of the parameter. Returns true on success, false otherwise. |
| 207 | bool Init(const std::string& in_app_version, |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 208 | const std::string& in_update_url, |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 209 | bool in_interactive); |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 210 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 211 | // Permanently changes the release channel to |channel|. Performs a |
| 212 | // powerwash, if required and allowed. |
| 213 | // Returns true on success, false otherwise. Note: This call will fail if |
| 214 | // there's a channel change pending already. This is to serialize all the |
| 215 | // channel changes done by the user in order to avoid having to solve |
| 216 | // numerous edge cases around ensuring the powerwash happens as intended in |
| 217 | // all such cases. |
Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 218 | virtual bool SetTargetChannel(const std::string& channel, |
| 219 | bool is_powerwash_allowed); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 220 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 221 | // Updates the download channel for this particular attempt from the current |
| 222 | // value of target channel. This method takes a "snapshot" of the current |
| 223 | // value of target channel and uses it for all subsequent Omaha requests for |
| 224 | // this attempt (i.e. initial request as well as download progress/error |
| 225 | // event requests). The snapshot will be updated only when either this method |
| 226 | // or Init is called again. |
Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 227 | virtual void UpdateDownloadChannel(); |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 228 | |
Alex Deymo | 560ae1d | 2014-10-28 02:17:54 -0700 | [diff] [blame] | 229 | virtual bool is_powerwash_allowed() const { return is_powerwash_allowed_; } |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 230 | |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 231 | // Check if the provided update URL is official, meaning either the default |
| 232 | // autoupdate server or the autoupdate autotest server. |
| 233 | virtual bool IsUpdateUrlOfficial() const; |
| 234 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 235 | // For unit-tests. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 236 | void set_root(const std::string& root); |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 237 | void set_current_channel(const std::string& channel) { |
| 238 | current_channel_ = channel; |
| 239 | } |
Gilad Arnold | 76b2b48 | 2014-04-01 13:32:43 -0700 | [diff] [blame] | 240 | void set_target_channel(const std::string& channel) { |
| 241 | target_channel_ = channel; |
| 242 | } |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 243 | |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 244 | // Enforce security mode for testing purposes. |
| 245 | void SetLockDown(bool lock); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 246 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 247 | private: |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 248 | FRIEND_TEST(OmahaRequestParamsTest, IsValidChannelTest); |
| 249 | FRIEND_TEST(OmahaRequestParamsTest, ShouldLockDownTest); |
| 250 | FRIEND_TEST(OmahaRequestParamsTest, ChannelIndexTest); |
| 251 | FRIEND_TEST(OmahaRequestParamsTest, LsbPreserveTest); |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 252 | FRIEND_TEST(OmahaRequestParamsTest, CollectECFWVersionsTest); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 253 | |
| 254 | // Use a validator that is a non-static member of this class so that its |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 255 | // inputs can be mocked in unit tests (e.g., build type for IsValidChannel). |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 256 | typedef bool( |
| 257 | OmahaRequestParams::*ValueValidator)( // NOLINT(readability/casting) |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 258 | const std::string&) const; |
| 259 | |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 260 | // Returns true if parameter values should be locked down for security |
| 261 | // reasons. If this is an official build running in normal boot mode, all |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 262 | // values except the release channel are parsed only from the read-only rootfs |
| 263 | // partition and the channel values are restricted to a pre-approved set. |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 264 | bool ShouldLockDown() const; |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 265 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 266 | // Returns true if |channel| is a valid channel, false otherwise. This method |
| 267 | // restricts the channel value only if the image is official (see |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 268 | // IsOfficialBuild). |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 269 | bool IsValidChannel(const std::string& channel) const; |
| 270 | |
| 271 | // Returns the index of the given channel. |
| 272 | int GetChannelIndex(const std::string& channel) const; |
| 273 | |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 274 | // Returns True if we should store the fw/ec versions based on our hwid_. |
| 275 | // Compares hwid to a set of whitelisted prefixes. |
| 276 | bool CollectECFWVersions() const; |
| 277 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 278 | // These are individual helper methods to initialize the said properties from |
| 279 | // the LSB value. |
| 280 | void SetTargetChannelFromLsbValue(); |
| 281 | void SetCurrentChannelFromLsbValue(); |
| 282 | void SetIsPowerwashAllowedFromLsbValue(); |
| 283 | |
| 284 | // Initializes the required properties from the LSB value. |
| 285 | void InitFromLsbValue(); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 286 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 287 | // Fetches the value for a given key from |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 288 | // /mnt/stateful_partition/etc/lsb-release if possible and |stateful_override| |
| 289 | // is true. Failing that, it looks for the key in /etc/lsb-release. If |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 290 | // |validator| is non-null, uses it to validate and ignore invalid values. |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 291 | std::string GetLsbValue(const std::string& key, |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 292 | const std::string& default_value, |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 293 | ValueValidator validator, |
| 294 | bool stateful_override) const; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 295 | |
| 296 | // Gets the machine type (e.g. "i686"). |
| 297 | std::string GetMachineType() const; |
| 298 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 299 | // Global system context. |
| 300 | SystemState* system_state_; |
| 301 | |
| 302 | // Basic properties of the OS and Application that go into the Omaha request. |
| 303 | std::string os_platform_; |
| 304 | std::string os_version_; |
| 305 | std::string os_sp_; |
| 306 | std::string os_board_; |
| 307 | |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 308 | // The board app id identifies the app id for the board irrespective of the |
| 309 | // channel that we're on. The canary app id identifies the app id to be used |
| 310 | // iff we're in the canary-channel. These values could be different depending |
| 311 | // on how the release tools are implemented. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 312 | std::string board_app_id_; |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 313 | std::string canary_app_id_; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 314 | |
| 315 | std::string app_version_; |
| 316 | std::string app_lang_; |
| 317 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 318 | // The three channel values we deal with. |
| 319 | // Current channel: is always the channel from /etc/lsb-release. It never |
| 320 | // changes. It's just read in during initialization. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 321 | std::string current_channel_; |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 322 | |
| 323 | // Target channel: It starts off with the value of current channel. But if |
| 324 | // the user changes the channel, then it'll have a different value. If the |
| 325 | // user changes multiple times, target channel will always contain the most |
| 326 | // recent change and is updated immediately to the user-selected value even |
| 327 | // if we're in the middle of a download (as opposed to download channel |
| 328 | // which gets updated only at the start of next download) |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 329 | std::string target_channel_; |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 330 | |
| 331 | // The channel from which we're downloading the payload. This should normally |
| 332 | // be the same as target channel. But if the user made another channel change |
| 333 | // we started the download, then they'd be different, in which case, we'd |
| 334 | // detect elsewhere that the target channel has been changed and cancel the |
| 335 | // current download attempt. |
| 336 | std::string download_channel_; |
| 337 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 338 | std::string hwid_; // Hardware Qualification ID of the client |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 339 | std::string fw_version_; // Chrome OS Firmware Version. |
| 340 | std::string ec_version_; // Chrome OS EC Version. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 341 | bool delta_okay_; // If this client can accept a delta |
| 342 | bool interactive_; // Whether this is a user-initiated update check |
| 343 | |
| 344 | // The URL to send the Omaha request to. |
| 345 | std::string update_url_; |
| 346 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 347 | // Prefix of the target OS version that the enterprise wants this device |
| 348 | // to be pinned to. It's empty otherwise. |
| 349 | std::string target_version_prefix_; |
| 350 | |
| 351 | // True if scattering is enabled, in which case waiting_period_ specifies the |
| 352 | // amount of absolute time that we've to wait for before sending a request to |
| 353 | // Omaha. |
| 354 | bool wall_clock_based_wait_enabled_; |
| 355 | base::TimeDelta waiting_period_; |
| 356 | |
| 357 | // True if scattering is enabled to denote the number of update checks |
| 358 | // we've to skip before we can send a request to Omaha. The min and max |
| 359 | // values establish the bounds for a random number to be chosen within that |
| 360 | // range to enable such a wait. |
| 361 | bool update_check_count_wait_enabled_; |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 362 | int64_t min_update_checks_needed_; |
| 363 | int64_t max_update_checks_allowed_; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 364 | |
| 365 | // True if we are allowed to do powerwash, if required, on a channel change. |
| 366 | bool is_powerwash_allowed_; |
| 367 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 368 | // When reading files, prepend root_ to the paths. Useful for testing. |
| 369 | std::string root_; |
| 370 | |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 371 | // Force security lock down for testing purposes. |
| 372 | bool force_lock_down_; |
| 373 | bool forced_lock_down_; |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 374 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 375 | // TODO(jaysri): Uncomment this after fixing unit tests, as part of |
| 376 | // chromium-os:39752 |
| 377 | // DISALLOW_COPY_AND_ASSIGN(OmahaRequestParams); |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 378 | }; |
| 379 | |
| 380 | } // namespace chromeos_update_engine |
| 381 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 382 | #endif // UPDATE_ENGINE_OMAHA_REQUEST_PARAMS_H_ |