blob: 068468b824517a660fea631ad124c1668beb62de [file] [log] [blame]
Alex Deymo40d86b22015-09-03 22:27:10 -07001//
2// Copyright (C) 2015 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//
16
Alex Deymo1b03f9f2015-12-09 00:38:36 -080017#include "update_engine/hardware_android.h"
Alex Deymo40d86b22015-09-03 22:27:10 -070018
Alex Deymofb905d92016-06-03 19:26:58 -070019#include <sys/types.h>
20
Tom Cherryfadd03c2017-10-10 14:45:09 -070021#include <memory>
Alex Deymofb905d92016-06-03 19:26:58 -070022
Tom Cherryfadd03c2017-10-10 14:45:09 -070023#include <android-base/properties.h>
Alex Deymodd132f32015-09-14 19:12:07 -070024#include <base/files/file_util.h>
Tao Bao304680c2018-03-31 10:36:52 -070025#include <bootloader_message/bootloader_message.h>
Alex Deymo40d86b22015-09-03 22:27:10 -070026
Alex Deymo39910dc2015-11-09 17:04:30 -080027#include "update_engine/common/hardware.h"
Sen Jiang9c123462015-11-19 13:16:23 -080028#include "update_engine/common/platform_constants.h"
Alex Deymo40d86b22015-09-03 22:27:10 -070029
Tom Cherryfadd03c2017-10-10 14:45:09 -070030using android::base::GetBoolProperty;
31using android::base::GetIntProperty;
32using android::base::GetProperty;
Alex Deymo40d86b22015-09-03 22:27:10 -070033using std::string;
34
35namespace chromeos_update_engine {
36
Alex Deymofb905d92016-06-03 19:26:58 -070037namespace {
38
Alex Deymoebf6e122017-03-10 16:12:01 -080039// Android properties that identify the hardware and potentially non-updatable
40// parts of the bootloader (such as the bootloader version and the baseband
41// version).
42const char kPropBootBootloader[] = "ro.boot.bootloader";
43const char kPropBootBaseband[] = "ro.boot.baseband";
44const char kPropProductManufacturer[] = "ro.product.manufacturer";
45const char kPropBootHardwareSKU[] = "ro.boot.hardware.sku";
46const char kPropBootRevision[] = "ro.boot.revision";
Sen Jiang5011df62017-06-28 17:13:19 -070047const char kPropBuildDateUTC[] = "ro.build.date.utc";
Alex Deymoebf6e122017-03-10 16:12:01 -080048
Alex Deymofb905d92016-06-03 19:26:58 -070049} // namespace
50
Alex Deymo40d86b22015-09-03 22:27:10 -070051namespace hardware {
52
53// Factory defined in hardware.h.
54std::unique_ptr<HardwareInterface> CreateHardware() {
Ben Chanab5a0af2017-10-12 14:57:50 -070055 return std::make_unique<HardwareAndroid>();
Alex Deymo40d86b22015-09-03 22:27:10 -070056}
57
58} // namespace hardware
59
Alex Deymo1c4e84a2015-09-22 16:58:10 -070060// In Android there are normally three kinds of builds: eng, userdebug and user.
61// These builds target respectively a developer build, a debuggable version of
62// the final product and the pristine final product the end user will run.
63// Apart from the ro.build.type property name, they differ in the following
64// properties that characterize the builds:
65// * eng builds: ro.secure=0 and ro.debuggable=1
66// * userdebug builds: ro.secure=1 and ro.debuggable=1
67// * user builds: ro.secure=1 and ro.debuggable=0
68//
69// See IsOfficialBuild() and IsNormalMode() for the meaning of these options in
70// Android.
71
Alex Deymo40d86b22015-09-03 22:27:10 -070072bool HardwareAndroid::IsOfficialBuild() const {
Alex Deymo1c4e84a2015-09-22 16:58:10 -070073 // We run an official build iff ro.secure == 1, because we expect the build to
74 // behave like the end user product and check for updates. Note that while
75 // developers are able to build "official builds" by just running "make user",
76 // that will only result in a more restrictive environment. The important part
77 // is that we don't produce and push "non-official" builds to the end user.
78 //
79 // In case of a non-bool value, we take the most restrictive option and
80 // assume we are in an official-build.
Tom Cherryfadd03c2017-10-10 14:45:09 -070081 return GetBoolProperty("ro.secure", true);
Alex Deymo40d86b22015-09-03 22:27:10 -070082}
83
84bool HardwareAndroid::IsNormalBootMode() const {
Alex Deymo1c4e84a2015-09-22 16:58:10 -070085 // We are running in "dev-mode" iff ro.debuggable == 1. In dev-mode the
86 // update_engine will allow extra developers options, such as providing a
87 // different update URL. In case of error, we assume the build is in
88 // normal-mode.
Tom Cherryfadd03c2017-10-10 14:45:09 -070089 return !GetBoolProperty("ro.debuggable", false);
Alex Deymo40d86b22015-09-03 22:27:10 -070090}
91
Sen Jiange67bb5b2016-06-20 15:53:56 -070092bool HardwareAndroid::AreDevFeaturesEnabled() const {
93 return !IsNormalBootMode();
94}
95
Alex Deymo46a9aae2016-05-04 20:20:11 -070096bool HardwareAndroid::IsOOBEEnabled() const {
97 // No OOBE flow blocking updates for Android-based boards.
98 return false;
99}
100
Alex Deymo40d86b22015-09-03 22:27:10 -0700101bool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const {
Alex Deymo46a9aae2016-05-04 20:20:11 -0700102 LOG(WARNING) << "OOBE is not enabled but IsOOBEComplete() called.";
Alex Deymo4d2990d2015-09-15 12:11:26 -0700103 if (out_time_of_oobe)
104 *out_time_of_oobe = base::Time();
Alex Deymo40d86b22015-09-03 22:27:10 -0700105 return true;
106}
107
108string HardwareAndroid::GetHardwareClass() const {
Tom Cherryfadd03c2017-10-10 14:45:09 -0700109 auto manufacturer = GetProperty(kPropProductManufacturer, "");
110 auto sku = GetProperty(kPropBootHardwareSKU, "");
111 auto revision = GetProperty(kPropBootRevision, "");
Alex Deymoebf6e122017-03-10 16:12:01 -0800112
Tom Cherryfadd03c2017-10-10 14:45:09 -0700113 return manufacturer + ":" + sku + ":" + revision;
Alex Deymo40d86b22015-09-03 22:27:10 -0700114}
115
116string HardwareAndroid::GetFirmwareVersion() const {
Tom Cherryfadd03c2017-10-10 14:45:09 -0700117 return GetProperty(kPropBootBootloader, "");
Alex Deymo40d86b22015-09-03 22:27:10 -0700118}
119
120string HardwareAndroid::GetECVersion() const {
Tom Cherryfadd03c2017-10-10 14:45:09 -0700121 return GetProperty(kPropBootBaseband, "");
Alex Deymo40d86b22015-09-03 22:27:10 -0700122}
123
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -0800124int HardwareAndroid::GetMinKernelKeyVersion() const {
125 LOG(WARNING) << "STUB: No Kernel key version is available.";
126 return -1;
127}
128
Marton Hunyady99ced782018-05-08 12:59:50 +0200129int HardwareAndroid::GetMinFirmwareKeyVersion() const {
130 LOG(WARNING) << "STUB: No Firmware key version is available.";
131 return -1;
132}
133
Zentaro Kavanagh8f6f2432018-05-16 13:48:12 -0700134int HardwareAndroid::GetMaxFirmwareKeyRollforward() const {
135 LOG(WARNING) << "STUB: Getting firmware_max_rollforward is not supported.";
136 return -1;
137}
138
139bool HardwareAndroid::SetMaxFirmwareKeyRollforward(
140 int firmware_max_rollforward) {
141 LOG(WARNING) << "STUB: Setting firmware_max_rollforward is not supported.";
142 return false;
143}
144
Zentaro Kavanagh5d956152018-05-15 09:40:33 -0700145bool HardwareAndroid::SetMaxKernelKeyRollforward(int kernel_max_rollforward) {
146 LOG(WARNING) << "STUB: Setting kernel_max_rollforward is not supported.";
Zentaro Kavanaghbaacb982018-02-20 17:48:39 -0800147 return false;
148}
149
Alex Deymo40d86b22015-09-03 22:27:10 -0700150int HardwareAndroid::GetPowerwashCount() const {
151 LOG(WARNING) << "STUB: Assuming no factory reset was performed.";
152 return 0;
153}
154
Zentaro Kavanagh0418de32019-01-15 10:29:35 -0800155bool HardwareAndroid::SchedulePowerwash(bool is_rollback) {
Alex Deymofb905d92016-06-03 19:26:58 -0700156 LOG(INFO) << "Scheduling a powerwash to BCB.";
Zentaro Kavanagh0418de32019-01-15 10:29:35 -0800157 LOG_IF(WARNING, is_rollback) << "is_rollback was true but isn't supported.";
Sen Jiangd944faa2018-08-22 18:46:39 -0700158 string err;
159 if (!update_bootloader_message({"--wipe_data", "--reason=wipe_data_from_ota"},
160 &err)) {
161 LOG(ERROR) << "Failed to update bootloader message: " << err;
162 return false;
163 }
164 return true;
Alex Deymofb905d92016-06-03 19:26:58 -0700165}
166
167bool HardwareAndroid::CancelPowerwash() {
Sen Jiangd944faa2018-08-22 18:46:39 -0700168 string err;
169 if (!clear_bootloader_message(&err)) {
170 LOG(ERROR) << "Failed to clear bootloader message: " << err;
171 return false;
172 }
173 return true;
Alex Deymofb905d92016-06-03 19:26:58 -0700174}
175
Alex Deymodd132f32015-09-14 19:12:07 -0700176bool HardwareAndroid::GetNonVolatileDirectory(base::FilePath* path) const {
Sen Jiang9c123462015-11-19 13:16:23 -0800177 base::FilePath local_path(constants::kNonVolatileDirectory);
Alex Deymodd132f32015-09-14 19:12:07 -0700178 if (!base::PathExists(local_path)) {
179 LOG(ERROR) << "Non-volatile directory not found: " << local_path.value();
180 return false;
181 }
182 *path = local_path;
183 return true;
184}
185
186bool HardwareAndroid::GetPowerwashSafeDirectory(base::FilePath* path) const {
187 // On Android, we don't have a directory persisted across powerwash.
188 return false;
189}
190
Sen Jiang5011df62017-06-28 17:13:19 -0700191int64_t HardwareAndroid::GetBuildTimestamp() const {
Tom Cherryfadd03c2017-10-10 14:45:09 -0700192 return GetIntProperty<int64_t>(kPropBuildDateUTC, 0);
Sen Jiang5011df62017-06-28 17:13:19 -0700193}
194
Tianjie Xu4ad3af62019-10-30 11:59:45 -0700195// Returns true if the device runs an userdebug build, and explicitly allows OTA
196// downgrade.
197bool HardwareAndroid::AllowDowngrade() const {
198 return GetBoolProperty("ro.ota.allow_downgrade", false) &&
199 GetBoolProperty("ro.debuggable", false);
200}
201
Amin Hassani1677e812017-06-21 13:36:36 -0700202bool HardwareAndroid::GetFirstActiveOmahaPingSent() const {
203 LOG(WARNING) << "STUB: Assuming first active omaha was never set.";
204 return false;
205}
206
Amin Hassani80f4d4c2018-05-16 13:34:00 -0700207bool HardwareAndroid::SetFirstActiveOmahaPingSent() {
208 LOG(WARNING) << "STUB: Assuming first active omaha is set.";
209 // We will set it true, so its failure doesn't cause escalation.
210 return true;
Amin Hassani1677e812017-06-21 13:36:36 -0700211}
212
Tianjie Xud6aa91f2019-11-14 11:55:10 -0800213void HardwareAndroid::SetWarmReset(bool warm_reset) {
214 constexpr char warm_reset_prop[] = "ota.warm_reset";
215 if (!android::base::SetProperty(warm_reset_prop, warm_reset ? "1" : "0")) {
216 LOG(WARNING) << "Failed to set prop " << warm_reset_prop;
217 }
218}
219
Alex Deymo40d86b22015-09-03 22:27:10 -0700220} // namespace chromeos_update_engine