blob: 4946b915a8a24769ae96d5f1e69ccf193a4a2866 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Deymo42432912013-07-12 20:21:15 -070016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#ifndef UPDATE_ENGINE_COMMON_HARDWARE_INTERFACE_H_
18#define UPDATE_ENGINE_COMMON_HARDWARE_INTERFACE_H_
Alex Deymo42432912013-07-12 20:21:15 -070019
20#include <string>
Alex Vakulenko59e253e2014-02-24 10:40:21 -080021#include <vector>
Alex Deymo42432912013-07-12 20:21:15 -070022
Alex Deymodd132f32015-09-14 19:12:07 -070023#include <base/files/file_path.h>
Alex Deymobccbc382014-04-03 13:38:55 -070024#include <base/time/time.h>
25
Alex Deymo42432912013-07-12 20:21:15 -070026namespace chromeos_update_engine {
27
Alex Deymo763e7db2015-08-27 21:08:08 -070028// The hardware interface allows access to the crossystem exposed properties,
29// such as the firmware version, hwid, verified boot mode.
Alex Deymo42432912013-07-12 20:21:15 -070030// These stateless functions are tied together in this interface to facilitate
31// unit testing.
32class HardwareInterface {
33 public:
Alex Deymo610277e2014-11-11 21:18:11 -080034 virtual ~HardwareInterface() {}
35
Alex Deymo1c4e84a2015-09-22 16:58:10 -070036 // Returns whether this is an official build. Official build means that the
37 // server maintains and updates the build, so update_engine should run and
38 // periodically check for updates.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080039 virtual bool IsOfficialBuild() const = 0;
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070040
41 // Returns true if the boot mode is normal or if it's unable to
42 // determine the boot mode. Returns false if the boot mode is
Alex Deymo1c4e84a2015-09-22 16:58:10 -070043 // developer. A dev-mode boot will allow the user to access developer-only
44 // features.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080045 virtual bool IsNormalBootMode() const = 0;
J. Richard Barnette522d36f2013-10-28 17:22:12 -070046
Sen Jiange67bb5b2016-06-20 15:53:56 -070047 // Returns whether the developer features are enabled.
48 virtual bool AreDevFeaturesEnabled() const = 0;
49
Alex Deymo46a9aae2016-05-04 20:20:11 -070050 // Returns whether the device has an OOBE flow that the user must go through
51 // before getting non-critical updates. Use IsOOBEComplete() to determine if
52 // that flow is complete.
53 virtual bool IsOOBEEnabled() const = 0;
54
Alex Deymobccbc382014-04-03 13:38:55 -070055 // Returns true if the OOBE process has been completed and EULA accepted,
56 // False otherwise. If True is returned, and |out_time_of_oobe| isn't null,
57 // the time-stamp of when OOBE happened is stored at |out_time_of_oobe|.
58 virtual bool IsOOBEComplete(base::Time* out_time_of_oobe) const = 0;
59
J. Richard Barnette522d36f2013-10-28 17:22:12 -070060 // Returns the HWID or an empty string on error.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080061 virtual std::string GetHardwareClass() const = 0;
J. Richard Barnette522d36f2013-10-28 17:22:12 -070062
63 // Returns the firmware version or an empty string if the system is
64 // not running chrome os firmware.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080065 virtual std::string GetFirmwareVersion() const = 0;
J. Richard Barnette522d36f2013-10-28 17:22:12 -070066
67 // Returns the ec version or an empty string if the system is not
68 // running a custom chrome os ec.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080069 virtual std::string GetECVersion() const = 0;
Alex Deymo42432912013-07-12 20:21:15 -070070
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -080071 // Returns the minimum kernel key version that verified boot on Chrome OS
72 // will allow to boot. This is the value of crossystem tpm_kernver. Returns
73 // -1 on error, or if not running on Chrome OS.
74 virtual int GetMinKernelKeyVersion() const = 0;
75
Marton Hunyady99ced782018-05-08 12:59:50 +020076 // Returns the minimum firmware key version that verified boot on Chrome OS
77 // will allow to boot. This is the value of crossystem tpm_fwver. Returns
78 // -1 on error, or if not running on Chrome OS.
79 virtual int GetMinFirmwareKeyVersion() const = 0;
80
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -080081 // Sets the maximum kernel key version that verified boot should roll
82 // forward to. This is the value of crossystem max_kernel_rollforward.
83 // Returns false if the value cannot be set, or if not running on Chrome OS.
84 virtual bool SetMaxKernelKeyRollforward(int max_kernel_rollforward) = 0;
85
Alex Deymoebbe7ef2014-10-30 13:02:49 -070086 // Returns the powerwash_count from the stateful. If the file is not found
87 // or is invalid, returns -1. Brand new machines out of the factory or after
88 // recovery don't have this value set.
89 virtual int GetPowerwashCount() const = 0;
Alex Deymodd132f32015-09-14 19:12:07 -070090
Alex Deymofb905d92016-06-03 19:26:58 -070091 // Signals that a powerwash (stateful partition wipe) should be performed
92 // after reboot.
93 virtual bool SchedulePowerwash() = 0;
94
95 // Cancel the powerwash operation scheduled to be performed on next boot.
96 virtual bool CancelPowerwash() = 0;
97
Alex Deymodd132f32015-09-14 19:12:07 -070098 // Store in |path| the path to a non-volatile directory (persisted across
99 // reboots) available for this daemon. In case of an error, such as no
100 // directory available, returns false.
101 virtual bool GetNonVolatileDirectory(base::FilePath* path) const = 0;
102
103 // Store in |path| the path to a non-volatile directory persisted across
104 // powerwash cycles. In case of an error, such as no directory available,
105 // returns false.
106 virtual bool GetPowerwashSafeDirectory(base::FilePath* path) const = 0;
Amin Hassani1677e812017-06-21 13:36:36 -0700107
108 // Returns whether the first active ping was sent to Omaha at some point, and
109 // that the value is persisted across recovery (and powerwash) once set with
110 // |SetFirstActiveOmahaPingSent()|.
111 virtual bool GetFirstActiveOmahaPingSent() const = 0;
112
113 // Persist the fact that first active ping was sent to omaha. It bails out if
114 // it fails.
115 virtual void SetFirstActiveOmahaPingSent() = 0;
Alex Deymo42432912013-07-12 20:21:15 -0700116};
117
118} // namespace chromeos_update_engine
119
Alex Deymo39910dc2015-11-09 17:04:30 -0800120#endif // UPDATE_ENGINE_COMMON_HARDWARE_INTERFACE_H_