Darin Petkov | f2065b4 | 2011-05-17 16:36:27 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/omaha_request_params.h" |
| 6 | |
| 7 | #include <errno.h> |
| 8 | #include <fcntl.h> |
| 9 | #include <sys/utsname.h> |
| 10 | |
| 11 | #include <map> |
| 12 | #include <string> |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 13 | #include <vector> |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 14 | |
Ben Chan | 06c76a4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 15 | #include <base/files/file_util.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 16 | #include <base/strings/string_util.h> |
Alex Deymo | 2b4e2a5 | 2014-09-23 12:05:56 -0700 | [diff] [blame] | 17 | #include <chromeos/key_value_store.h> |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 18 | #include <policy/device_policy.h> |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 19 | |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 20 | #include "update_engine/constants.h" |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 21 | #include "update_engine/hardware_interface.h" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 22 | #include "update_engine/system_state.h" |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 23 | #include "update_engine/utils.h" |
| 24 | |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 25 | #define CALL_MEMBER_FN(object, member) ((object).*(member)) |
| 26 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 27 | using std::map; |
| 28 | using std::string; |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 29 | using std::vector; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 30 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 31 | namespace chromeos_update_engine { |
| 32 | |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 33 | const char kProductionOmahaUrl[] = |
| 34 | "https://tools.google.com/service/update2"; |
| 35 | const char kAUTestOmahaUrl[] = |
| 36 | "https://omaha.sandbox.google.com/service/update2"; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 37 | |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 38 | const char OmahaRequestParams::kAppId[] = |
| 39 | "{87efface-864d-49a5-9bb3-4b050a7c227a}"; |
| 40 | const char OmahaRequestParams::kOsPlatform[] = "Chrome OS"; |
| 41 | const char OmahaRequestParams::kOsVersion[] = "Indy"; |
| 42 | const char OmahaRequestParams::kUpdateChannelKey[] = "CHROMEOS_RELEASE_TRACK"; |
| 43 | const char OmahaRequestParams::kIsPowerwashAllowedKey[] = |
| 44 | "CHROMEOS_IS_POWERWASH_ALLOWED"; |
| 45 | const char OmahaRequestParams::kAutoUpdateServerKey[] = "CHROMEOS_AUSERVER"; |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 46 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 47 | const char* kChannelsByStability[] = { |
| 48 | // This list has to be sorted from least stable to most stable channel. |
| 49 | "canary-channel", |
| 50 | "dev-channel", |
| 51 | "beta-channel", |
| 52 | "stable-channel", |
| 53 | }; |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 54 | |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 55 | bool OmahaRequestParams::Init(const string& in_app_version, |
| 56 | const string& in_update_url, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 57 | bool in_interactive) { |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 58 | LOG(INFO) << "Initializing parameters for this update attempt"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 59 | InitFromLsbValue(); |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 60 | bool stateful_override = !ShouldLockDown(); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 61 | os_platform_ = OmahaRequestParams::kOsPlatform; |
| 62 | os_version_ = OmahaRequestParams::kOsVersion; |
| 63 | app_version_ = in_app_version.empty() ? |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 64 | GetLsbValue("CHROMEOS_RELEASE_VERSION", "", nullptr, stateful_override) : |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 65 | in_app_version; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 66 | os_sp_ = app_version_ + "_" + GetMachineType(); |
| 67 | os_board_ = GetLsbValue("CHROMEOS_RELEASE_BOARD", |
| 68 | "", |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 69 | nullptr, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 70 | stateful_override); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 71 | string release_app_id = GetLsbValue("CHROMEOS_RELEASE_APPID", |
| 72 | OmahaRequestParams::kAppId, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 73 | nullptr, |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 74 | stateful_override); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 75 | board_app_id_ = GetLsbValue("CHROMEOS_BOARD_APPID", |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 76 | release_app_id, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 77 | nullptr, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 78 | stateful_override); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 79 | canary_app_id_ = GetLsbValue("CHROMEOS_CANARY_APPID", |
| 80 | release_app_id, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 81 | nullptr, |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 82 | stateful_override); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 83 | app_lang_ = "en-US"; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 84 | hwid_ = system_state_->hardware()->GetHardwareClass(); |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 85 | if (CollectECFWVersions()) { |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 86 | fw_version_ = system_state_->hardware()->GetFirmwareVersion(); |
| 87 | ec_version_ = system_state_->hardware()->GetECVersion(); |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 88 | } |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 89 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 90 | if (current_channel_ == target_channel_) { |
| 91 | // deltas are only okay if the /.nodelta file does not exist. if we don't |
| 92 | // know (i.e. stat() returns some unexpected error), then err on the side of |
| 93 | // caution and say deltas are not okay. |
| 94 | struct stat stbuf; |
| 95 | delta_okay_ = (stat((root_ + "/.nodelta").c_str(), &stbuf) < 0) && |
| 96 | (errno == ENOENT); |
| 97 | |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 98 | } else { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 99 | LOG(INFO) << "Disabling deltas as a channel change is pending"; |
| 100 | // For now, disable delta updates if the current channel is different from |
| 101 | // the channel that we're sending to the update server because such updates |
| 102 | // are destined to fail -- the current rootfs hash will be different than |
| 103 | // the expected hash due to the different channel in /etc/lsb-release. |
| 104 | delta_okay_ = false; |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 105 | } |
| 106 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 107 | if (in_update_url.empty()) |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 108 | update_url_ = GetLsbValue(kAutoUpdateServerKey, kProductionOmahaUrl, |
| 109 | nullptr, stateful_override); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 110 | else |
| 111 | update_url_ = in_update_url; |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 112 | |
| 113 | // Set the interactive flag accordingly. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 114 | interactive_ = in_interactive; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 115 | return true; |
| 116 | } |
| 117 | |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 118 | bool OmahaRequestParams::IsUpdateUrlOfficial() const { |
| 119 | return (update_url_ == kAUTestOmahaUrl || |
| 120 | update_url_ == GetLsbValue(kAutoUpdateServerKey, kProductionOmahaUrl, |
| 121 | nullptr, !ShouldLockDown())); |
| 122 | } |
| 123 | |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 124 | bool OmahaRequestParams::CollectECFWVersions() const { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 125 | return { |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 126 | StartsWithASCII(hwid_, string("SAMS ALEX"), true) || |
| 127 | StartsWithASCII(hwid_, string("BUTTERFLY"), true) || |
| 128 | StartsWithASCII(hwid_, string("LUMPY"), true) || |
| 129 | StartsWithASCII(hwid_, string("PARROT"), true) || |
| 130 | StartsWithASCII(hwid_, string("SPRING"), true) || |
| 131 | StartsWithASCII(hwid_, string("SNOW"), true) |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 132 | }; |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 135 | bool OmahaRequestParams::SetTargetChannel(const string& new_target_channel, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 136 | bool is_powerwash_allowed) { |
| 137 | LOG(INFO) << "SetTargetChannel called with " << new_target_channel |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 138 | << ", Is Powerwash Allowed = " |
| 139 | << utils::ToString(is_powerwash_allowed) |
| 140 | << ". Current channel = " << current_channel_ |
| 141 | << ", existing target channel = " << target_channel_ |
| 142 | << ", download channel = " << download_channel_; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 143 | TEST_AND_RETURN_FALSE(IsValidChannel(new_target_channel)); |
Alex Deymo | 2b4e2a5 | 2014-09-23 12:05:56 -0700 | [diff] [blame] | 144 | chromeos::KeyValueStore lsb_release; |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 145 | base::FilePath kFile(root_ + kStatefulPartition + "/etc/lsb-release"); |
Alex Deymo | a765844 | 2014-04-17 15:49:37 -0700 | [diff] [blame] | 146 | |
Alex Deymo | 2b4e2a5 | 2014-09-23 12:05:56 -0700 | [diff] [blame] | 147 | lsb_release.Load(kFile); |
Alex Deymo | a765844 | 2014-04-17 15:49:37 -0700 | [diff] [blame] | 148 | lsb_release.SetString(kUpdateChannelKey, new_target_channel); |
| 149 | lsb_release.SetBoolean(kIsPowerwashAllowedKey, is_powerwash_allowed); |
| 150 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 151 | TEST_AND_RETURN_FALSE(base::CreateDirectory(kFile.DirName())); |
Alex Deymo | 2b4e2a5 | 2014-09-23 12:05:56 -0700 | [diff] [blame] | 152 | TEST_AND_RETURN_FALSE(lsb_release.Save(kFile)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 153 | target_channel_ = new_target_channel; |
| 154 | is_powerwash_allowed_ = is_powerwash_allowed; |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 155 | return true; |
| 156 | } |
| 157 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 158 | void OmahaRequestParams::SetTargetChannelFromLsbValue() { |
| 159 | string target_channel_new_value = GetLsbValue( |
| 160 | kUpdateChannelKey, |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 161 | current_channel_, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 162 | &chromeos_update_engine::OmahaRequestParams::IsValidChannel, |
| 163 | true); // stateful_override |
| 164 | |
| 165 | if (target_channel_ != target_channel_new_value) { |
| 166 | target_channel_ = target_channel_new_value; |
| 167 | LOG(INFO) << "Target Channel set to " << target_channel_ |
| 168 | << " from LSB file"; |
| 169 | } |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 172 | void OmahaRequestParams::SetCurrentChannelFromLsbValue() { |
| 173 | string current_channel_new_value = GetLsbValue( |
| 174 | kUpdateChannelKey, |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 175 | current_channel_, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 176 | nullptr, // No need to validate the read-only rootfs channel. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 177 | false); // stateful_override is false so we get the current channel. |
| 178 | |
| 179 | if (current_channel_ != current_channel_new_value) { |
| 180 | current_channel_ = current_channel_new_value; |
| 181 | LOG(INFO) << "Current Channel set to " << current_channel_ |
| 182 | << " from LSB file in rootfs"; |
| 183 | } |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 184 | } |
| 185 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 186 | void OmahaRequestParams::SetIsPowerwashAllowedFromLsbValue() { |
| 187 | string is_powerwash_allowed_str = GetLsbValue( |
| 188 | kIsPowerwashAllowedKey, |
| 189 | "false", |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 190 | nullptr, // no need to validate |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 191 | true); // always get it from stateful, as that's the only place it'll be |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 192 | bool is_powerwash_allowed_new_value = (is_powerwash_allowed_str == "true"); |
| 193 | if (is_powerwash_allowed_ != is_powerwash_allowed_new_value) { |
| 194 | is_powerwash_allowed_ = is_powerwash_allowed_new_value; |
| 195 | LOG(INFO) << "Powerwash Allowed set to " |
| 196 | << utils::ToString(is_powerwash_allowed_) |
| 197 | << " from LSB file in stateful"; |
| 198 | } |
| 199 | } |
| 200 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 201 | void OmahaRequestParams::UpdateDownloadChannel() { |
| 202 | if (download_channel_ != target_channel_) { |
| 203 | download_channel_ = target_channel_; |
| 204 | LOG(INFO) << "Download channel for this attempt = " << download_channel_; |
| 205 | } |
| 206 | } |
| 207 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 208 | void OmahaRequestParams::InitFromLsbValue() { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 209 | SetCurrentChannelFromLsbValue(); |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 210 | SetTargetChannelFromLsbValue(); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 211 | SetIsPowerwashAllowedFromLsbValue(); |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 212 | UpdateDownloadChannel(); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | string OmahaRequestParams::GetLsbValue(const string& key, |
| 216 | const string& default_value, |
| 217 | ValueValidator validator, |
| 218 | bool stateful_override) const { |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 219 | vector<string> files; |
| 220 | if (stateful_override) { |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 221 | files.push_back(string(kStatefulPartition) + "/etc/lsb-release"); |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 222 | } |
| 223 | files.push_back("/etc/lsb-release"); |
| 224 | for (vector<string>::const_iterator it = files.begin(); |
| 225 | it != files.end(); ++it) { |
| 226 | // TODO(adlr): make sure files checked are owned as root (and all their |
| 227 | // parents are recursively, too). |
Alex Deymo | 2b4e2a5 | 2014-09-23 12:05:56 -0700 | [diff] [blame] | 228 | chromeos::KeyValueStore data; |
| 229 | if (!data.Load(base::FilePath(root_ + *it))) |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 230 | continue; |
| 231 | |
Alex Deymo | a765844 | 2014-04-17 15:49:37 -0700 | [diff] [blame] | 232 | string value; |
| 233 | if (data.GetString(key, &value)) { |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 234 | if (validator && !CALL_MEMBER_FN(*this, validator)(value)) { |
| 235 | continue; |
| 236 | } |
| 237 | return value; |
| 238 | } |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 239 | } |
| 240 | // not found |
| 241 | return default_value; |
| 242 | } |
| 243 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 244 | string OmahaRequestParams::GetMachineType() const { |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 245 | struct utsname buf; |
| 246 | string ret; |
| 247 | if (uname(&buf) == 0) |
| 248 | ret = buf.machine; |
| 249 | return ret; |
| 250 | } |
| 251 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 252 | bool OmahaRequestParams::ShouldLockDown() const { |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 253 | if (force_lock_down_) { |
| 254 | return forced_lock_down_; |
| 255 | } |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 256 | return system_state_->hardware()->IsOfficialBuild() && |
| 257 | system_state_->hardware()->IsNormalBootMode(); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 260 | bool OmahaRequestParams::IsValidChannel(const string& channel) const { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 261 | return GetChannelIndex(channel) >= 0; |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 264 | void OmahaRequestParams::set_root(const string& root) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 265 | root_ = root; |
| 266 | InitFromLsbValue(); |
| 267 | } |
| 268 | |
| 269 | void OmahaRequestParams::SetLockDown(bool lock) { |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 270 | force_lock_down_ = true; |
| 271 | forced_lock_down_ = lock; |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 274 | int OmahaRequestParams::GetChannelIndex(const string& channel) const { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 275 | for (size_t t = 0; t < arraysize(kChannelsByStability); ++t) |
| 276 | if (channel == kChannelsByStability[t]) |
| 277 | return t; |
| 278 | |
| 279 | return -1; |
| 280 | } |
| 281 | |
| 282 | bool OmahaRequestParams::to_more_stable_channel() const { |
| 283 | int current_channel_index = GetChannelIndex(current_channel_); |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 284 | int download_channel_index = GetChannelIndex(download_channel_); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 285 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 286 | return download_channel_index > current_channel_index; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 289 | string OmahaRequestParams::GetAppId() const { |
| 290 | return download_channel_ == "canary-channel" ? canary_app_id_ : board_app_id_; |
| 291 | } |
| 292 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 293 | } // namespace chromeos_update_engine |