Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2013 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 | // |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 16 | |
Alex Deymo | 1b03f9f | 2015-12-09 00:38:36 -0800 | [diff] [blame] | 17 | #include "update_engine/hardware_chromeos.h" |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 18 | |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 19 | #include <utility> |
| 20 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 21 | #include <base/files/file_path.h> |
Ben Chan | 06c76a4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 22 | #include <base/files/file_util.h> |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 23 | #include <base/logging.h> |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 24 | #include <base/strings/string_number_conversions.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 25 | #include <base/strings/string_util.h> |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 26 | #include <brillo/key_value_store.h> |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 27 | #include <debugd/dbus-constants.h> |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 28 | #include <vboot/crossystem.h> |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 29 | |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 30 | extern "C" { |
| 31 | #include "vboot/vboot_host.h" |
| 32 | } |
| 33 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 34 | #include "update_engine/common/constants.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 35 | #include "update_engine/common/hardware.h" |
| 36 | #include "update_engine/common/hwid_override.h" |
Sen Jiang | 9c12346 | 2015-11-19 13:16:23 -0800 | [diff] [blame] | 37 | #include "update_engine/common/platform_constants.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 38 | #include "update_engine/common/subprocess.h" |
| 39 | #include "update_engine/common/utils.h" |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 40 | #include "update_engine/dbus_connection.h" |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 41 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 42 | using std::string; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 43 | using std::vector; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 44 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 45 | namespace { |
| 46 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 47 | const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed"; |
| 48 | |
| 49 | // The stateful directory used by update_engine to store powerwash-safe files. |
| 50 | // The files stored here must be whitelisted in the powerwash scripts. |
| 51 | const char kPowerwashSafeDirectory[] = |
| 52 | "/mnt/stateful_partition/unencrypted/preserve"; |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 53 | |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 54 | // The powerwash_count marker file contains the number of times the device was |
| 55 | // powerwashed. This value is incremented by the clobber-state script when |
| 56 | // a powerwash is performed. |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 57 | const char kPowerwashCountMarker[] = "powerwash_count"; |
| 58 | |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 59 | // The name of the marker file used to trigger powerwash when post-install |
| 60 | // completes successfully so that the device is powerwashed on next reboot. |
| 61 | const char kPowerwashMarkerFile[] = |
| 62 | "/mnt/stateful_partition/factory_install_reset"; |
| 63 | |
Zentaro Kavanagh | 0418de3 | 2019-01-15 10:29:35 -0800 | [diff] [blame] | 64 | // The contents of the powerwash marker file for the non-rollback case. |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 65 | const char kPowerwashCommand[] = "safe fast keepimg reason=update_engine\n"; |
| 66 | |
Zentaro Kavanagh | 0418de3 | 2019-01-15 10:29:35 -0800 | [diff] [blame] | 67 | // The contents of the powerwas marker file for the rollback case. |
| 68 | const char kRollbackPowerwashCommand[] = |
| 69 | "safe fast keepimg rollback reason=update_engine\n"; |
| 70 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 71 | // UpdateManager config path. |
| 72 | const char* kConfigFilePath = "/etc/update_manager.conf"; |
| 73 | |
| 74 | // UpdateManager config options: |
| 75 | const char* kConfigOptsIsOOBEEnabled = "is_oobe_enabled"; |
| 76 | |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 77 | const char* kActivePingKey = "first_active_omaha_ping_sent"; |
| 78 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 79 | } // namespace |
| 80 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 81 | namespace chromeos_update_engine { |
| 82 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 83 | namespace hardware { |
| 84 | |
| 85 | // Factory defined in hardware.h. |
| 86 | std::unique_ptr<HardwareInterface> CreateHardware() { |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 87 | std::unique_ptr<HardwareChromeOS> hardware(new HardwareChromeOS()); |
| 88 | hardware->Init(); |
| 89 | return std::move(hardware); |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | } // namespace hardware |
| 93 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 94 | void HardwareChromeOS::Init() { |
| 95 | LoadConfig("" /* root_prefix */, IsNormalBootMode()); |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 96 | debugd_proxy_.reset( |
| 97 | new org::chromium::debugdProxy(DBusConnection::Get()->GetDBus())); |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 100 | bool HardwareChromeOS::IsOfficialBuild() const { |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 101 | return VbGetSystemPropertyInt("debug_build") == 0; |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 104 | bool HardwareChromeOS::IsNormalBootMode() const { |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 105 | bool dev_mode = VbGetSystemPropertyInt("devsw_boot") != 0; |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 106 | return !dev_mode; |
| 107 | } |
| 108 | |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 109 | bool HardwareChromeOS::AreDevFeaturesEnabled() const { |
| 110 | // Even though the debugd tools are also gated on devmode, checking here can |
| 111 | // save us a D-Bus call so it's worth doing explicitly. |
| 112 | if (IsNormalBootMode()) |
| 113 | return false; |
| 114 | |
| 115 | int32_t dev_features = debugd::DEV_FEATURES_DISABLED; |
| 116 | brillo::ErrorPtr error; |
| 117 | // Some boards may not include debugd so it's expected that this may fail, |
| 118 | // in which case we treat it as disabled. |
| 119 | if (debugd_proxy_ && debugd_proxy_->QueryDevFeatures(&dev_features, &error) && |
| 120 | !(dev_features & debugd::DEV_FEATURES_DISABLED)) { |
| 121 | LOG(INFO) << "Debugd dev tools enabled."; |
| 122 | return true; |
| 123 | } |
| 124 | return false; |
| 125 | } |
| 126 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 127 | bool HardwareChromeOS::IsOOBEEnabled() const { |
| 128 | return is_oobe_enabled_; |
| 129 | } |
| 130 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 131 | bool HardwareChromeOS::IsOOBEComplete(base::Time* out_time_of_oobe) const { |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 132 | if (!is_oobe_enabled_) { |
| 133 | LOG(WARNING) << "OOBE is not enabled but IsOOBEComplete() was called"; |
| 134 | } |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 135 | struct stat statbuf; |
| 136 | if (stat(kOOBECompletedMarker, &statbuf) != 0) { |
| 137 | if (errno != ENOENT) { |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 138 | PLOG(ERROR) << "Error getting information about " << kOOBECompletedMarker; |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 139 | } |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | if (out_time_of_oobe != nullptr) |
| 144 | *out_time_of_oobe = base::Time::FromTimeT(statbuf.st_mtime); |
| 145 | return true; |
| 146 | } |
| 147 | |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 148 | static string ReadValueFromCrosSystem(const string& key) { |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 149 | char value_buffer[VB_MAX_STRING_PROPERTY]; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 150 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 151 | const char* rv = VbGetSystemPropertyString( |
| 152 | key.c_str(), value_buffer, sizeof(value_buffer)); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 153 | if (rv != nullptr) { |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 154 | string return_value(value_buffer); |
Ben Chan | 736fcb5 | 2014-05-21 18:28:22 -0700 | [diff] [blame] | 155 | base::TrimWhitespaceASCII(return_value, base::TRIM_ALL, &return_value); |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 156 | return return_value; |
| 157 | } |
J. Richard Barnette | c7dd853 | 2013-10-29 16:30:46 -0700 | [diff] [blame] | 158 | |
| 159 | LOG(ERROR) << "Unable to read crossystem key " << key; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 160 | return ""; |
| 161 | } |
| 162 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 163 | string HardwareChromeOS::GetHardwareClass() const { |
Chris Masone | f8d037f | 2014-02-19 01:53:00 +0000 | [diff] [blame] | 164 | if (USE_HWID_OVERRIDE) { |
| 165 | return HwidOverride::Read(base::FilePath("/")); |
| 166 | } |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 167 | return ReadValueFromCrosSystem("hwid"); |
| 168 | } |
| 169 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 170 | string HardwareChromeOS::GetFirmwareVersion() const { |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 171 | return ReadValueFromCrosSystem("fwid"); |
| 172 | } |
| 173 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 174 | string HardwareChromeOS::GetECVersion() const { |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 175 | string input_line; |
| 176 | int exit_code = 0; |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 177 | vector<string> cmd = {"/usr/sbin/mosys", "-k", "ec", "info"}; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 178 | |
| 179 | bool success = Subprocess::SynchronousExec(cmd, &exit_code, &input_line); |
| 180 | if (!success || exit_code) { |
| 181 | LOG(ERROR) << "Unable to read ec info from mosys (" << exit_code << ")"; |
| 182 | return ""; |
| 183 | } |
| 184 | |
| 185 | return utils::ParseECVersion(input_line); |
| 186 | } |
| 187 | |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 188 | int HardwareChromeOS::GetMinKernelKeyVersion() const { |
| 189 | return VbGetSystemPropertyInt("tpm_kernver"); |
| 190 | } |
| 191 | |
Zentaro Kavanagh | 8f6f243 | 2018-05-16 13:48:12 -0700 | [diff] [blame] | 192 | int HardwareChromeOS::GetMaxFirmwareKeyRollforward() const { |
| 193 | return VbGetSystemPropertyInt("firmware_max_rollforward"); |
| 194 | } |
| 195 | |
| 196 | bool HardwareChromeOS::SetMaxFirmwareKeyRollforward( |
| 197 | int firmware_max_rollforward) { |
| 198 | // Not all devices have this field yet. So first try to read |
| 199 | // it and if there is an error just fail. |
| 200 | if (GetMaxFirmwareKeyRollforward() == -1) |
| 201 | return false; |
| 202 | |
| 203 | return VbSetSystemPropertyInt("firmware_max_rollforward", |
| 204 | firmware_max_rollforward) == 0; |
| 205 | } |
| 206 | |
Marton Hunyady | 99ced78 | 2018-05-08 12:59:50 +0200 | [diff] [blame] | 207 | int HardwareChromeOS::GetMinFirmwareKeyVersion() const { |
| 208 | return VbGetSystemPropertyInt("tpm_fwver"); |
| 209 | } |
| 210 | |
Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 211 | bool HardwareChromeOS::SetMaxKernelKeyRollforward(int kernel_max_rollforward) { |
| 212 | return VbSetSystemPropertyInt("kernel_max_rollforward", |
| 213 | kernel_max_rollforward) == 0; |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 216 | int HardwareChromeOS::GetPowerwashCount() const { |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 217 | int powerwash_count; |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 218 | base::FilePath marker_path = |
| 219 | base::FilePath(kPowerwashSafeDirectory).Append(kPowerwashCountMarker); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 220 | string contents; |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 221 | if (!utils::ReadFile(marker_path.value(), &contents)) |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 222 | return -1; |
| 223 | base::TrimWhitespaceASCII(contents, base::TRIM_TRAILING, &contents); |
| 224 | if (!base::StringToInt(contents, &powerwash_count)) |
| 225 | return -1; |
| 226 | return powerwash_count; |
| 227 | } |
| 228 | |
Zentaro Kavanagh | 0418de3 | 2019-01-15 10:29:35 -0800 | [diff] [blame] | 229 | bool HardwareChromeOS::SchedulePowerwash(bool is_rollback) { |
| 230 | const char* powerwash_command = |
| 231 | is_rollback ? kRollbackPowerwashCommand : kPowerwashCommand; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 232 | bool result = utils::WriteFile( |
Zentaro Kavanagh | 0418de3 | 2019-01-15 10:29:35 -0800 | [diff] [blame] | 233 | kPowerwashMarkerFile, powerwash_command, strlen(powerwash_command)); |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 234 | if (result) { |
Alex Deymo | caa4672 | 2016-06-09 12:08:29 -0700 | [diff] [blame] | 235 | LOG(INFO) << "Created " << kPowerwashMarkerFile |
Zentaro Kavanagh | 0418de3 | 2019-01-15 10:29:35 -0800 | [diff] [blame] | 236 | << " to powerwash on next reboot (is_rollback=" << is_rollback |
| 237 | << ")"; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 238 | } else { |
Alex Deymo | caa4672 | 2016-06-09 12:08:29 -0700 | [diff] [blame] | 239 | PLOG(ERROR) << "Error in creating powerwash marker file: " |
| 240 | << kPowerwashMarkerFile; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | return result; |
| 244 | } |
| 245 | |
| 246 | bool HardwareChromeOS::CancelPowerwash() { |
| 247 | bool result = base::DeleteFile(base::FilePath(kPowerwashMarkerFile), false); |
| 248 | |
| 249 | if (result) { |
| 250 | LOG(INFO) << "Successfully deleted the powerwash marker file : " |
Alex Deymo | caa4672 | 2016-06-09 12:08:29 -0700 | [diff] [blame] | 251 | << kPowerwashMarkerFile; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 252 | } else { |
| 253 | PLOG(ERROR) << "Could not delete the powerwash marker file : " |
Alex Deymo | caa4672 | 2016-06-09 12:08:29 -0700 | [diff] [blame] | 254 | << kPowerwashMarkerFile; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | return result; |
| 258 | } |
| 259 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 260 | bool HardwareChromeOS::GetNonVolatileDirectory(base::FilePath* path) const { |
Sen Jiang | 9c12346 | 2015-11-19 13:16:23 -0800 | [diff] [blame] | 261 | *path = base::FilePath(constants::kNonVolatileDirectory); |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 262 | return true; |
| 263 | } |
| 264 | |
| 265 | bool HardwareChromeOS::GetPowerwashSafeDirectory(base::FilePath* path) const { |
| 266 | *path = base::FilePath(kPowerwashSafeDirectory); |
| 267 | return true; |
| 268 | } |
| 269 | |
Sen Jiang | 5011df6 | 2017-06-28 17:13:19 -0700 | [diff] [blame] | 270 | int64_t HardwareChromeOS::GetBuildTimestamp() const { |
| 271 | // TODO(senj): implement this in Chrome OS. |
| 272 | return 0; |
| 273 | } |
| 274 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 275 | void HardwareChromeOS::LoadConfig(const string& root_prefix, bool normal_mode) { |
| 276 | brillo::KeyValueStore store; |
| 277 | |
| 278 | if (normal_mode) { |
| 279 | store.Load(base::FilePath(root_prefix + kConfigFilePath)); |
| 280 | } else { |
| 281 | if (store.Load(base::FilePath(root_prefix + kStatefulPartition + |
| 282 | kConfigFilePath))) { |
| 283 | LOG(INFO) << "UpdateManager Config loaded from stateful partition."; |
| 284 | } else { |
| 285 | store.Load(base::FilePath(root_prefix + kConfigFilePath)); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | if (!store.GetBoolean(kConfigOptsIsOOBEEnabled, &is_oobe_enabled_)) |
| 290 | is_oobe_enabled_ = true; // Default value. |
| 291 | } |
| 292 | |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 293 | bool HardwareChromeOS::GetFirstActiveOmahaPingSent() const { |
| 294 | int exit_code = 0; |
| 295 | string active_ping_str; |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 296 | vector<string> cmd = {"vpd_get_value", kActivePingKey}; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 297 | if (!Subprocess::SynchronousExec(cmd, &exit_code, &active_ping_str) || |
| 298 | exit_code) { |
| 299 | LOG(ERROR) << "Failed to get vpd key for " << kActivePingKey |
| 300 | << " with exit code: " << exit_code; |
| 301 | return false; |
| 302 | } |
| 303 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 304 | base::TrimWhitespaceASCII(active_ping_str, base::TRIM_ALL, &active_ping_str); |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 305 | int active_ping; |
| 306 | if (active_ping_str.empty() || |
| 307 | !base::StringToInt(active_ping_str, &active_ping)) { |
| 308 | LOG(INFO) << "Failed to parse active_ping value: " << active_ping_str; |
| 309 | return false; |
| 310 | } |
| 311 | return static_cast<bool>(active_ping); |
| 312 | } |
| 313 | |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 314 | bool HardwareChromeOS::SetFirstActiveOmahaPingSent() { |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 315 | int exit_code = 0; |
| 316 | string output; |
| 317 | vector<string> vpd_set_cmd = { |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 318 | "vpd", "-i", "RW_VPD", "-s", string(kActivePingKey) + "=1"}; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 319 | if (!Subprocess::SynchronousExec(vpd_set_cmd, &exit_code, &output) || |
| 320 | exit_code) { |
| 321 | LOG(ERROR) << "Failed to set vpd key for " << kActivePingKey |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 322 | << " with exit code: " << exit_code << " with error: " << output; |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 323 | return false; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 326 | vector<string> vpd_dump_cmd = {"dump_vpd_log", "--force"}; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 327 | if (!Subprocess::SynchronousExec(vpd_dump_cmd, &exit_code, &output) || |
| 328 | exit_code) { |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 329 | LOG(ERROR) << "Failed to cache " << kActivePingKey << " using dump_vpd_log" |
| 330 | << " with exit code: " << exit_code << " with error: " << output; |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 331 | return false; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 332 | } |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 333 | return true; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Tianjie Xu | d6aa91f | 2019-11-14 11:55:10 -0800 | [diff] [blame] | 336 | void HardwareChromeOS::SetWarmReset(bool warm_reset) {} |
| 337 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 338 | } // namespace chromeos_update_engine |