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