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