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 | // |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 16 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 17 | #include "update_engine/omaha_request_action.h" |
Darin Petkov | 85ced13 | 2010-09-01 10:20:56 -0700 | [diff] [blame] | 18 | |
Andrew de los Reyes | 08c4e27 | 2010-04-15 14:02:17 -0700 | [diff] [blame] | 19 | #include <inttypes.h> |
Darin Petkov | 85ced13 | 2010-09-01 10:20:56 -0700 | [diff] [blame] | 20 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 21 | #include <map> |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 22 | #include <sstream> |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 23 | #include <string> |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 24 | #include <vector> |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 25 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 26 | #include <base/bind.h> |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 27 | #include <base/logging.h> |
| 28 | #include <base/rand_util.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 29 | #include <base/strings/string_number_conversions.h> |
| 30 | #include <base/strings/string_util.h> |
| 31 | #include <base/strings/stringprintf.h> |
| 32 | #include <base/time/time.h> |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 33 | #include <expat.h> |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 34 | |
| 35 | #include "update_engine/action_pipe.h" |
Alex Deymo | f6ee016 | 2015-07-31 12:35:22 -0700 | [diff] [blame] | 36 | #include "update_engine/connection_manager.h" |
Jay Srinivasan | d29695d | 2013-04-08 15:08:05 -0700 | [diff] [blame] | 37 | #include "update_engine/constants.h" |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 38 | #include "update_engine/hardware_interface.h" |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 39 | #include "update_engine/omaha_hash_calculator.h" |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 40 | #include "update_engine/omaha_request_params.h" |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 41 | #include "update_engine/p2p_manager.h" |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 42 | #include "update_engine/payload_state_interface.h" |
Alex Deymo | ac41a82 | 2015-09-15 20:52:53 -0700 | [diff] [blame] | 43 | #include "update_engine/platform_constants.h" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 44 | #include "update_engine/prefs_interface.h" |
adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 45 | #include "update_engine/utils.h" |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 46 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 47 | using base::Time; |
| 48 | using base::TimeDelta; |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 49 | using std::map; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 50 | using std::string; |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 51 | using std::vector; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 52 | |
| 53 | namespace chromeos_update_engine { |
| 54 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 55 | // List of custom pair tags that we interpret in the Omaha Response: |
| 56 | static const char* kTagDeadline = "deadline"; |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 57 | static const char* kTagDisablePayloadBackoff = "DisablePayloadBackoff"; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 58 | static const char* kTagVersion = "version"; |
Jay Srinivasan | d671e97 | 2013-01-11 17:17:19 -0800 | [diff] [blame] | 59 | // Deprecated: "IsDelta" |
| 60 | static const char* kTagIsDeltaPayload = "IsDeltaPayload"; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 61 | static const char* kTagMaxFailureCountPerUrl = "MaxFailureCountPerUrl"; |
| 62 | static const char* kTagMaxDaysToScatter = "MaxDaysToScatter"; |
| 63 | // Deprecated: "ManifestSignatureRsa" |
| 64 | // Deprecated: "ManifestSize" |
| 65 | static const char* kTagMetadataSignatureRsa = "MetadataSignatureRsa"; |
| 66 | static const char* kTagMetadataSize = "MetadataSize"; |
| 67 | static const char* kTagMoreInfo = "MoreInfo"; |
Don Garrett | 42bd3aa | 2013-04-10 18:14:56 -0700 | [diff] [blame] | 68 | // Deprecated: "NeedsAdmin" |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 69 | static const char* kTagPrompt = "Prompt"; |
| 70 | static const char* kTagSha256 = "sha256"; |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 71 | static const char* kTagDisableP2PForDownloading = "DisableP2PForDownloading"; |
| 72 | static const char* kTagDisableP2PForSharing = "DisableP2PForSharing"; |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 73 | static const char* kTagPublicKeyRsa = "PublicKeyRsa"; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 74 | |
Alex Deymo | ac41a82 | 2015-09-15 20:52:53 -0700 | [diff] [blame] | 75 | static const char* kOmahaUpdaterVersion = "0.1.0.0"; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 76 | |
Alex Deymo | ac41a82 | 2015-09-15 20:52:53 -0700 | [diff] [blame] | 77 | namespace { |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 78 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 79 | // Returns an XML ping element attribute assignment with attribute |
| 80 | // |name| and value |ping_days| if |ping_days| has a value that needs |
| 81 | // to be sent, or an empty string otherwise. |
| 82 | string GetPingAttribute(const string& name, int ping_days) { |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 83 | if (ping_days > 0 || ping_days == OmahaRequestAction::kNeverPinged) |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 84 | return base::StringPrintf(" %s=\"%d\"", name.c_str(), ping_days); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 85 | return ""; |
| 86 | } |
| 87 | |
| 88 | // Returns an XML ping element if any of the elapsed days need to be |
| 89 | // sent, or an empty string otherwise. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 90 | string GetPingXml(int ping_active_days, int ping_roll_call_days) { |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 91 | string ping_active = GetPingAttribute("a", ping_active_days); |
| 92 | string ping_roll_call = GetPingAttribute("r", ping_roll_call_days); |
| 93 | if (!ping_active.empty() || !ping_roll_call.empty()) { |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 94 | return base::StringPrintf(" <ping active=\"1\"%s%s></ping>\n", |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 95 | ping_active.c_str(), |
| 96 | ping_roll_call.c_str()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 97 | } |
| 98 | return ""; |
| 99 | } |
| 100 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 101 | // Returns an XML that goes into the body of the <app> element of the Omaha |
| 102 | // request based on the given parameters. |
| 103 | string GetAppBody(const OmahaEvent* event, |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 104 | OmahaRequestParams* params, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 105 | bool ping_only, |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 106 | bool include_ping, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 107 | int ping_active_days, |
| 108 | int ping_roll_call_days, |
| 109 | PrefsInterface* prefs) { |
| 110 | string app_body; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 111 | if (event == nullptr) { |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 112 | if (include_ping) |
| 113 | app_body = GetPingXml(ping_active_days, ping_roll_call_days); |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 114 | if (!ping_only) { |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 115 | app_body += base::StringPrintf( |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 116 | " <updatecheck targetversionprefix=\"%s\"" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 117 | "></updatecheck>\n", |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 118 | XmlEncodeWithDefault(params->target_version_prefix(), "").c_str()); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 119 | |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 120 | // If this is the first update check after a reboot following a previous |
| 121 | // update, generate an event containing the previous version number. If |
| 122 | // the previous version preference file doesn't exist the event is still |
| 123 | // generated with a previous version of 0.0.0.0 -- this is relevant for |
| 124 | // older clients or new installs. The previous version event is not sent |
| 125 | // for ping-only requests because they come before the client has |
| 126 | // rebooted. |
| 127 | string prev_version; |
| 128 | if (!prefs->GetString(kPrefsPreviousVersion, &prev_version)) { |
| 129 | prev_version = "0.0.0.0"; |
| 130 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 131 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 132 | app_body += base::StringPrintf( |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 133 | " <event eventtype=\"%d\" eventresult=\"%d\" " |
| 134 | "previousversion=\"%s\"></event>\n", |
| 135 | OmahaEvent::kTypeUpdateComplete, |
| 136 | OmahaEvent::kResultSuccessReboot, |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 137 | XmlEncodeWithDefault(prev_version, "0.0.0.0").c_str()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 138 | LOG_IF(WARNING, !prefs->SetString(kPrefsPreviousVersion, "")) |
| 139 | << "Unable to reset the previous version."; |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 140 | } |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 141 | } else { |
Darin Petkov | c91dd6b | 2011-01-10 12:31:34 -0800 | [diff] [blame] | 142 | // The error code is an optional attribute so append it only if the result |
| 143 | // is not success. |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 144 | string error_code; |
| 145 | if (event->result != OmahaEvent::kResultSuccess) { |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 146 | error_code = base::StringPrintf(" errorcode=\"%d\"", |
| 147 | static_cast<int>(event->error_code)); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 148 | } |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 149 | app_body = base::StringPrintf( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 150 | " <event eventtype=\"%d\" eventresult=\"%d\"%s></event>\n", |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 151 | event->type, event->result, error_code.c_str()); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 152 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 153 | |
| 154 | return app_body; |
| 155 | } |
| 156 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 157 | // Returns the cohort* argument to include in the <app> tag for the passed |
| 158 | // |arg_name| and |prefs_key|, if any. The return value is suitable to |
| 159 | // concatenate to the list of arguments and includes a space at the end. |
| 160 | string GetCohortArgXml(PrefsInterface* prefs, |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 161 | const string arg_name, |
| 162 | const string prefs_key) { |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 163 | // There's nothing wrong with not having a given cohort setting, so we check |
| 164 | // existance first to avoid the warning log message. |
| 165 | if (!prefs->Exists(prefs_key)) |
| 166 | return ""; |
| 167 | string cohort_value; |
| 168 | if (!prefs->GetString(prefs_key, &cohort_value) || cohort_value.empty()) |
| 169 | return ""; |
| 170 | // This is a sanity check to avoid sending a huge XML file back to Ohama due |
| 171 | // to a compromised stateful partition making the update check fail in low |
| 172 | // network environments envent after a reboot. |
| 173 | if (cohort_value.size() > 1024) { |
| 174 | LOG(WARNING) << "The omaha cohort setting " << arg_name |
| 175 | << " has a too big value, which must be an error or an " |
| 176 | "attacker trying to inhibit updates."; |
| 177 | return ""; |
| 178 | } |
| 179 | |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 180 | string escaped_xml_value; |
| 181 | if (!XmlEncode(cohort_value, &escaped_xml_value)) { |
| 182 | LOG(WARNING) << "The omaha cohort setting " << arg_name |
| 183 | << " is ASCII-7 invalid, ignoring it."; |
| 184 | return ""; |
| 185 | } |
| 186 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 187 | return base::StringPrintf("%s=\"%s\" ", |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 188 | arg_name.c_str(), escaped_xml_value.c_str()); |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 191 | // Returns an XML that corresponds to the entire <app> node of the Omaha |
| 192 | // request based on the given parameters. |
| 193 | string GetAppXml(const OmahaEvent* event, |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 194 | OmahaRequestParams* params, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 195 | bool ping_only, |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 196 | bool include_ping, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 197 | int ping_active_days, |
| 198 | int ping_roll_call_days, |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 199 | int install_date_in_days, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 200 | SystemState* system_state) { |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 201 | string app_body = GetAppBody(event, params, ping_only, include_ping, |
| 202 | ping_active_days, ping_roll_call_days, |
| 203 | system_state->prefs()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 204 | string app_versions; |
| 205 | |
| 206 | // If we are upgrading to a more stable channel and we are allowed to do |
| 207 | // powerwash, then pass 0.0.0.0 as the version. This is needed to get the |
| 208 | // highest-versioned payload on the destination channel. |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 209 | if (params->to_more_stable_channel() && params->is_powerwash_allowed()) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 210 | LOG(INFO) << "Passing OS version as 0.0.0.0 as we are set to powerwash " |
| 211 | << "on downgrading to the version in the more stable channel"; |
| 212 | app_versions = "version=\"0.0.0.0\" from_version=\"" + |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 213 | XmlEncodeWithDefault(params->app_version(), "0.0.0.0") + "\" "; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 214 | } else { |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 215 | app_versions = "version=\"" + |
| 216 | XmlEncodeWithDefault(params->app_version(), "0.0.0.0") + "\" "; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 219 | string download_channel = params->download_channel(); |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 220 | string app_channels = |
| 221 | "track=\"" + XmlEncodeWithDefault(download_channel, "") + "\" "; |
| 222 | if (params->current_channel() != download_channel) { |
| 223 | app_channels += "from_track=\"" + XmlEncodeWithDefault( |
| 224 | params->current_channel(), "") + "\" "; |
| 225 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 226 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 227 | string delta_okay_str = params->delta_okay() ? "true" : "false"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 228 | |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 229 | // If install_date_days is not set (e.g. its value is -1 ), don't |
| 230 | // include the attribute. |
| 231 | string install_date_in_days_str = ""; |
| 232 | if (install_date_in_days >= 0) { |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 233 | install_date_in_days_str = base::StringPrintf("installdate=\"%d\" ", |
| 234 | install_date_in_days); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 237 | string app_cohort_args; |
| 238 | app_cohort_args += GetCohortArgXml(system_state->prefs(), |
| 239 | "cohort", kPrefsOmahaCohort); |
| 240 | app_cohort_args += GetCohortArgXml(system_state->prefs(), |
| 241 | "cohorthint", kPrefsOmahaCohortHint); |
| 242 | app_cohort_args += GetCohortArgXml(system_state->prefs(), |
| 243 | "cohortname", kPrefsOmahaCohortName); |
| 244 | |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 245 | string app_xml = " <app " |
| 246 | "appid=\"" + XmlEncodeWithDefault(params->GetAppId(), "") + "\" " + |
| 247 | app_cohort_args + |
| 248 | app_versions + |
| 249 | app_channels + |
| 250 | "lang=\"" + XmlEncodeWithDefault(params->app_lang(), "en-US") + "\" " + |
| 251 | "board=\"" + XmlEncodeWithDefault(params->os_board(), "") + "\" " + |
| 252 | "hardware_class=\"" + XmlEncodeWithDefault(params->hwid(), "") + "\" " + |
| 253 | "delta_okay=\"" + delta_okay_str + "\" " |
| 254 | "fw_version=\"" + XmlEncodeWithDefault(params->fw_version(), "") + "\" " + |
| 255 | "ec_version=\"" + XmlEncodeWithDefault(params->ec_version(), "") + "\" " + |
| 256 | install_date_in_days_str + |
| 257 | ">\n" + |
| 258 | app_body + |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 259 | " </app>\n"; |
| 260 | |
| 261 | return app_xml; |
| 262 | } |
| 263 | |
| 264 | // Returns an XML that corresponds to the entire <os> node of the Omaha |
| 265 | // request based on the given parameters. |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 266 | string GetOsXml(OmahaRequestParams* params) { |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 267 | string os_xml =" <os " |
| 268 | "version=\"" + XmlEncodeWithDefault(params->os_version(), "") + "\" " + |
| 269 | "platform=\"" + XmlEncodeWithDefault(params->os_platform(), "") + "\" " + |
| 270 | "sp=\"" + XmlEncodeWithDefault(params->os_sp(), "") + "\">" |
| 271 | "</os>\n"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 272 | return os_xml; |
| 273 | } |
| 274 | |
| 275 | // Returns an XML that corresponds to the entire Omaha request based on the |
| 276 | // given parameters. |
| 277 | string GetRequestXml(const OmahaEvent* event, |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 278 | OmahaRequestParams* params, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 279 | bool ping_only, |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 280 | bool include_ping, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 281 | int ping_active_days, |
| 282 | int ping_roll_call_days, |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 283 | int install_date_in_days, |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 284 | SystemState* system_state) { |
| 285 | string os_xml = GetOsXml(params); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 286 | string app_xml = GetAppXml(event, params, ping_only, include_ping, |
| 287 | ping_active_days, ping_roll_call_days, |
| 288 | install_date_in_days, system_state); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 289 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 290 | string install_source = base::StringPrintf("installsource=\"%s\" ", |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 291 | (params->interactive() ? "ondemandupdate" : "scheduler")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 292 | |
Alex Deymo | ac41a82 | 2015-09-15 20:52:53 -0700 | [diff] [blame] | 293 | string updater_version = XmlEncodeWithDefault( |
| 294 | base::StringPrintf("%s-%s", |
| 295 | constants::kOmahaUpdaterID, |
| 296 | kOmahaUpdaterVersion), ""); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 297 | string request_xml = |
| 298 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 299 | "<request protocol=\"3.0\" " + ( |
Alex Deymo | ac41a82 | 2015-09-15 20:52:53 -0700 | [diff] [blame] | 300 | "version=\"" + updater_version + "\" " |
| 301 | "updaterversion=\"" + updater_version + "\" " + |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 302 | install_source + |
| 303 | "ismachine=\"1\">\n") + |
| 304 | os_xml + |
| 305 | app_xml + |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 306 | "</request>\n"; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 307 | |
| 308 | return request_xml; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 309 | } |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 310 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 311 | } // namespace |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 312 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 313 | // Struct used for holding data obtained when parsing the XML. |
| 314 | struct OmahaParserData { |
David Zeuthen | f3e2801 | 2014-08-26 18:23:52 -0400 | [diff] [blame] | 315 | explicit OmahaParserData(XML_Parser _xml_parser) : xml_parser(_xml_parser) {} |
| 316 | |
| 317 | // Pointer to the expat XML_Parser object. |
| 318 | XML_Parser xml_parser; |
| 319 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 320 | // This is the state of the parser as it's processing the XML. |
| 321 | bool failed = false; |
David Zeuthen | f3e2801 | 2014-08-26 18:23:52 -0400 | [diff] [blame] | 322 | bool entity_decl = false; |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 323 | string current_path; |
| 324 | |
| 325 | // These are the values extracted from the XML. |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 326 | string app_cohort; |
| 327 | string app_cohorthint; |
| 328 | string app_cohortname; |
| 329 | bool app_cohort_set = false; |
| 330 | bool app_cohorthint_set = false; |
| 331 | bool app_cohortname_set = false; |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 332 | string updatecheck_status; |
| 333 | string updatecheck_poll_interval; |
| 334 | string daystart_elapsed_days; |
| 335 | string daystart_elapsed_seconds; |
| 336 | vector<string> url_codebase; |
| 337 | string package_name; |
| 338 | string package_size; |
| 339 | string manifest_version; |
| 340 | map<string, string> action_postinstall_attrs; |
| 341 | }; |
| 342 | |
| 343 | namespace { |
| 344 | |
| 345 | // Callback function invoked by expat. |
| 346 | void ParserHandlerStart(void* user_data, const XML_Char* element, |
| 347 | const XML_Char** attr) { |
| 348 | OmahaParserData* data = reinterpret_cast<OmahaParserData*>(user_data); |
| 349 | |
| 350 | if (data->failed) |
| 351 | return; |
| 352 | |
| 353 | data->current_path += string("/") + element; |
| 354 | |
| 355 | map<string, string> attrs; |
| 356 | if (attr != nullptr) { |
| 357 | for (int n = 0; attr[n] != nullptr && attr[n+1] != nullptr; n += 2) { |
| 358 | string key = attr[n]; |
| 359 | string value = attr[n + 1]; |
| 360 | attrs[key] = value; |
| 361 | } |
| 362 | } |
| 363 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 364 | if (data->current_path == "/response/app") { |
| 365 | if (attrs.find("cohort") != attrs.end()) { |
| 366 | data->app_cohort_set = true; |
| 367 | data->app_cohort = attrs["cohort"]; |
| 368 | } |
| 369 | if (attrs.find("cohorthint") != attrs.end()) { |
| 370 | data->app_cohorthint_set = true; |
| 371 | data->app_cohorthint = attrs["cohorthint"]; |
| 372 | } |
| 373 | if (attrs.find("cohortname") != attrs.end()) { |
| 374 | data->app_cohortname_set = true; |
| 375 | data->app_cohortname = attrs["cohortname"]; |
| 376 | } |
| 377 | } else if (data->current_path == "/response/app/updatecheck") { |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 378 | // There is only supposed to be a single <updatecheck> element. |
| 379 | data->updatecheck_status = attrs["status"]; |
| 380 | data->updatecheck_poll_interval = attrs["PollInterval"]; |
| 381 | } else if (data->current_path == "/response/daystart") { |
| 382 | // Get the install-date. |
| 383 | data->daystart_elapsed_days = attrs["elapsed_days"]; |
| 384 | data->daystart_elapsed_seconds = attrs["elapsed_seconds"]; |
| 385 | } else if (data->current_path == "/response/app/updatecheck/urls/url") { |
| 386 | // Look at all <url> elements. |
| 387 | data->url_codebase.push_back(attrs["codebase"]); |
| 388 | } else if (data->package_name.empty() && data->current_path == |
| 389 | "/response/app/updatecheck/manifest/packages/package") { |
| 390 | // Only look at the first <package>. |
| 391 | data->package_name = attrs["name"]; |
| 392 | data->package_size = attrs["size"]; |
| 393 | } else if (data->current_path == "/response/app/updatecheck/manifest") { |
| 394 | // Get the version. |
| 395 | data->manifest_version = attrs[kTagVersion]; |
| 396 | } else if (data->current_path == |
| 397 | "/response/app/updatecheck/manifest/actions/action") { |
| 398 | // We only care about the postinstall action. |
| 399 | if (attrs["event"] == "postinstall") { |
| 400 | data->action_postinstall_attrs = attrs; |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | // Callback function invoked by expat. |
| 406 | void ParserHandlerEnd(void* user_data, const XML_Char* element) { |
| 407 | OmahaParserData* data = reinterpret_cast<OmahaParserData*>(user_data); |
| 408 | if (data->failed) |
| 409 | return; |
| 410 | |
| 411 | const string path_suffix = string("/") + element; |
| 412 | |
Alex Vakulenko | 6a9d349 | 2015-06-15 12:53:22 -0700 | [diff] [blame] | 413 | if (!base::EndsWith(data->current_path, path_suffix, true)) { |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 414 | LOG(ERROR) << "Unexpected end element '" << element |
| 415 | << "' with current_path='" << data->current_path << "'"; |
| 416 | data->failed = true; |
| 417 | return; |
| 418 | } |
| 419 | data->current_path.resize(data->current_path.size() - path_suffix.size()); |
| 420 | } |
| 421 | |
David Zeuthen | f3e2801 | 2014-08-26 18:23:52 -0400 | [diff] [blame] | 422 | // Callback function invoked by expat. |
| 423 | // |
| 424 | // This is called for entity declarations. Since Omaha is guaranteed |
| 425 | // to never return any XML with entities our course of action is to |
| 426 | // just stop parsing. This avoids potential resource exhaustion |
| 427 | // problems AKA the "billion laughs". CVE-2013-0340. |
| 428 | void ParserHandlerEntityDecl(void *user_data, |
| 429 | const XML_Char *entity_name, |
| 430 | int is_parameter_entity, |
| 431 | const XML_Char *value, |
| 432 | int value_length, |
| 433 | const XML_Char *base, |
| 434 | const XML_Char *system_id, |
| 435 | const XML_Char *public_id, |
| 436 | const XML_Char *notation_name) { |
| 437 | OmahaParserData* data = reinterpret_cast<OmahaParserData*>(user_data); |
| 438 | |
| 439 | LOG(ERROR) << "XML entities are not supported. Aborting parsing."; |
| 440 | data->failed = true; |
| 441 | data->entity_decl = true; |
| 442 | XML_StopParser(data->xml_parser, false); |
| 443 | } |
| 444 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 445 | } // namespace |
| 446 | |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 447 | bool XmlEncode(const string& input, string* output) { |
| 448 | if (std::find_if(input.begin(), input.end(), |
| 449 | [](const char c){return c & 0x80;}) != input.end()) { |
| 450 | LOG(WARNING) << "Invalid ASCII-7 string passed to the XML encoder:"; |
| 451 | utils::HexDumpString(input); |
| 452 | return false; |
| 453 | } |
Alex Deymo | cc45785 | 2015-06-18 18:35:50 -0700 | [diff] [blame] | 454 | output->clear(); |
| 455 | // We need at least input.size() space in the output, but the code below will |
| 456 | // handle it if we need more. |
| 457 | output->reserve(input.size()); |
| 458 | for (char c : input) { |
| 459 | switch (c) { |
| 460 | case '\"': |
| 461 | output->append("""); |
| 462 | break; |
| 463 | case '\'': |
| 464 | output->append("'"); |
| 465 | break; |
| 466 | case '&': |
| 467 | output->append("&"); |
| 468 | break; |
| 469 | case '<': |
| 470 | output->append("<"); |
| 471 | break; |
| 472 | case '>': |
| 473 | output->append(">"); |
| 474 | break; |
| 475 | default: |
| 476 | output->push_back(c); |
| 477 | } |
| 478 | } |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 479 | return true; |
| 480 | } |
| 481 | |
| 482 | string XmlEncodeWithDefault(const string& input, const string& default_value) { |
| 483 | string output; |
| 484 | if (XmlEncode(input, &output)) |
| 485 | return output; |
| 486 | return default_value; |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 489 | OmahaRequestAction::OmahaRequestAction(SystemState* system_state, |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 490 | OmahaEvent* event, |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 491 | HttpFetcher* http_fetcher, |
| 492 | bool ping_only) |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 493 | : system_state_(system_state), |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 494 | event_(event), |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 495 | http_fetcher_(http_fetcher), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 496 | ping_only_(ping_only), |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 497 | ping_active_days_(0), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 498 | ping_roll_call_days_(0) { |
| 499 | params_ = system_state->request_params(); |
| 500 | } |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 501 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 502 | OmahaRequestAction::~OmahaRequestAction() {} |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 503 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 504 | // Calculates the value to use for the ping days parameter. |
| 505 | int OmahaRequestAction::CalculatePingDays(const string& key) { |
| 506 | int days = kNeverPinged; |
| 507 | int64_t last_ping = 0; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 508 | if (system_state_->prefs()->GetInt64(key, &last_ping) && last_ping >= 0) { |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 509 | days = (Time::Now() - Time::FromInternalValue(last_ping)).InDays(); |
| 510 | if (days < 0) { |
| 511 | // If |days| is negative, then the system clock must have jumped |
| 512 | // back in time since the ping was sent. Mark the value so that |
| 513 | // it doesn't get sent to the server but we still update the |
| 514 | // last ping daystart preference. This way the next ping time |
| 515 | // will be correct, hopefully. |
| 516 | days = kPingTimeJump; |
| 517 | LOG(WARNING) << |
| 518 | "System clock jumped back in time. Resetting ping daystarts."; |
| 519 | } |
| 520 | } |
| 521 | return days; |
| 522 | } |
| 523 | |
| 524 | void OmahaRequestAction::InitPingDays() { |
| 525 | // We send pings only along with update checks, not with events. |
| 526 | if (IsEvent()) { |
| 527 | return; |
| 528 | } |
| 529 | // TODO(petkov): Figure a way to distinguish active use pings |
| 530 | // vs. roll call pings. Currently, the two pings are identical. A |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 531 | // fix needs to change this code as well as UpdateLastPingDays and ShouldPing. |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 532 | ping_active_days_ = CalculatePingDays(kPrefsLastActivePingDay); |
| 533 | ping_roll_call_days_ = CalculatePingDays(kPrefsLastRollCallPingDay); |
| 534 | } |
| 535 | |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 536 | bool OmahaRequestAction::ShouldPing() const { |
| 537 | if (ping_active_days_ == OmahaRequestAction::kNeverPinged && |
| 538 | ping_roll_call_days_ == OmahaRequestAction::kNeverPinged) { |
| 539 | int powerwash_count = system_state_->hardware()->GetPowerwashCount(); |
| 540 | if (powerwash_count > 0) { |
| 541 | LOG(INFO) << "Not sending ping with a=-1 r=-1 to omaha because " |
| 542 | << "powerwash_count is " << powerwash_count; |
| 543 | return false; |
| 544 | } |
| 545 | return true; |
| 546 | } |
| 547 | return ping_active_days_ > 0 || ping_roll_call_days_ > 0; |
| 548 | } |
| 549 | |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 550 | // static |
| 551 | int OmahaRequestAction::GetInstallDate(SystemState* system_state) { |
| 552 | PrefsInterface* prefs = system_state->prefs(); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 553 | if (prefs == nullptr) |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 554 | return -1; |
| 555 | |
| 556 | // If we have the value stored on disk, just return it. |
| 557 | int64_t stored_value; |
| 558 | if (prefs->GetInt64(kPrefsInstallDateDays, &stored_value)) { |
| 559 | // Convert and sanity-check. |
| 560 | int install_date_days = static_cast<int>(stored_value); |
| 561 | if (install_date_days >= 0) |
| 562 | return install_date_days; |
| 563 | LOG(ERROR) << "Dropping stored Omaha InstallData since its value num_days=" |
| 564 | << install_date_days << " looks suspicious."; |
| 565 | prefs->Delete(kPrefsInstallDateDays); |
| 566 | } |
| 567 | |
| 568 | // Otherwise, if OOBE is not complete then do nothing and wait for |
| 569 | // ParseResponse() to call ParseInstallDate() and then |
| 570 | // PersistInstallDate() to set the kPrefsInstallDateDays state |
| 571 | // variable. Once that is done, we'll then report back in future |
| 572 | // Omaha requests. This works exactly because OOBE triggers an |
| 573 | // update check. |
| 574 | // |
| 575 | // However, if OOBE is complete and the kPrefsInstallDateDays state |
| 576 | // variable is not set, there are two possibilities |
| 577 | // |
| 578 | // 1. The update check in OOBE failed so we never got a response |
| 579 | // from Omaha (no network etc.); or |
| 580 | // |
| 581 | // 2. OOBE was done on an older version that didn't write to the |
| 582 | // kPrefsInstallDateDays state variable. |
| 583 | // |
| 584 | // In both cases, we approximate the install date by simply |
| 585 | // inspecting the timestamp of when OOBE happened. |
| 586 | |
| 587 | Time time_of_oobe; |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 588 | if (!system_state->hardware()->IsOOBEComplete(&time_of_oobe)) { |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 589 | LOG(INFO) << "Not generating Omaha InstallData as we have " |
| 590 | << "no prefs file and OOBE is not complete."; |
| 591 | return -1; |
| 592 | } |
| 593 | |
| 594 | int num_days; |
| 595 | if (!utils::ConvertToOmahaInstallDate(time_of_oobe, &num_days)) { |
| 596 | LOG(ERROR) << "Not generating Omaha InstallData from time of OOBE " |
| 597 | << "as its value '" << utils::ToString(time_of_oobe) |
| 598 | << "' looks suspicious."; |
| 599 | return -1; |
| 600 | } |
| 601 | |
| 602 | // Persist this to disk, for future use. |
| 603 | if (!OmahaRequestAction::PersistInstallDate(system_state, |
| 604 | num_days, |
| 605 | kProvisionedFromOOBEMarker)) |
| 606 | return -1; |
| 607 | |
| 608 | LOG(INFO) << "Set the Omaha InstallDate from OOBE time-stamp to " |
| 609 | << num_days << " days"; |
| 610 | |
| 611 | return num_days; |
| 612 | } |
| 613 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 614 | void OmahaRequestAction::PerformAction() { |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 615 | http_fetcher_->set_delegate(this); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 616 | InitPingDays(); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 617 | if (ping_only_ && !ShouldPing()) { |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 618 | processor_->ActionComplete(this, ErrorCode::kSuccess); |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 619 | return; |
| 620 | } |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 621 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 622 | string request_post(GetRequestXml(event_.get(), |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 623 | params_, |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 624 | ping_only_, |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 625 | ShouldPing(), // include_ping |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 626 | ping_active_days_, |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 627 | ping_roll_call_days_, |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 628 | GetInstallDate(system_state_), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 629 | system_state_)); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 630 | |
Gilad Arnold | 9dd1e7c | 2012-02-16 12:13:36 -0800 | [diff] [blame] | 631 | http_fetcher_->SetPostData(request_post.data(), request_post.size(), |
| 632 | kHttpContentTypeTextXml); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 633 | LOG(INFO) << "Posting an Omaha request to " << params_->update_url(); |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 634 | LOG(INFO) << "Request: " << request_post; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 635 | http_fetcher_->BeginTransfer(params_->update_url()); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 638 | void OmahaRequestAction::TerminateProcessing() { |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 639 | http_fetcher_->TerminateTransfer(); |
| 640 | } |
| 641 | |
| 642 | // We just store the response in the buffer. Once we've received all bytes, |
| 643 | // we'll look in the buffer and decide what to do. |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 644 | void OmahaRequestAction::ReceivedBytes(HttpFetcher *fetcher, |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 645 | const void* bytes, |
| 646 | size_t length) { |
| 647 | const uint8_t* byte_ptr = reinterpret_cast<const uint8_t*>(bytes); |
| 648 | response_buffer_.insert(response_buffer_.end(), byte_ptr, byte_ptr + length); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | namespace { |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 652 | |
| 653 | // Parses a 64 bit base-10 int from a string and returns it. Returns 0 |
| 654 | // on error. If the string contains "0", that's indistinguishable from |
| 655 | // error. |
| 656 | off_t ParseInt(const string& str) { |
| 657 | off_t ret = 0; |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 658 | int rc = sscanf(str.c_str(), "%" PRIi64, &ret); // NOLINT(runtime/printf) |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 659 | if (rc < 1) { |
| 660 | // failure |
| 661 | return 0; |
| 662 | } |
| 663 | return ret; |
| 664 | } |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 665 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 666 | // Parses |str| and returns |true| if, and only if, its value is "true". |
| 667 | bool ParseBool(const string& str) { |
| 668 | return str == "true"; |
| 669 | } |
| 670 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 671 | // Update the last ping day preferences based on the server daystart |
| 672 | // response. Returns true on success, false otherwise. |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 673 | bool UpdateLastPingDays(OmahaParserData *parser_data, PrefsInterface* prefs) { |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 674 | int64_t elapsed_seconds = 0; |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 675 | TEST_AND_RETURN_FALSE( |
| 676 | base::StringToInt64(parser_data->daystart_elapsed_seconds, |
| 677 | &elapsed_seconds)); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 678 | TEST_AND_RETURN_FALSE(elapsed_seconds >= 0); |
| 679 | |
| 680 | // Remember the local time that matches the server's last midnight |
| 681 | // time. |
| 682 | Time daystart = Time::Now() - TimeDelta::FromSeconds(elapsed_seconds); |
| 683 | prefs->SetInt64(kPrefsLastActivePingDay, daystart.ToInternalValue()); |
| 684 | prefs->SetInt64(kPrefsLastRollCallPingDay, daystart.ToInternalValue()); |
| 685 | return true; |
| 686 | } |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 687 | } // namespace |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 688 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 689 | bool OmahaRequestAction::ParseResponse(OmahaParserData* parser_data, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 690 | OmahaResponse* output_object, |
| 691 | ScopedActionCompleter* completer) { |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 692 | if (parser_data->updatecheck_status.empty()) { |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 693 | completer->set_code(ErrorCode::kOmahaResponseInvalid); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 694 | return false; |
| 695 | } |
| 696 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 697 | // chromium-os:37289: The PollInterval is not supported by Omaha server |
| 698 | // currently. But still keeping this existing code in case we ever decide to |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 699 | // slow down the request rate from the server-side. Note that the PollInterval |
| 700 | // is not persisted, so it has to be sent by the server on every response to |
| 701 | // guarantee that the scheduler uses this value (otherwise, if the device got |
| 702 | // rebooted after the last server-indicated value, it'll revert to the default |
| 703 | // value). Also kDefaultMaxUpdateChecks value for the scattering logic is |
| 704 | // based on the assumption that we perform an update check every hour so that |
| 705 | // the max value of 8 will roughly be equivalent to one work day. If we decide |
| 706 | // to use PollInterval permanently, we should update the |
| 707 | // max_update_checks_allowed to take PollInterval into account. Note: The |
| 708 | // parsing for PollInterval happens even before parsing of the status because |
| 709 | // we may want to specify the PollInterval even when there's no update. |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 710 | base::StringToInt(parser_data->updatecheck_poll_interval, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 711 | &output_object->poll_interval); |
| 712 | |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 713 | // Check for the "elapsed_days" attribute in the "daystart" |
| 714 | // element. This is the number of days since Jan 1 2007, 0:00 |
| 715 | // PST. If we don't have a persisted value of the Omaha InstallDate, |
| 716 | // we'll use it to calculate it and then persist it. |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 717 | if (ParseInstallDate(parser_data, output_object) && |
| 718 | !HasInstallDate(system_state_)) { |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 719 | // Since output_object->install_date_days is never negative, the |
| 720 | // elapsed_days -> install-date calculation is reduced to simply |
| 721 | // rounding down to the nearest number divisible by 7. |
| 722 | int remainder = output_object->install_date_days % 7; |
| 723 | int install_date_days_rounded = |
| 724 | output_object->install_date_days - remainder; |
| 725 | if (PersistInstallDate(system_state_, |
| 726 | install_date_days_rounded, |
| 727 | kProvisionedFromOmahaResponse)) { |
| 728 | LOG(INFO) << "Set the Omaha InstallDate from Omaha Response to " |
| 729 | << install_date_days_rounded << " days"; |
| 730 | } |
| 731 | } |
| 732 | |
Alex Deymo | 00d79ac | 2015-06-29 15:41:49 -0700 | [diff] [blame] | 733 | // We persist the cohorts sent by omaha even if the status is "noupdate". |
| 734 | if (parser_data->app_cohort_set) |
| 735 | PersistCohortData(kPrefsOmahaCohort, parser_data->app_cohort); |
| 736 | if (parser_data->app_cohorthint_set) |
| 737 | PersistCohortData(kPrefsOmahaCohortHint, parser_data->app_cohorthint); |
| 738 | if (parser_data->app_cohortname_set) |
| 739 | PersistCohortData(kPrefsOmahaCohortName, parser_data->app_cohortname); |
| 740 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 741 | if (!ParseStatus(parser_data, output_object, completer)) |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 742 | return false; |
| 743 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 744 | // Note: ParseUrls MUST be called before ParsePackage as ParsePackage |
| 745 | // appends the package name to the URLs populated in this method. |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 746 | if (!ParseUrls(parser_data, output_object, completer)) |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 747 | return false; |
| 748 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 749 | if (!ParsePackage(parser_data, output_object, completer)) |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 750 | return false; |
| 751 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 752 | if (!ParseParams(parser_data, output_object, completer)) |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 753 | return false; |
| 754 | |
| 755 | return true; |
| 756 | } |
| 757 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 758 | bool OmahaRequestAction::ParseStatus(OmahaParserData* parser_data, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 759 | OmahaResponse* output_object, |
| 760 | ScopedActionCompleter* completer) { |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 761 | const string& status = parser_data->updatecheck_status; |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 762 | if (status == "noupdate") { |
| 763 | LOG(INFO) << "No update."; |
| 764 | output_object->update_exists = false; |
| 765 | SetOutputObject(*output_object); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 766 | completer->set_code(ErrorCode::kSuccess); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 767 | return false; |
| 768 | } |
| 769 | |
| 770 | if (status != "ok") { |
| 771 | LOG(ERROR) << "Unknown Omaha response status: " << status; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 772 | completer->set_code(ErrorCode::kOmahaResponseInvalid); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 773 | return false; |
| 774 | } |
| 775 | |
| 776 | return true; |
| 777 | } |
| 778 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 779 | bool OmahaRequestAction::ParseUrls(OmahaParserData* parser_data, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 780 | OmahaResponse* output_object, |
| 781 | ScopedActionCompleter* completer) { |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 782 | if (parser_data->url_codebase.empty()) { |
| 783 | LOG(ERROR) << "No Omaha Response URLs"; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 784 | completer->set_code(ErrorCode::kOmahaResponseInvalid); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 785 | return false; |
| 786 | } |
| 787 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 788 | LOG(INFO) << "Found " << parser_data->url_codebase.size() << " url(s)"; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 789 | output_object->payload_urls.clear(); |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 790 | for (const auto& codebase : parser_data->url_codebase) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 791 | if (codebase.empty()) { |
| 792 | LOG(ERROR) << "Omaha Response URL has empty codebase"; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 793 | completer->set_code(ErrorCode::kOmahaResponseInvalid); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 794 | return false; |
| 795 | } |
| 796 | output_object->payload_urls.push_back(codebase); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 799 | return true; |
| 800 | } |
| 801 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 802 | bool OmahaRequestAction::ParsePackage(OmahaParserData* parser_data, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 803 | OmahaResponse* output_object, |
| 804 | ScopedActionCompleter* completer) { |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 805 | if (parser_data->package_name.empty()) { |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 806 | LOG(ERROR) << "Omaha Response has empty package name"; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 807 | completer->set_code(ErrorCode::kOmahaResponseInvalid); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 808 | return false; |
| 809 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 810 | |
| 811 | // Append the package name to each URL in our list so that we don't |
| 812 | // propagate the urlBase vs packageName distinctions beyond this point. |
| 813 | // From now on, we only need to use payload_urls. |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 814 | for (auto& payload_url : output_object->payload_urls) |
| 815 | payload_url += parser_data->package_name; |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 816 | |
| 817 | // Parse the payload size. |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 818 | off_t size = ParseInt(parser_data->package_size); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 819 | if (size <= 0) { |
| 820 | LOG(ERROR) << "Omaha Response has invalid payload size: " << size; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 821 | completer->set_code(ErrorCode::kOmahaResponseInvalid); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 822 | return false; |
| 823 | } |
| 824 | output_object->size = size; |
| 825 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 826 | LOG(INFO) << "Payload size = " << output_object->size << " bytes"; |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 827 | |
| 828 | return true; |
| 829 | } |
| 830 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 831 | bool OmahaRequestAction::ParseParams(OmahaParserData* parser_data, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 832 | OmahaResponse* output_object, |
| 833 | ScopedActionCompleter* completer) { |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 834 | output_object->version = parser_data->manifest_version; |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 835 | if (output_object->version.empty()) { |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 836 | LOG(ERROR) << "Omaha Response does not have version in manifest!"; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 837 | completer->set_code(ErrorCode::kOmahaResponseInvalid); |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 838 | return false; |
| 839 | } |
| 840 | |
| 841 | LOG(INFO) << "Received omaha response to update to version " |
| 842 | << output_object->version; |
| 843 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 844 | map<string, string> attrs = parser_data->action_postinstall_attrs; |
| 845 | if (attrs.empty()) { |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 846 | LOG(ERROR) << "Omaha Response has no postinstall event action"; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 847 | completer->set_code(ErrorCode::kOmahaResponseInvalid); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 848 | return false; |
| 849 | } |
| 850 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 851 | output_object->hash = attrs[kTagSha256]; |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 852 | if (output_object->hash.empty()) { |
| 853 | LOG(ERROR) << "Omaha Response has empty sha256 value"; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 854 | completer->set_code(ErrorCode::kOmahaResponseInvalid); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 855 | return false; |
| 856 | } |
| 857 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 858 | // Get the optional properties one by one. |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 859 | output_object->more_info_url = attrs[kTagMoreInfo]; |
| 860 | output_object->metadata_size = ParseInt(attrs[kTagMetadataSize]); |
| 861 | output_object->metadata_signature = attrs[kTagMetadataSignatureRsa]; |
| 862 | output_object->prompt = ParseBool(attrs[kTagPrompt]); |
| 863 | output_object->deadline = attrs[kTagDeadline]; |
| 864 | output_object->max_days_to_scatter = ParseInt(attrs[kTagMaxDaysToScatter]); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 865 | output_object->disable_p2p_for_downloading = |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 866 | ParseBool(attrs[kTagDisableP2PForDownloading]); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 867 | output_object->disable_p2p_for_sharing = |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 868 | ParseBool(attrs[kTagDisableP2PForSharing]); |
| 869 | output_object->public_key_rsa = attrs[kTagPublicKeyRsa]; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 870 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 871 | string max = attrs[kTagMaxFailureCountPerUrl]; |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 872 | if (!base::StringToUint(max, &output_object->max_failure_count_per_url)) |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 873 | output_object->max_failure_count_per_url = kDefaultMaxFailureCountPerUrl; |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 874 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 875 | output_object->is_delta_payload = ParseBool(attrs[kTagIsDeltaPayload]); |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 876 | |
| 877 | output_object->disable_payload_backoff = |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 878 | ParseBool(attrs[kTagDisablePayloadBackoff]); |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 879 | |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 880 | return true; |
| 881 | } |
| 882 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 883 | // If the transfer was successful, this uses expat to parse the response |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 884 | // and fill in the appropriate fields of the output object. Also, notifies |
| 885 | // the processor that we're done. |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 886 | void OmahaRequestAction::TransferComplete(HttpFetcher *fetcher, |
| 887 | bool successful) { |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 888 | ScopedActionCompleter completer(processor_, this); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 889 | string current_response(response_buffer_.begin(), response_buffer_.end()); |
| 890 | LOG(INFO) << "Omaha request response: " << current_response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 891 | |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 892 | PayloadStateInterface* const payload_state = system_state_->payload_state(); |
| 893 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 894 | // Events are best effort transactions -- assume they always succeed. |
| 895 | if (IsEvent()) { |
| 896 | CHECK(!HasOutputPipe()) << "No output pipe allowed for event requests."; |
Andrew de los Reyes | 2008e4c | 2011-01-12 10:17:52 -0800 | [diff] [blame] | 897 | if (event_->result == OmahaEvent::kResultError && successful && |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 898 | system_state_->hardware()->IsOfficialBuild()) { |
Andrew de los Reyes | 2008e4c | 2011-01-12 10:17:52 -0800 | [diff] [blame] | 899 | LOG(INFO) << "Signalling Crash Reporter."; |
| 900 | utils::ScheduleCrashReporterUpload(); |
| 901 | } |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 902 | completer.set_code(ErrorCode::kSuccess); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 903 | return; |
| 904 | } |
| 905 | |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 906 | if (!successful) { |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 907 | LOG(ERROR) << "Omaha request network transfer failed."; |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 908 | int code = GetHTTPResponseCode(); |
| 909 | // Makes sure we send sane error values. |
| 910 | if (code < 0 || code >= 1000) { |
| 911 | code = 999; |
| 912 | } |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 913 | completer.set_code(static_cast<ErrorCode>( |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 914 | static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + code)); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 915 | return; |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 916 | } |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 917 | |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 918 | XML_Parser parser = XML_ParserCreate(nullptr); |
David Zeuthen | f3e2801 | 2014-08-26 18:23:52 -0400 | [diff] [blame] | 919 | OmahaParserData parser_data(parser); |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 920 | XML_SetUserData(parser, &parser_data); |
| 921 | XML_SetElementHandler(parser, ParserHandlerStart, ParserHandlerEnd); |
David Zeuthen | f3e2801 | 2014-08-26 18:23:52 -0400 | [diff] [blame] | 922 | XML_SetEntityDeclHandler(parser, ParserHandlerEntityDecl); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 923 | XML_Status res = XML_Parse( |
| 924 | parser, |
| 925 | reinterpret_cast<const char*>(response_buffer_.data()), |
| 926 | response_buffer_.size(), |
| 927 | XML_TRUE); |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 928 | XML_ParserFree(parser); |
| 929 | |
| 930 | if (res != XML_STATUS_OK || parser_data.failed) { |
Alex Deymo | a9bb7dc | 2015-06-19 09:50:23 -0700 | [diff] [blame] | 931 | LOG(ERROR) << "Omaha response not valid XML: " |
| 932 | << XML_ErrorString(XML_GetErrorCode(parser)) |
| 933 | << " at line " << XML_GetCurrentLineNumber(parser) |
| 934 | << " col " << XML_GetCurrentColumnNumber(parser); |
David Zeuthen | f3e2801 | 2014-08-26 18:23:52 -0400 | [diff] [blame] | 935 | ErrorCode error_code = ErrorCode::kOmahaRequestXMLParseError; |
| 936 | if (response_buffer_.empty()) { |
| 937 | error_code = ErrorCode::kOmahaRequestEmptyResponseError; |
| 938 | } else if (parser_data.entity_decl) { |
| 939 | error_code = ErrorCode::kOmahaRequestXMLHasEntityDecl; |
| 940 | } |
| 941 | completer.set_code(error_code); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 942 | return; |
| 943 | } |
| 944 | |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 945 | // Update the last ping day preferences based on the server daystart response |
| 946 | // even if we didn't send a ping. Omaha always includes the daystart in the |
| 947 | // response, but log the error if it didn't. |
| 948 | LOG_IF(ERROR, !UpdateLastPingDays(&parser_data, system_state_->prefs())) |
| 949 | << "Failed to update the last ping day preferences!"; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 950 | |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 951 | if (!HasOutputPipe()) { |
| 952 | // Just set success to whether or not the http transfer succeeded, |
| 953 | // which must be true at this point in the code. |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 954 | completer.set_code(ErrorCode::kSuccess); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 955 | return; |
| 956 | } |
| 957 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 958 | OmahaResponse output_object; |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 959 | if (!ParseResponse(&parser_data, &output_object, &completer)) |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 960 | return; |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 961 | output_object.update_exists = true; |
| 962 | SetOutputObject(output_object); |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 963 | |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 964 | if (ShouldIgnoreUpdate(output_object)) { |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 965 | output_object.update_exists = false; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 966 | completer.set_code(ErrorCode::kOmahaUpdateIgnoredPerPolicy); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 967 | return; |
| 968 | } |
| 969 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 970 | // If Omaha says to disable p2p, respect that |
| 971 | if (output_object.disable_p2p_for_downloading) { |
| 972 | LOG(INFO) << "Forcibly disabling use of p2p for downloading as " |
| 973 | << "requested by Omaha."; |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 974 | payload_state->SetUsingP2PForDownloading(false); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 975 | } |
| 976 | if (output_object.disable_p2p_for_sharing) { |
| 977 | LOG(INFO) << "Forcibly disabling use of p2p for sharing as " |
| 978 | << "requested by Omaha."; |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 979 | payload_state->SetUsingP2PForSharing(false); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 980 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 981 | |
| 982 | // Update the payload state with the current response. The payload state |
| 983 | // will automatically reset all stale state if this response is different |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 984 | // from what's stored already. We are updating the payload state as late |
| 985 | // as possible in this method so that if a new release gets pushed and then |
| 986 | // got pulled back due to some issues, we don't want to clear our internal |
| 987 | // state unnecessarily. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 988 | payload_state->SetResponse(output_object); |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 989 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 990 | // It could be we've already exceeded the deadline for when p2p is |
| 991 | // allowed or that we've tried too many times with p2p. Check that. |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 992 | if (payload_state->GetUsingP2PForDownloading()) { |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 993 | payload_state->P2PNewAttempt(); |
| 994 | if (!payload_state->P2PAttemptAllowed()) { |
| 995 | LOG(INFO) << "Forcibly disabling use of p2p for downloading because " |
| 996 | << "of previous failures when using p2p."; |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 997 | payload_state->SetUsingP2PForDownloading(false); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | |
| 1001 | // From here on, we'll complete stuff in CompleteProcessing() so |
| 1002 | // disable |completer| since we'll create a new one in that |
| 1003 | // function. |
| 1004 | completer.set_should_complete(false); |
| 1005 | |
| 1006 | // If we're allowed to use p2p for downloading we do not pay |
| 1007 | // attention to wall-clock-based waiting if the URL is indeed |
| 1008 | // available via p2p. Therefore, check if the file is available via |
| 1009 | // p2p before deferring... |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 1010 | if (payload_state->GetUsingP2PForDownloading()) { |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1011 | LookupPayloadViaP2P(output_object); |
| 1012 | } else { |
| 1013 | CompleteProcessing(); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | void OmahaRequestAction::CompleteProcessing() { |
| 1018 | ScopedActionCompleter completer(processor_, this); |
| 1019 | OmahaResponse& output_object = const_cast<OmahaResponse&>(GetOutputObject()); |
| 1020 | PayloadStateInterface* payload_state = system_state_->payload_state(); |
| 1021 | |
| 1022 | if (ShouldDeferDownload(&output_object)) { |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 1023 | output_object.update_exists = false; |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1024 | LOG(INFO) << "Ignoring Omaha updates as updates are deferred by policy."; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1025 | completer.set_code(ErrorCode::kOmahaUpdateDeferredPerPolicy); |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 1026 | return; |
| 1027 | } |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1028 | |
Chris Sosa | 20f005c | 2013-09-05 13:53:08 -0700 | [diff] [blame] | 1029 | if (payload_state->ShouldBackoffDownload()) { |
| 1030 | output_object.update_exists = false; |
| 1031 | LOG(INFO) << "Ignoring Omaha updates in order to backoff our retry " |
| 1032 | << "attempts"; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1033 | completer.set_code(ErrorCode::kOmahaUpdateDeferredForBackoff); |
Chris Sosa | 20f005c | 2013-09-05 13:53:08 -0700 | [diff] [blame] | 1034 | return; |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1035 | } |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1036 | completer.set_code(ErrorCode::kSuccess); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | void OmahaRequestAction::OnLookupPayloadViaP2PCompleted(const string& url) { |
| 1040 | LOG(INFO) << "Lookup complete, p2p-client returned URL '" << url << "'"; |
| 1041 | if (!url.empty()) { |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 1042 | system_state_->payload_state()->SetP2PUrl(url); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1043 | } else { |
| 1044 | LOG(INFO) << "Forcibly disabling use of p2p for downloading " |
| 1045 | << "because no suitable peer could be found."; |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 1046 | system_state_->payload_state()->SetUsingP2PForDownloading(false); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1047 | } |
| 1048 | CompleteProcessing(); |
| 1049 | } |
| 1050 | |
| 1051 | void OmahaRequestAction::LookupPayloadViaP2P(const OmahaResponse& response) { |
David Zeuthen | 41996ad | 2013-09-24 15:43:24 -0700 | [diff] [blame] | 1052 | // If the device is in the middle of an update, the state variables |
| 1053 | // kPrefsUpdateStateNextDataOffset, kPrefsUpdateStateNextDataLength |
| 1054 | // tracks the offset and length of the operation currently in |
| 1055 | // progress. The offset is based from the end of the manifest which |
| 1056 | // is kPrefsManifestMetadataSize bytes long. |
| 1057 | // |
| 1058 | // To make forward progress and avoid deadlocks, we need to find a |
| 1059 | // peer that has at least the entire operation we're currently |
| 1060 | // working on. Otherwise we may end up in a situation where two |
| 1061 | // devices bounce back and forth downloading from each other, |
| 1062 | // neither making any forward progress until one of them decides to |
| 1063 | // stop using p2p (via kMaxP2PAttempts and kMaxP2PAttemptTimeSeconds |
| 1064 | // safe-guards). See http://crbug.com/297170 for an example) |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1065 | size_t minimum_size = 0; |
David Zeuthen | 41996ad | 2013-09-24 15:43:24 -0700 | [diff] [blame] | 1066 | int64_t manifest_metadata_size = 0; |
| 1067 | int64_t next_data_offset = 0; |
| 1068 | int64_t next_data_length = 0; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1069 | if (system_state_ && |
David Zeuthen | 41996ad | 2013-09-24 15:43:24 -0700 | [diff] [blame] | 1070 | system_state_->prefs()->GetInt64(kPrefsManifestMetadataSize, |
| 1071 | &manifest_metadata_size) && |
| 1072 | manifest_metadata_size != -1 && |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1073 | system_state_->prefs()->GetInt64(kPrefsUpdateStateNextDataOffset, |
David Zeuthen | 41996ad | 2013-09-24 15:43:24 -0700 | [diff] [blame] | 1074 | &next_data_offset) && |
| 1075 | next_data_offset != -1 && |
| 1076 | system_state_->prefs()->GetInt64(kPrefsUpdateStateNextDataLength, |
| 1077 | &next_data_length)) { |
| 1078 | minimum_size = manifest_metadata_size + next_data_offset + next_data_length; |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | string file_id = utils::CalculateP2PFileId(response.hash, response.size); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1082 | if (system_state_->p2p_manager()) { |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1083 | LOG(INFO) << "Checking if payload is available via p2p, file_id=" |
| 1084 | << file_id << " minimum_size=" << minimum_size; |
| 1085 | system_state_->p2p_manager()->LookupUrlForFile( |
| 1086 | file_id, |
| 1087 | minimum_size, |
David Zeuthen | 4cc5ed2 | 2014-01-15 12:35:03 -0800 | [diff] [blame] | 1088 | TimeDelta::FromSeconds(kMaxP2PNetworkWaitTimeSeconds), |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1089 | base::Bind(&OmahaRequestAction::OnLookupPayloadViaP2PCompleted, |
| 1090 | base::Unretained(this))); |
| 1091 | } |
rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1094 | bool OmahaRequestAction::ShouldDeferDownload(OmahaResponse* output_object) { |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1095 | if (params_->interactive()) { |
| 1096 | LOG(INFO) << "Not deferring download because update is interactive."; |
| 1097 | return false; |
| 1098 | } |
| 1099 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1100 | // If we're using p2p to download _and_ we have a p2p URL, we never |
| 1101 | // defer the download. This is because the download will always |
| 1102 | // happen from a peer on the LAN and we've been waiting in line for |
| 1103 | // our turn. |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 1104 | const PayloadStateInterface* payload_state = system_state_->payload_state(); |
| 1105 | if (payload_state->GetUsingP2PForDownloading() && |
| 1106 | !payload_state->GetP2PUrl().empty()) { |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1107 | LOG(INFO) << "Download not deferred because download " |
| 1108 | << "will happen from a local peer (via p2p)."; |
| 1109 | return false; |
| 1110 | } |
| 1111 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1112 | // We should defer the downloads only if we've first satisfied the |
| 1113 | // wall-clock-based-waiting period and then the update-check-based waiting |
| 1114 | // period, if required. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1115 | if (!params_->wall_clock_based_wait_enabled()) { |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1116 | LOG(INFO) << "Wall-clock-based waiting period is not enabled," |
| 1117 | << " so no deferring needed."; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1118 | return false; |
| 1119 | } |
| 1120 | |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1121 | switch (IsWallClockBasedWaitingSatisfied(output_object)) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1122 | case kWallClockWaitNotSatisfied: |
| 1123 | // We haven't even satisfied the first condition, passing the |
| 1124 | // wall-clock-based waiting period, so we should defer the downloads |
| 1125 | // until that happens. |
| 1126 | LOG(INFO) << "wall-clock-based-wait not satisfied."; |
| 1127 | return true; |
| 1128 | |
| 1129 | case kWallClockWaitDoneButUpdateCheckWaitRequired: |
| 1130 | LOG(INFO) << "wall-clock-based-wait satisfied and " |
| 1131 | << "update-check-based-wait required."; |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1132 | return !IsUpdateCheckCountBasedWaitingSatisfied(); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1133 | |
| 1134 | case kWallClockWaitDoneAndUpdateCheckWaitNotRequired: |
| 1135 | // Wall-clock-based waiting period is satisfied, and it's determined |
| 1136 | // that we do not need the update-check-based wait. so no need to |
| 1137 | // defer downloads. |
| 1138 | LOG(INFO) << "wall-clock-based-wait satisfied and " |
| 1139 | << "update-check-based-wait is not required."; |
| 1140 | return false; |
| 1141 | |
| 1142 | default: |
| 1143 | // Returning false for this default case so we err on the |
| 1144 | // side of downloading updates than deferring in case of any bugs. |
| 1145 | NOTREACHED(); |
| 1146 | return false; |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | OmahaRequestAction::WallClockWaitResult |
| 1151 | OmahaRequestAction::IsWallClockBasedWaitingSatisfied( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1152 | OmahaResponse* output_object) { |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1153 | Time update_first_seen_at; |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1154 | int64_t update_first_seen_at_int; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1155 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 1156 | if (system_state_->prefs()->Exists(kPrefsUpdateFirstSeenAt)) { |
| 1157 | if (system_state_->prefs()->GetInt64(kPrefsUpdateFirstSeenAt, |
| 1158 | &update_first_seen_at_int)) { |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1159 | // Note: This timestamp could be that of ANY update we saw in the past |
| 1160 | // (not necessarily this particular update we're considering to apply) |
| 1161 | // but never got to apply because of some reason (e.g. stop AU policy, |
| 1162 | // updates being pulled out from Omaha, changes in target version prefix, |
| 1163 | // new update being rolled out, etc.). But for the purposes of scattering |
| 1164 | // it doesn't matter which update the timestamp corresponds to. i.e. |
| 1165 | // the clock starts ticking the first time we see an update and we're |
| 1166 | // ready to apply when the random wait period is satisfied relative to |
| 1167 | // that first seen timestamp. |
| 1168 | update_first_seen_at = Time::FromInternalValue(update_first_seen_at_int); |
| 1169 | LOG(INFO) << "Using persisted value of UpdateFirstSeenAt: " |
| 1170 | << utils::ToString(update_first_seen_at); |
| 1171 | } else { |
| 1172 | // This seems like an unexpected error where the persisted value exists |
| 1173 | // but it's not readable for some reason. Just skip scattering in this |
| 1174 | // case to be safe. |
| 1175 | LOG(INFO) << "Not scattering as UpdateFirstSeenAt value cannot be read"; |
| 1176 | return kWallClockWaitDoneAndUpdateCheckWaitNotRequired; |
| 1177 | } |
| 1178 | } else { |
| 1179 | update_first_seen_at = Time::Now(); |
| 1180 | update_first_seen_at_int = update_first_seen_at.ToInternalValue(); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 1181 | if (system_state_->prefs()->SetInt64(kPrefsUpdateFirstSeenAt, |
| 1182 | update_first_seen_at_int)) { |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1183 | LOG(INFO) << "Persisted the new value for UpdateFirstSeenAt: " |
| 1184 | << utils::ToString(update_first_seen_at); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1185 | } else { |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1186 | // This seems like an unexpected error where the value cannot be |
| 1187 | // persisted for some reason. Just skip scattering in this |
| 1188 | // case to be safe. |
| 1189 | LOG(INFO) << "Not scattering as UpdateFirstSeenAt value " |
| 1190 | << utils::ToString(update_first_seen_at) |
| 1191 | << " cannot be persisted"; |
| 1192 | return kWallClockWaitDoneAndUpdateCheckWaitNotRequired; |
| 1193 | } |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1196 | TimeDelta elapsed_time = Time::Now() - update_first_seen_at; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1197 | TimeDelta max_scatter_period = TimeDelta::FromDays( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1198 | output_object->max_days_to_scatter); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1199 | |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1200 | LOG(INFO) << "Waiting Period = " |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1201 | << utils::FormatSecs(params_->waiting_period().InSeconds()) |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1202 | << ", Time Elapsed = " |
| 1203 | << utils::FormatSecs(elapsed_time.InSeconds()) |
| 1204 | << ", MaxDaysToScatter = " |
| 1205 | << max_scatter_period.InDays(); |
| 1206 | |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1207 | if (!output_object->deadline.empty()) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1208 | // The deadline is set for all rules which serve a delta update from a |
| 1209 | // previous FSI, which means this update will be applied mostly in OOBE |
| 1210 | // cases. For these cases, we shouldn't scatter so as to finish the OOBE |
| 1211 | // quickly. |
| 1212 | LOG(INFO) << "Not scattering as deadline flag is set"; |
| 1213 | return kWallClockWaitDoneAndUpdateCheckWaitNotRequired; |
| 1214 | } |
| 1215 | |
| 1216 | if (max_scatter_period.InDays() == 0) { |
| 1217 | // This means the Omaha rule creator decides that this rule |
| 1218 | // should not be scattered irrespective of the policy. |
| 1219 | LOG(INFO) << "Not scattering as MaxDaysToScatter in rule is 0."; |
| 1220 | return kWallClockWaitDoneAndUpdateCheckWaitNotRequired; |
| 1221 | } |
| 1222 | |
| 1223 | if (elapsed_time > max_scatter_period) { |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1224 | // This means we've waited more than the upperbound wait in the rule |
| 1225 | // from the time we first saw a valid update available to us. |
| 1226 | // This will prevent update starvation. |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1227 | LOG(INFO) << "Not scattering as we're past the MaxDaysToScatter limit."; |
| 1228 | return kWallClockWaitDoneAndUpdateCheckWaitNotRequired; |
| 1229 | } |
| 1230 | |
| 1231 | // This means we are required to participate in scattering. |
| 1232 | // See if our turn has arrived now. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1233 | TimeDelta remaining_wait_time = params_->waiting_period() - elapsed_time; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1234 | if (remaining_wait_time.InSeconds() <= 0) { |
| 1235 | // Yes, it's our turn now. |
| 1236 | LOG(INFO) << "Successfully passed the wall-clock-based-wait."; |
| 1237 | |
| 1238 | // But we can't download until the update-check-count-based wait is also |
| 1239 | // satisfied, so mark it as required now if update checks are enabled. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1240 | return params_->update_check_count_wait_enabled() ? |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1241 | kWallClockWaitDoneButUpdateCheckWaitRequired : |
| 1242 | kWallClockWaitDoneAndUpdateCheckWaitNotRequired; |
| 1243 | } |
| 1244 | |
| 1245 | // Not our turn yet, so we have to wait until our turn to |
| 1246 | // help scatter the downloads across all clients of the enterprise. |
| 1247 | LOG(INFO) << "Update deferred for another " |
| 1248 | << utils::FormatSecs(remaining_wait_time.InSeconds()) |
| 1249 | << " per policy."; |
| 1250 | return kWallClockWaitNotSatisfied; |
| 1251 | } |
| 1252 | |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1253 | bool OmahaRequestAction::IsUpdateCheckCountBasedWaitingSatisfied() { |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1254 | int64_t update_check_count_value; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1255 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 1256 | if (system_state_->prefs()->Exists(kPrefsUpdateCheckCount)) { |
| 1257 | if (!system_state_->prefs()->GetInt64(kPrefsUpdateCheckCount, |
| 1258 | &update_check_count_value)) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1259 | // We are unable to read the update check count from file for some reason. |
| 1260 | // So let's proceed anyway so as to not stall the update. |
| 1261 | LOG(ERROR) << "Unable to read update check count. " |
| 1262 | << "Skipping update-check-count-based-wait."; |
| 1263 | return true; |
| 1264 | } |
| 1265 | } else { |
| 1266 | // This file does not exist. This means we haven't started our update |
| 1267 | // check count down yet, so this is the right time to start the count down. |
| 1268 | update_check_count_value = base::RandInt( |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1269 | params_->min_update_checks_needed(), |
| 1270 | params_->max_update_checks_allowed()); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1271 | |
| 1272 | LOG(INFO) << "Randomly picked update check count value = " |
| 1273 | << update_check_count_value; |
| 1274 | |
| 1275 | // Write out the initial value of update_check_count_value. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 1276 | if (!system_state_->prefs()->SetInt64(kPrefsUpdateCheckCount, |
| 1277 | update_check_count_value)) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1278 | // We weren't able to write the update check count file for some reason. |
| 1279 | // So let's proceed anyway so as to not stall the update. |
| 1280 | LOG(ERROR) << "Unable to write update check count. " |
| 1281 | << "Skipping update-check-count-based-wait."; |
| 1282 | return true; |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | if (update_check_count_value == 0) { |
| 1287 | LOG(INFO) << "Successfully passed the update-check-based-wait."; |
| 1288 | return true; |
| 1289 | } |
| 1290 | |
| 1291 | if (update_check_count_value < 0 || |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1292 | update_check_count_value > params_->max_update_checks_allowed()) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1293 | // We err on the side of skipping scattering logic instead of stalling |
| 1294 | // a machine from receiving any updates in case of any unexpected state. |
| 1295 | LOG(ERROR) << "Invalid value for update check count detected. " |
| 1296 | << "Skipping update-check-count-based-wait."; |
| 1297 | return true; |
| 1298 | } |
| 1299 | |
| 1300 | // Legal value, we need to wait for more update checks to happen |
| 1301 | // until this becomes 0. |
| 1302 | LOG(INFO) << "Deferring Omaha updates for another " |
| 1303 | << update_check_count_value |
| 1304 | << " update checks per policy"; |
| 1305 | return false; |
| 1306 | } |
| 1307 | |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1308 | // static |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 1309 | bool OmahaRequestAction::ParseInstallDate(OmahaParserData* parser_data, |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1310 | OmahaResponse* output_object) { |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1311 | int64_t elapsed_days = 0; |
David Zeuthen | e8ed863 | 2014-07-24 13:38:10 -0400 | [diff] [blame] | 1312 | if (!base::StringToInt64(parser_data->daystart_elapsed_days, |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1313 | &elapsed_days)) |
| 1314 | return false; |
| 1315 | |
| 1316 | if (elapsed_days < 0) |
| 1317 | return false; |
| 1318 | |
| 1319 | output_object->install_date_days = elapsed_days; |
| 1320 | return true; |
| 1321 | } |
| 1322 | |
| 1323 | // static |
| 1324 | bool OmahaRequestAction::HasInstallDate(SystemState *system_state) { |
| 1325 | PrefsInterface* prefs = system_state->prefs(); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1326 | if (prefs == nullptr) |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1327 | return false; |
| 1328 | |
| 1329 | return prefs->Exists(kPrefsInstallDateDays); |
| 1330 | } |
| 1331 | |
| 1332 | // static |
| 1333 | bool OmahaRequestAction::PersistInstallDate( |
| 1334 | SystemState *system_state, |
| 1335 | int install_date_days, |
| 1336 | InstallDateProvisioningSource source) { |
| 1337 | TEST_AND_RETURN_FALSE(install_date_days >= 0); |
| 1338 | |
| 1339 | PrefsInterface* prefs = system_state->prefs(); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1340 | if (prefs == nullptr) |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1341 | return false; |
| 1342 | |
| 1343 | if (!prefs->SetInt64(kPrefsInstallDateDays, install_date_days)) |
| 1344 | return false; |
| 1345 | |
Alex Deymo | af9a863 | 2015-09-23 18:51:48 -0700 | [diff] [blame] | 1346 | string metric_name = metrics::kMetricInstallDateProvisioningSource; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1347 | system_state->metrics_lib()->SendEnumToUMA( |
| 1348 | metric_name, |
| 1349 | static_cast<int>(source), // Sample. |
| 1350 | kProvisionedMax); // Maximum. |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1351 | |
| 1352 | return true; |
| 1353 | } |
| 1354 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1355 | bool OmahaRequestAction::PersistCohortData( |
| 1356 | const string& prefs_key, |
| 1357 | const string& new_value) { |
| 1358 | if (new_value.empty() && system_state_->prefs()->Exists(prefs_key)) { |
| 1359 | LOG(INFO) << "Removing stored " << prefs_key << " value."; |
| 1360 | return system_state_->prefs()->Delete(prefs_key); |
| 1361 | } else if (!new_value.empty()) { |
| 1362 | LOG(INFO) << "Storing new setting " << prefs_key << " as " << new_value; |
| 1363 | return system_state_->prefs()->SetString(prefs_key, new_value); |
| 1364 | } |
| 1365 | return true; |
| 1366 | } |
| 1367 | |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1368 | void OmahaRequestAction::ActionCompleted(ErrorCode code) { |
| 1369 | // We only want to report this on "update check". |
| 1370 | if (ping_only_ || event_ != nullptr) |
| 1371 | return; |
| 1372 | |
| 1373 | metrics::CheckResult result = metrics::CheckResult::kUnset; |
| 1374 | metrics::CheckReaction reaction = metrics::CheckReaction::kUnset; |
| 1375 | metrics::DownloadErrorCode download_error_code = |
| 1376 | metrics::DownloadErrorCode::kUnset; |
| 1377 | |
| 1378 | // Regular update attempt. |
| 1379 | switch (code) { |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1380 | case ErrorCode::kSuccess: |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1381 | // OK, we parsed the response successfully but that does |
| 1382 | // necessarily mean that an update is available. |
| 1383 | if (HasOutputPipe()) { |
| 1384 | const OmahaResponse& response = GetOutputObject(); |
| 1385 | if (response.update_exists) { |
| 1386 | result = metrics::CheckResult::kUpdateAvailable; |
| 1387 | reaction = metrics::CheckReaction::kUpdating; |
| 1388 | } else { |
| 1389 | result = metrics::CheckResult::kNoUpdateAvailable; |
| 1390 | } |
| 1391 | } else { |
| 1392 | result = metrics::CheckResult::kNoUpdateAvailable; |
| 1393 | } |
| 1394 | break; |
| 1395 | |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1396 | case ErrorCode::kOmahaUpdateIgnoredPerPolicy: |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1397 | result = metrics::CheckResult::kUpdateAvailable; |
| 1398 | reaction = metrics::CheckReaction::kIgnored; |
| 1399 | break; |
| 1400 | |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1401 | case ErrorCode::kOmahaUpdateDeferredPerPolicy: |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1402 | result = metrics::CheckResult::kUpdateAvailable; |
| 1403 | reaction = metrics::CheckReaction::kDeferring; |
| 1404 | break; |
| 1405 | |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1406 | case ErrorCode::kOmahaUpdateDeferredForBackoff: |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1407 | result = metrics::CheckResult::kUpdateAvailable; |
| 1408 | reaction = metrics::CheckReaction::kBackingOff; |
| 1409 | break; |
| 1410 | |
| 1411 | default: |
| 1412 | // We report two flavors of errors, "Download errors" and "Parsing |
| 1413 | // error". Try to convert to the former and if that doesn't work |
| 1414 | // we know it's the latter. |
| 1415 | metrics::DownloadErrorCode tmp_error = utils::GetDownloadErrorCode(code); |
| 1416 | if (tmp_error != metrics::DownloadErrorCode::kInputMalformed) { |
| 1417 | result = metrics::CheckResult::kDownloadError; |
| 1418 | download_error_code = tmp_error; |
| 1419 | } else { |
| 1420 | result = metrics::CheckResult::kParsingError; |
| 1421 | } |
| 1422 | break; |
| 1423 | } |
| 1424 | |
| 1425 | metrics::ReportUpdateCheckMetrics(system_state_, |
| 1426 | result, reaction, download_error_code); |
| 1427 | } |
| 1428 | |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1429 | bool OmahaRequestAction::ShouldIgnoreUpdate( |
| 1430 | const OmahaResponse& response) const { |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1431 | // Note: policy decision to not update to a version we rolled back from. |
| 1432 | string rollback_version = |
| 1433 | system_state_->payload_state()->GetRollbackVersion(); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1434 | if (!rollback_version.empty()) { |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1435 | LOG(INFO) << "Detected previous rollback from version " << rollback_version; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1436 | if (rollback_version == response.version) { |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1437 | LOG(INFO) << "Received version that we rolled back from. Ignoring."; |
| 1438 | return true; |
| 1439 | } |
| 1440 | } |
| 1441 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1442 | if (!IsUpdateAllowedOverCurrentConnection()) { |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1443 | LOG(INFO) << "Update is not allowed over current connection."; |
| 1444 | return true; |
| 1445 | } |
| 1446 | |
| 1447 | // Note: We could technically delete the UpdateFirstSeenAt state when we |
| 1448 | // return true. If we do, it'll mean a device has to restart the |
| 1449 | // UpdateFirstSeenAt and thus help scattering take effect when the AU is |
| 1450 | // turned on again. On the other hand, it also increases the chance of update |
| 1451 | // starvation if an admin turns AU on/off more frequently. We choose to err on |
| 1452 | // the side of preventing starvation at the cost of not applying scattering in |
| 1453 | // those cases. |
| 1454 | return false; |
| 1455 | } |
| 1456 | |
| 1457 | bool OmahaRequestAction::IsUpdateAllowedOverCurrentConnection() const { |
| 1458 | NetworkConnectionType type; |
| 1459 | NetworkTethering tethering; |
Alex Deymo | f6ee016 | 2015-07-31 12:35:22 -0700 | [diff] [blame] | 1460 | ConnectionManagerInterface* connection_manager = |
| 1461 | system_state_->connection_manager(); |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 1462 | if (!connection_manager->GetConnectionProperties(&type, &tethering)) { |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1463 | LOG(INFO) << "We could not determine our connection type. " |
| 1464 | << "Defaulting to allow updates."; |
| 1465 | return true; |
| 1466 | } |
| 1467 | bool is_allowed = connection_manager->IsUpdateAllowedOver(type, tethering); |
| 1468 | LOG(INFO) << "We are connected via " |
Alex Deymo | f6ee016 | 2015-07-31 12:35:22 -0700 | [diff] [blame] | 1469 | << ConnectionManager::StringForConnectionType(type) |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1470 | << ", Updates allowed: " << (is_allowed ? "Yes" : "No"); |
| 1471 | return is_allowed; |
| 1472 | } |
| 1473 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1474 | } // namespace chromeos_update_engine |