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