blob: 42737bbbaa55a69ac75e0624b8c73b986250306c [file] [log] [blame]
Jay Srinivasan43488792012-06-19 00:25:31 -07001// 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 Srinivasan55f50c22013-01-10 19:24:35 -08007#include "update_engine/real_system_state.h"
Jay Srinivasan43488792012-06-19 00:25:31 -07008
9namespace chromeos_update_engine {
10
11static const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed";
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080012static const char kPrefsDirectory[] = "/var/lib/update_engine/prefs";
Jay Srinivasan43488792012-06-19 00:25:31 -070013
Jay Srinivasan34b5d862012-07-23 11:43:22 -070014RealSystemState::RealSystemState()
15 : device_policy_(NULL),
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080016 connection_manager_(this) {}
17
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080018bool RealSystemState::Initialize(bool enable_gpio) {
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080019 metrics_lib_.Init();
20
21 if (!prefs_.Init(FilePath(kPrefsDirectory))) {
22 LOG(ERROR) << "Failed to initialize preferences.";
23 return false;
24 }
25
26 if (!payload_state_.Initialize(&prefs_))
27 return false;
28
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080029 // Initialize the GPIO handler as instructed.
30 if (enable_gpio) {
31 // A real GPIO handler. Defer GPIO discovery to ensure the udev has ample
32 // time to export the devices. Also require that test mode is physically
33 // queried at most once and the result cached, for a more consistent update
34 // behavior.
35 udev_iface_.reset(new StandardUdevInterface());
36 file_descriptor_.reset(new EintrSafeFileDescriptor());
37 gpio_handler_.reset(new StandardGpioHandler(udev_iface_.get(),
38 file_descriptor_.get(),
39 true, true));
40 } else {
41 // A no-op GPIO handler, always indicating a non-test mode.
42 gpio_handler_.reset(new NoopGpioHandler(false));
43 }
44
Jay Srinivasan55f50c22013-01-10 19:24:35 -080045 // Create the update attempter.
46 update_attempter_.reset(new UpdateAttempter(this, &dbus_));
47
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080048 // All is well. Initialization successful.
49 return true;
50}
Jay Srinivasan43488792012-06-19 00:25:31 -070051
52bool RealSystemState::IsOOBEComplete() {
53 return file_util::PathExists(FilePath(kOOBECompletedMarker));
54}
55
Jay Srinivasan43488792012-06-19 00:25:31 -070056} // namespace chromeos_update_engine