blob: b37b0074211d30e8ababf82d02baf1dd4f8eba8a [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
Sen Jiang5011df62017-06-28 17:13:19 -070020#include <stdint.h>
21
Alex Deymo42432912013-07-12 20:21:15 -070022#include <string>
Alex Vakulenko59e253e2014-02-24 10:40:21 -080023#include <vector>
Alex Deymo42432912013-07-12 20:21:15 -070024
Alex Deymodd132f32015-09-14 19:12:07 -070025#include <base/files/file_path.h>
Alex Deymobccbc382014-04-03 13:38:55 -070026#include <base/time/time.h>
27
Yifan Hong87029332020-09-01 17:20:08 -070028#include "update_engine/common/error_code.h"
29
Alex Deymo42432912013-07-12 20:21:15 -070030namespace chromeos_update_engine {
31
Alex Deymo763e7db2015-08-27 21:08:08 -070032// The hardware interface allows access to the crossystem exposed properties,
33// such as the firmware version, hwid, verified boot mode.
Alex Deymo42432912013-07-12 20:21:15 -070034// These stateless functions are tied together in this interface to facilitate
35// unit testing.
36class HardwareInterface {
37 public:
Alex Deymo610277e2014-11-11 21:18:11 -080038 virtual ~HardwareInterface() {}
39
Alex Deymo1c4e84a2015-09-22 16:58:10 -070040 // Returns whether this is an official build. Official build means that the
41 // server maintains and updates the build, so update_engine should run and
42 // periodically check for updates.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080043 virtual bool IsOfficialBuild() const = 0;
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070044
45 // Returns true if the boot mode is normal or if it's unable to
46 // determine the boot mode. Returns false if the boot mode is
Alex Deymo1c4e84a2015-09-22 16:58:10 -070047 // developer. A dev-mode boot will allow the user to access developer-only
48 // features.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080049 virtual bool IsNormalBootMode() const = 0;
J. Richard Barnette522d36f2013-10-28 17:22:12 -070050
Sen Jiange67bb5b2016-06-20 15:53:56 -070051 // Returns whether the developer features are enabled.
52 virtual bool AreDevFeaturesEnabled() const = 0;
53
Alex Deymo46a9aae2016-05-04 20:20:11 -070054 // Returns whether the device has an OOBE flow that the user must go through
55 // before getting non-critical updates. Use IsOOBEComplete() to determine if
56 // that flow is complete.
57 virtual bool IsOOBEEnabled() const = 0;
58
Alex Deymobccbc382014-04-03 13:38:55 -070059 // Returns true if the OOBE process has been completed and EULA accepted,
60 // False otherwise. If True is returned, and |out_time_of_oobe| isn't null,
61 // the time-stamp of when OOBE happened is stored at |out_time_of_oobe|.
62 virtual bool IsOOBEComplete(base::Time* out_time_of_oobe) const = 0;
63
J. Richard Barnette522d36f2013-10-28 17:22:12 -070064 // Returns the HWID or an empty string on error.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080065 virtual std::string GetHardwareClass() const = 0;
J. Richard Barnette522d36f2013-10-28 17:22:12 -070066
67 // Returns the firmware version or an empty string if the system is
68 // not running chrome os firmware.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080069 virtual std::string GetFirmwareVersion() const = 0;
J. Richard Barnette522d36f2013-10-28 17:22:12 -070070
71 // Returns the ec version or an empty string if the system is not
72 // running a custom chrome os ec.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080073 virtual std::string GetECVersion() const = 0;
Alex Deymo42432912013-07-12 20:21:15 -070074
Matt Ziegelbaumaa8e1a42019-05-09 21:41:58 -040075 // Returns the OEM device requisition or an empty string if the system does
76 // not have a requisition, or if not running Chrome OS.
77 virtual std::string GetDeviceRequisition() const = 0;
78
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -080079 // Returns the minimum kernel key version that verified boot on Chrome OS
80 // will allow to boot. This is the value of crossystem tpm_kernver. Returns
81 // -1 on error, or if not running on Chrome OS.
82 virtual int GetMinKernelKeyVersion() const = 0;
83
Marton Hunyady99ced782018-05-08 12:59:50 +020084 // Returns the minimum firmware key version that verified boot on Chrome OS
85 // will allow to boot. This is the value of crossystem tpm_fwver. Returns
86 // -1 on error, or if not running on Chrome OS.
87 virtual int GetMinFirmwareKeyVersion() const = 0;
88
Zentaro Kavanagh8f6f2432018-05-16 13:48:12 -070089 // Returns the maximum firmware key version that verified boot should roll
90 // forward to. This is the value of crossystem firmware_max_rollforward.
91 // Returns -1 on error, if this board does not yet support this value, or
92 // if not running on Chrome OS.
93 virtual int GetMaxFirmwareKeyRollforward() const = 0;
94
95 // Sets the maximum firmware key version that verified boot should roll
96 // forward to. This is the value of crossystem firmware_max_rollforward.
97 // This value is not available on all Chrome OS devices.
98 virtual bool SetMaxFirmwareKeyRollforward(int firmware_max_rollforward) = 0;
99
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -0800100 // Sets the maximum kernel key version that verified boot should roll
Zentaro Kavanagh5d956152018-05-15 09:40:33 -0700101 // forward to. This is the value of crossystem kernel_max_rollforward.
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -0800102 // Returns false if the value cannot be set, or if not running on Chrome OS.
Zentaro Kavanagh5d956152018-05-15 09:40:33 -0700103 virtual bool SetMaxKernelKeyRollforward(int kernel_max_rollforward) = 0;
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -0800104
Alex Deymoebbe7ef2014-10-30 13:02:49 -0700105 // Returns the powerwash_count from the stateful. If the file is not found
106 // or is invalid, returns -1. Brand new machines out of the factory or after
107 // recovery don't have this value set.
108 virtual int GetPowerwashCount() const = 0;
Alex Deymodd132f32015-09-14 19:12:07 -0700109
Alex Deymofb905d92016-06-03 19:26:58 -0700110 // Signals that a powerwash (stateful partition wipe) should be performed
Zentaro Kavanagh28def4f2019-01-15 17:15:01 -0800111 // after reboot. If |save_rollback_data| is true additional state is
112 // preserved during shutdown that can be restored after the powerwash.
113 virtual bool SchedulePowerwash(bool save_rollback_data) = 0;
Alex Deymofb905d92016-06-03 19:26:58 -0700114
115 // Cancel the powerwash operation scheduled to be performed on next boot.
116 virtual bool CancelPowerwash() = 0;
117
Alex Deymodd132f32015-09-14 19:12:07 -0700118 // Store in |path| the path to a non-volatile directory (persisted across
119 // reboots) available for this daemon. In case of an error, such as no
120 // directory available, returns false.
121 virtual bool GetNonVolatileDirectory(base::FilePath* path) const = 0;
122
123 // Store in |path| the path to a non-volatile directory persisted across
124 // powerwash cycles. In case of an error, such as no directory available,
125 // returns false.
126 virtual bool GetPowerwashSafeDirectory(base::FilePath* path) const = 0;
Sen Jiang5011df62017-06-28 17:13:19 -0700127
128 // Returns the timestamp of the current OS build.
129 virtual int64_t GetBuildTimestamp() const = 0;
Sen Jiang44906962018-01-08 17:39:04 -0800130
Tianjie Xu4ad3af62019-10-30 11:59:45 -0700131 // Returns true if the current OS build allows installing the payload with an
132 // older timestamp.
133 virtual bool AllowDowngrade() const = 0;
134
Amin Hassani1677e812017-06-21 13:36:36 -0700135 // Returns whether the first active ping was sent to Omaha at some point, and
136 // that the value is persisted across recovery (and powerwash) once set with
137 // |SetFirstActiveOmahaPingSent()|.
138 virtual bool GetFirstActiveOmahaPingSent() const = 0;
139
Amin Hassani80f4d4c2018-05-16 13:34:00 -0700140 // Persist the fact that first active ping was sent to omaha and returns false
141 // if failed to persist it.
142 virtual bool SetFirstActiveOmahaPingSent() = 0;
Tianjie Xud6aa91f2019-11-14 11:55:10 -0800143
144 // If |warm_reset| is true, sets the warm reset to indicate a warm reset is
145 // needed on the next reboot. Otherwise, clears the flag.
146 virtual void SetWarmReset(bool warm_reset) = 0;
Kelvin Zhangd7191032020-08-11 10:48:16 -0400147
148 // Return the version/timestamp for partition `partition_name`.
149 // Don't make any assumption about the formatting of returned string.
150 // Only used for logging/debugging purposes.
151 virtual std::string GetVersionForLogging(
152 const std::string& partition_name) const = 0;
153
154 // Return true if and only if `new_version` is "newer" than the
155 // version number of partition `partition_name`. The notion of
156 // "newer" is defined by this function. Caller should not make
157 // any assumption about the underlying logic.
Yifan Hong87029332020-09-01 17:20:08 -0700158 // Return:
159 // - kSuccess if update is valid.
160 // - kPayloadTimestampError if downgrade is detected
161 // - kDownloadManifestParseError if |new_version| has an incorrect format
162 // - Other error values if the source of error is known, or kError for
163 // a generic error on the device.
164 virtual ErrorCode IsPartitionUpdateValid(
165 const std::string& partition_name,
166 const std::string& new_version) const = 0;
Alex Deymo42432912013-07-12 20:21:15 -0700167};
168
169} // namespace chromeos_update_engine
170
Alex Deymo39910dc2015-11-09 17:04:30 -0800171#endif // UPDATE_ENGINE_COMMON_HARDWARE_INTERFACE_H_