Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <base/file_util.h> |
| 6 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 7 | #include "update_engine/real_system_state.h" |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 8 | #include "update_engine/utils.h" |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 9 | |
| 10 | namespace chromeos_update_engine { |
| 11 | |
| 12 | static const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed"; |
| 13 | |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 14 | RealSystemState::RealSystemState() |
| 15 | : device_policy_(NULL), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 16 | connection_manager_(this), |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 17 | request_params_(this), |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 18 | p2p_manager_(NULL), |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 19 | system_rebooted_(false) {} |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 20 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 21 | bool RealSystemState::Initialize(bool enable_gpio) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 22 | metrics_lib_.Init(); |
| 23 | |
| 24 | if (!prefs_.Init(FilePath(kPrefsDirectory))) { |
| 25 | LOG(ERROR) << "Failed to initialize preferences."; |
| 26 | return false; |
| 27 | } |
| 28 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 29 | if (!powerwash_safe_prefs_.Init(FilePath(kPowerwashSafePrefsDir))) { |
| 30 | LOG(ERROR) << "Failed to initialize powerwash preferences."; |
| 31 | return false; |
| 32 | } |
| 33 | |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 34 | if (!utils::FileExists(kSystemRebootedMarkerFile)) { |
| 35 | if (!utils::WriteFile(kSystemRebootedMarkerFile, "", 0)) { |
| 36 | LOG(ERROR) << "Could not create reboot marker file"; |
| 37 | return false; |
| 38 | } |
| 39 | system_rebooted_ = true; |
| 40 | } |
| 41 | |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 42 | p2p_manager_.reset(P2PManager::Construct(NULL, &prefs_, "cros_au", |
| 43 | kMaxP2PFilesToKeep)); |
| 44 | |
Jay Srinivasan | 19409b7 | 2013-04-12 19:23:36 -0700 | [diff] [blame] | 45 | if (!payload_state_.Initialize(this)) |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 46 | return false; |
| 47 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 48 | // Initialize the GPIO handler as instructed. |
| 49 | if (enable_gpio) { |
| 50 | // A real GPIO handler. Defer GPIO discovery to ensure the udev has ample |
| 51 | // time to export the devices. Also require that test mode is physically |
| 52 | // queried at most once and the result cached, for a more consistent update |
| 53 | // behavior. |
| 54 | udev_iface_.reset(new StandardUdevInterface()); |
| 55 | file_descriptor_.reset(new EintrSafeFileDescriptor()); |
| 56 | gpio_handler_.reset(new StandardGpioHandler(udev_iface_.get(), |
| 57 | file_descriptor_.get(), |
| 58 | true, true)); |
| 59 | } else { |
| 60 | // A no-op GPIO handler, always indicating a non-test mode. |
| 61 | gpio_handler_.reset(new NoopGpioHandler(false)); |
| 62 | } |
| 63 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 64 | // Create the update attempter. |
| 65 | update_attempter_.reset(new UpdateAttempter(this, &dbus_)); |
| 66 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 67 | // All is well. Initialization successful. |
| 68 | return true; |
| 69 | } |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 70 | |
| 71 | bool RealSystemState::IsOOBEComplete() { |
| 72 | return file_util::PathExists(FilePath(kOOBECompletedMarker)); |
| 73 | } |
| 74 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 75 | } // namespace chromeos_update_engine |