blob: af502f6fdf48272c137e8df94903b6f0410cca26 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001diff --git a/common/platform_constants_android.cc b/common/platform_constants_android.cc
2index 371fe26..ef13058 100644
3--- a/common/platform_constants_android.cc
4+++ b/common/platform_constants_android.cc
5@@ -30,7 +30,7 @@ const char kUpdatePayloadPublicKeyPath[] =
6 const char kCACertificatesPath[] = "/system/etc/security/cacerts_google";
7 // No deadline file API support on Android.
8 const char kOmahaResponseDeadlineFile[] = "";
9-const char kNonVolatileDirectory[] = "/data/misc/update_engine";
10+const char kNonVolatileDirectory[] = "/var/lib/update_engine";
11 const char kPostinstallMountOptions[] =
12 "context=u:object_r:postinstall_file:s0";
13
14diff --git a/hardware_android.cc b/hardware_android.cc
15index 947b13a..0ccb161 100644
16--- a/hardware_android.cc
17+++ b/hardware_android.cc
18@@ -22,10 +22,11 @@
19
20 #include <algorithm>
21 #include <memory>
22-
23+#if 0
24 #include <bootloader.h>
25
26 #include <android-base/properties.h>
27+#endif
28 #include <base/files/file_util.h>
29 #include <base/strings/stringprintf.h>
30
31@@ -34,9 +35,11 @@
32 #include "update_engine/common/utils.h"
33 #include "update_engine/utils_android.h"
34
35+#if 0
36 using android::base::GetBoolProperty;
37 using android::base::GetIntProperty;
38 using android::base::GetProperty;
39+#endif
40 using std::string;
41
42 namespace chromeos_update_engine {
43@@ -58,7 +61,7 @@ const char kPropProductManufacturer[] = "ro.product.manufacturer";
44 const char kPropBootHardwareSKU[] = "ro.boot.hardware.sku";
45 const char kPropBootRevision[] = "ro.boot.revision";
46 const char kPropBuildDateUTC[] = "ro.build.date.utc";
47-
48+#if 0
49 // Write a recovery command line |message| to the BCB. The arguments to recovery
50 // must be separated by '\n'. An empty string will erase the BCB.
51 bool WriteBootloaderRecoveryMessage(const string& message) {
52@@ -91,7 +94,7 @@ bool WriteBootloaderRecoveryMessage(const string& message) {
53 }
54 return true;
55 }
56-
57+#endif
58 } // namespace
59
60 namespace hardware {
61@@ -124,7 +127,7 @@ bool HardwareAndroid::IsOfficialBuild() const {
62 //
63 // In case of a non-bool value, we take the most restrictive option and
64 // assume we are in an official-build.
65- return GetBoolProperty("ro.secure", true);
66+ return true;//GetBoolProperty("ro.secure", true);
67 }
68
69 bool HardwareAndroid::IsNormalBootMode() const {
70@@ -132,11 +135,11 @@ bool HardwareAndroid::IsNormalBootMode() const {
71 // update_engine will allow extra developers options, such as providing a
72 // different update URL. In case of error, we assume the build is in
73 // normal-mode.
74- return !GetBoolProperty("ro.debuggable", false);
75+ return true;//!GetBoolProperty("ro.debuggable", false);
76 }
77
78 bool HardwareAndroid::AreDevFeaturesEnabled() const {
79- return !IsNormalBootMode();
80+ return false;//!IsNormalBootMode();
81 }
82
83 bool HardwareAndroid::IsOOBEEnabled() const {
84@@ -152,19 +155,22 @@ bool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const {
85 }
86
87 string HardwareAndroid::GetHardwareClass() const {
88- auto manufacturer = GetProperty(kPropProductManufacturer, "");
89- auto sku = GetProperty(kPropBootHardwareSKU, "");
90- auto revision = GetProperty(kPropBootRevision, "");
91+ //auto manufacturer = GetProperty(kPropProductManufacturer, "");
92+ //auto sku = GetProperty(kPropBootHardwareSKU, "");
93+ //auto revision = GetProperty(kPropBootRevision, "");
94
95- return manufacturer + ":" + sku + ":" + revision;
96+ //return manufacturer + ":" + sku + ":" + revision;
97+ return "manufacturer:sku:revision";
98 }
99
100 string HardwareAndroid::GetFirmwareVersion() const {
101- return GetProperty(kPropBootBootloader, "");
102+ //return GetProperty(kPropBootBootloader, "");
103+ return "1.0";
104 }
105
106 string HardwareAndroid::GetECVersion() const {
107- return GetProperty(kPropBootBaseband, "");
108+ //return GetProperty(kPropBootBaseband, "");
109+ return "1.0";
110 }
111
112 int HardwareAndroid::GetPowerwashCount() const {
113@@ -174,11 +180,11 @@ int HardwareAndroid::GetPowerwashCount() const {
114
115 bool HardwareAndroid::SchedulePowerwash() {
116 LOG(INFO) << "Scheduling a powerwash to BCB.";
117- return WriteBootloaderRecoveryMessage(kAndroidRecoveryPowerwashCommand);
118+ return false;//WriteBootloaderRecoveryMessage(kAndroidRecoveryPowerwashCommand);
119 }
120
121 bool HardwareAndroid::CancelPowerwash() {
122- return WriteBootloaderRecoveryMessage("");
123+ return true;//WriteBootloaderRecoveryMessage("");
124 }
125
126 bool HardwareAndroid::GetNonVolatileDirectory(base::FilePath* path) const {
127@@ -197,7 +203,8 @@ bool HardwareAndroid::GetPowerwashSafeDirectory(base::FilePath* path) const {
128 }
129
130 int64_t HardwareAndroid::GetBuildTimestamp() const {
131- return GetIntProperty<int64_t>(kPropBuildDateUTC, 0);
132+ //return GetIntProperty<int64_t>(kPropBuildDateUTC, 0);
133+ return utils::GetIntProperty(kPropBuildDateUTC, 0);
134 }
135
136 bool HardwareAndroid::GetFirstActiveOmahaPingSent() const {
137diff --git a/sideload_main.cc b/sideload_main.cc
138index ddb312e..b983534 100644
139--- a/sideload_main.cc
140+++ b/sideload_main.cc
141@@ -155,7 +155,7 @@ bool ApplyUpdatePayload(const string& payload,
142
143 // During the sideload we don't access the prefs persisted on disk but instead
144 // use a temporary memory storage.
145- MemoryPrefs prefs;
146+ //MemoryPrefs prefs;
147
148 std::unique_ptr<BootControlInterface> boot_control =
149 boot_control::CreateBootControl();
150@@ -169,9 +169,21 @@ bool ApplyUpdatePayload(const string& payload,
151 LOG(ERROR) << "Error initializing the HardwareInterface.";
152 return false;
153 }
154+ base::FilePath non_volatile_path;
155+ if (!hardware->GetNonVolatileDirectory(&non_volatile_path)) {
156+ LOG(ERROR) << "Failed to get a non-volatile directory.";
157+ return false;
158+ }
159+ std::unique_ptr<PrefsInterface> prefsIf;
160+ Prefs* prefs = new Prefs();
161+ if (!prefs->Init(non_volatile_path.Append(kPrefsSubDirectory))) {
162+ LOG(ERROR) << "Failed to initialize preferences.";
163+ return false;
164+ }
165+ prefsIf.reset(prefs);
166
167 UpdateAttempterAndroid update_attempter(
168- &sideload_daemon_state, &prefs, boot_control.get(), hardware.get());
169+ &sideload_daemon_state, prefsIf.get(), boot_control.get(), hardware.get());
170 update_attempter.Init();
171
172 TEST_AND_RETURN_FALSE(update_attempter.ApplyPayload(
173diff --git a/update_attempter_android.cc b/update_attempter_android.cc
174index 04ccb18..60e96ff 100644
175--- a/update_attempter_android.cc
176+++ b/update_attempter_android.cc
177@@ -21,7 +21,7 @@
178 #include <memory>
179 #include <utility>
180
181-#include <android-base/properties.h>
182+//#include <android-base/properties.h>
183 #include <base/bind.h>
184 #include <base/logging.h>
185 #include <base/strings/string_number_conversions.h>
186@@ -29,7 +29,7 @@
187 #include <brillo/data_encoding.h>
188 #include <brillo/message_loops/message_loop.h>
189 #include <brillo/strings/string_utils.h>
190-#include <log/log_safetynet.h>
191+//#include <log/log_safetynet.h>
192
193 #include "update_engine/common/constants.h"
194 #include "update_engine/common/error_code_utils.h"
195@@ -449,7 +449,7 @@ void UpdateAttempterAndroid::ProcessingDone(const ActionProcessor* processor,
196
197 case ErrorCode::kPayloadTimestampError:
198 // SafetyNet logging, b/36232423
199- android_errorWriteLog(0x534e4554, "36232423");
200+ //android_errorWriteLog(0x534e4554, "36232423");
201 break;
202
203 default:
204@@ -599,7 +599,10 @@ void UpdateAttempterAndroid::SetStatusAndNotify(UpdateStatus status) {
205 status_ = status;
206 size_t payload_size =
207 install_plan_.payloads.empty() ? 0 : install_plan_.payloads[0].size;
208- UpdateEngineStatus status_to_send = {.status = status_,
209+ UpdateEngineStatus status_to_send = {.last_checked_time = 0,
210+ .status = status_,
211+ .current_version = "n",
212+ .current_system_version = "n",
213 .progress = download_progress_,
214 .new_size_bytes = payload_size};
215
216@@ -764,8 +767,8 @@ void UpdateAttempterAndroid::UpdatePrefsAndReportUpdateMetricsOnReboot() {
217 string current_boot_id;
218 TEST_AND_RETURN(utils::GetBootId(&current_boot_id));
219 // Example: [ro.build.version.incremental]: [4292972]
220- string current_version =
221- android::base::GetProperty("ro.build.version.incremental", "");
222+ string current_version = "4292972";
223+ //android::base::GetProperty("ro.build.version.incremental", "");
224 TEST_AND_RETURN(!current_version.empty());
225
226 // If there's no record of previous version (e.g. due to a data wipe), we
227diff --git a/update_manager/policy.h b/update_manager/policy.h
228index b60c4da..a57cfa6 100644
229--- a/update_manager/policy.h
230+++ b/update_manager/policy.h
231@@ -202,7 +202,7 @@ class Policy {
232 std::string*, R*,
233 Args...) const) const {
234 std::string class_name = PolicyName() + "::";
235-
236+#if 0
237 if (reinterpret_cast<typeof(&Policy::UpdateCheckAllowed)>(
238 policy_method) == &Policy::UpdateCheckAllowed)
239 return class_name + "UpdateCheckAllowed";
240@@ -223,6 +223,7 @@ class Policy {
241 return class_name + "P2PEnabledChanged";
242
243 NOTREACHED();
244+#endif
245 return class_name + "(unknown)";
246 }
247
248diff --git a/utils_android.cc b/utils_android.cc
249index 393e65a..40c06b7 100644
250--- a/utils_android.cc
251+++ b/utils_android.cc
252@@ -15,8 +15,10 @@
253 //
254
255 #include "update_engine/utils_android.h"
256+#include <base/strings/string_number_conversions.h>
257+#include <brillo/key_value_store.h>
258
259-#include <fs_mgr.h>
260+#include <fstab/fstab.h>
261
262 using std::string;
263
264@@ -40,6 +42,9 @@ static struct fstab* OpenFSTab() {
265 namespace utils {
266
267 bool DeviceForMountPoint(const string& mount_point, base::FilePath* device) {
268+ //*device = base::FilePath("/dev/disk/by-partlabel/misc");
269+ // return true;
270+#if 1
271 struct fstab* fstab;
272 struct fstab_rec* record;
273
274@@ -58,8 +63,26 @@ bool DeviceForMountPoint(const string& mount_point, base::FilePath* device) {
275 *device = base::FilePath(record->blk_device);
276 fs_mgr_free_fstab(fstab);
277 return true;
278+#endif
279 }
280
281+int64_t GetIntProperty(const string& key, int64_t default_value){
282+ brillo::KeyValueStore store;
283+ if(store.Load(base::FilePath("/etc/update_engine/build.prop"))){
284+ std::string result;
285+ int64_t result_value;
286+ if(!store.GetString(key, &result)){
287+ LOG(ERROR) << "Error get key" << key;
288+ return default_value;
289+ }
290+ if(base::StringToInt64(result,&result_value)){
291+ return result_value;
292+ }
293+ }else{
294+ LOG(ERROR) << "Error opening property file.";
295+ }
296+ return default_value;
297+}
298 } // namespace utils
299
300 } // namespace chromeos_update_engine
301diff --git a/utils_android.h b/utils_android.h
302index 18dd8ab..9692610 100644
303--- a/utils_android.h
304+++ b/utils_android.h
305@@ -30,6 +30,7 @@ namespace utils {
306 bool DeviceForMountPoint(const std::string& mount_point,
307 base::FilePath* device);
308
309+int64_t GetIntProperty(const std::string& key, int64_t default_value);
310 } // namespace utils
311
312 } // namespace chromeos_update_engine