Browse Source

Add runtime checks for A/B vs traditional updates

This allows A/B devices to install legacy (non-payload) style update.zip
packages like our addonsu or gapps.

Change-Id: I907a92732470b947de007dde11fb71db64d94c9b
Christopher N. Hesse 3 years ago
parent
commit
19fe08051a
1 changed files with 26 additions and 16 deletions
  1. 26
    16
      install.cpp

+ 26
- 16
install.cpp View File

@@ -126,8 +126,6 @@ static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::stri
126 126
   }
127 127
 }
128 128
 
129
-#ifdef AB_OTA_UPDATER
130
-
131 129
 // Parses the metadata of the OTA package in |zip| and checks whether we are
132 130
 // allowed to accept this A/B package. Downgrading is not allowed unless
133 131
 // explicitly enabled in the package and only for incremental packages.
@@ -216,9 +214,9 @@ static int check_newer_ab_build(ZipArchiveHandle zip) {
216 214
   return 0;
217 215
 }
218 216
 
219
-int update_binary_command(const std::string& package, ZipArchiveHandle zip,
220
-                          const std::string& binary_path, int /* retry_count */, int status_fd,
221
-                          std::vector<std::string>* cmd) {
217
+int update_binary_command_ab(const std::string& package, ZipArchiveHandle zip,
218
+                             const std::string& binary_path, int /* retry_count */, int status_fd,
219
+                             std::vector<std::string>* cmd) {
222 220
   CHECK(cmd != nullptr);
223 221
   int ret = check_newer_ab_build(zip);
224 222
   if (ret != 0) {
@@ -261,11 +259,9 @@ int update_binary_command(const std::string& package, ZipArchiveHandle zip,
261 259
   return 0;
262 260
 }
263 261
 
264
-#else  // !AB_OTA_UPDATER
265
-
266
-int update_binary_command(const std::string& package, ZipArchiveHandle zip,
267
-                          const std::string& binary_path, int retry_count, int status_fd,
268
-                          std::vector<std::string>* cmd) {
262
+int update_binary_command_legacy(const std::string& package, ZipArchiveHandle zip,
263
+                                 const std::string& binary_path, int retry_count, int status_fd,
264
+                                 std::vector<std::string>* cmd) {
269 265
   CHECK(cmd != nullptr);
270 266
 
271 267
   // On traditional updates we extract the update binary from the package.
@@ -302,7 +298,6 @@ int update_binary_command(const std::string& package, ZipArchiveHandle zip,
302 298
   }
303 299
   return 0;
304 300
 }
305
-#endif  // !AB_OTA_UPDATER
306 301
 
307 302
 static void log_max_temperature(int* max_temperature, const std::atomic<bool>& logger_finished) {
308 303
   CHECK(max_temperature != nullptr);
@@ -326,17 +321,32 @@ static int try_update_binary(const std::string& package, ZipArchiveHandle zip, b
326 321
                              int* max_temperature) {
327 322
   read_source_target_build(zip, log_buffer);
328 323
 
324
+  int ret;
329 325
   int pipefd[2];
330 326
   pipe(pipefd);
331 327
 
332 328
   std::vector<std::string> args;
329
+  bool ab_ota = false;
330
+
333 331
 #ifdef AB_OTA_UPDATER
334
-  int ret = update_binary_command(package, zip, "/sbin/update_engine_sideload", retry_count,
335
-                                  pipefd[1], &args);
336
-#else
337
-  int ret = update_binary_command(package, zip, "/tmp/update-binary", retry_count, pipefd[1],
338
-                                  &args);
332
+  // A/B updates contain a payload.bin and a text file describing the payload.
333
+  // We check for this file to see whether the update package has to be flashed using update_engine
334
+  // or if it's a traditional package with an updater-script.
335
+  static constexpr const char* AB_OTA_PAYLOAD_PROPERTIES = "payload_properties.txt";
336
+  ZipString property_name(AB_OTA_PAYLOAD_PROPERTIES);
337
+  ZipEntry properties_entry;
338
+  if (FindEntry(zip, property_name, &properties_entry) == 0) {
339
+    ab_ota = true;
340
+  }
339 341
 #endif
342
+
343
+  if (ab_ota) {
344
+    ret = update_binary_command_ab(package, zip, "/sbin/update_engine_sideload", retry_count,
345
+                                   pipefd[1], &args);
346
+  } else {
347
+    ret = update_binary_command_legacy(package, zip, "/tmp/update-binary", retry_count, pipefd[1],
348
+                                       &args);
349
+  }
340 350
   if (ret) {
341 351
     close(pipefd[0]);
342 352
     close(pipefd[1]);