Merge "Move Image/ImageChunk/PatchChunk declaration into header files"
am: b4bc57ed39

Change-Id: If254ed9e24bc0cafa19db9766ed36643ca0fed49
diff --git a/etc/init.rc b/etc/init.rc
index 2e3c7a7..d8121cc 100644
--- a/etc/init.rc
+++ b/etc/init.rc
@@ -79,9 +79,9 @@
     critical
     seclabel u:r:ueventd:s0
 
-service healthd /sbin/healthd -r
+service charger /charger -r
     critical
-    seclabel u:r:healthd:s0
+    seclabel u:r:charger:s0
 
 service recovery /sbin/recovery
     seclabel u:r:recovery:s0
diff --git a/minui/graphics.cpp b/minui/graphics.cpp
index 3bdc33f..3bfce11 100644
--- a/minui/graphics.cpp
+++ b/minui/graphics.cpp
@@ -258,7 +258,7 @@
 }
 
 int gr_init_font(const char* name, GRFont** dest) {
-    GRFont* font = reinterpret_cast<GRFont*>(calloc(1, sizeof(*gr_font)));
+    GRFont* font = static_cast<GRFont*>(calloc(1, sizeof(*gr_font)));
     if (font == nullptr) {
         return -1;
     }
@@ -291,7 +291,7 @@
 
 
     // fall back to the compiled-in font.
-    gr_font = static_cast<GRFont*>(calloc(sizeof(*gr_font), 1));
+    gr_font = static_cast<GRFont*>(calloc(1, sizeof(*gr_font)));
     gr_font->texture = static_cast<GRSurface*>(malloc(sizeof(*gr_font->texture)));
     gr_font->texture->width = font.width;
     gr_font->texture->height = font.height;
diff --git a/recovery.cpp b/recovery.cpp
index c5ead45..6f62ff1 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -53,6 +53,7 @@
 #include <healthd/BatteryMonitor.h>
 #include <private/android_logger.h> /* private pmsg functions */
 #include <private/android_filesystem_config.h>  /* for AID_SYSTEM */
+#include <selinux/android.h>
 #include <selinux/label.h>
 #include <selinux/selinux.h>
 #include <ziparchive/zip_archive.h>
@@ -1480,12 +1481,8 @@
     ui->SetBackground(RecoveryUI::NONE);
     if (show_text) ui->ShowText(true);
 
-    struct selinux_opt seopts[] = {
-        { SELABEL_OPT_PATH, "/file_contexts" }
-    };
-
-    sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);
-
+    sehandle = selinux_android_file_context_handle();
+    selinux_android_set_sehandle(sehandle);
     if (!sehandle) {
         ui->Print("Warning: No file_contexts\n");
     }
diff --git a/tests/component/verifier_test.cpp b/tests/component/verifier_test.cpp
index 5338f05..e520f50 100644
--- a/tests/component/verifier_test.cpp
+++ b/tests/component/verifier_test.cpp
@@ -33,6 +33,8 @@
 #include "otautil/SysUtil.h"
 #include "verifier.h"
 
+using namespace std::string_literals;
+
 class VerifierTest : public testing::TestWithParam<std::vector<std::string>> {
  protected:
   void SetUp() override {
@@ -115,6 +117,21 @@
   ASSERT_FALSE(load_keys(key_file5.path, certs));
 }
 
+TEST(VerifierTest, BadPackage_SignatureStartOutOfBounds) {
+  std::string testkey_v3;
+  ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v3.txt"), &testkey_v3));
+
+  TemporaryFile key_file;
+  ASSERT_TRUE(android::base::WriteStringToFile(testkey_v3, key_file.path));
+  std::vector<Certificate> certs;
+  ASSERT_TRUE(load_keys(key_file.path, certs));
+
+  // Signature start is 65535 (0xffff) while comment size is 0 (Bug: 31914369).
+  std::string package = "\x50\x4b\x05\x06"s + std::string(12, '\0') + "\xff\xff\xff\xff\x00\x00"s;
+  ASSERT_EQ(VERIFY_FAILURE, verify_file(reinterpret_cast<const unsigned char*>(package.data()),
+                                        package.size(), certs));
+}
+
 TEST(VerifierTest, BadPackage_AlteredFooter) {
   std::string testkey_v3;
   ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v3.txt"), &testkey_v3));
diff --git a/tools/recovery_l10n/res/values-az-rAZ/strings.xml b/tools/recovery_l10n/res/values-az/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-az-rAZ/strings.xml
rename to tools/recovery_l10n/res/values-az/strings.xml
diff --git a/tools/recovery_l10n/res/values-b+sr+Latn/strings.xml b/tools/recovery_l10n/res/values-b+sr+Latn/strings.xml
new file mode 100644
index 0000000..c2d8f22
--- /dev/null
+++ b/tools/recovery_l10n/res/values-b+sr+Latn/strings.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="recovery_installing" msgid="2013591905463558223">"Ažuriranje sistema se instalira"</string>
+    <string name="recovery_erasing" msgid="7334826894904037088">"Briše se"</string>
+    <string name="recovery_no_command" msgid="4465476568623024327">"Nema komande"</string>
+    <string name="recovery_error" msgid="5748178989622716736">"Greška!"</string>
+    <string name="recovery_installing_security" msgid="9184031299717114342">"Instalira se bezbednosno ažuriranje"</string>
+</resources>
diff --git a/tools/recovery_l10n/res/values-be/strings.xml b/tools/recovery_l10n/res/values-be/strings.xml
new file mode 100644
index 0000000..7c0954d
--- /dev/null
+++ b/tools/recovery_l10n/res/values-be/strings.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="recovery_installing" msgid="2013591905463558223">"Усталёўка абнаўлення сістэмы"</string>
+    <string name="recovery_erasing" msgid="7334826894904037088">"Сціранне"</string>
+    <string name="recovery_no_command" msgid="4465476568623024327">"Няма каманды"</string>
+    <string name="recovery_error" msgid="5748178989622716736">"Памылка"</string>
+    <string name="recovery_installing_security" msgid="9184031299717114342">"Усталёўка абнаўлення сістэмы бяспекі"</string>
+</resources>
diff --git a/tools/recovery_l10n/res/values-bn-rBD/strings.xml b/tools/recovery_l10n/res/values-bn/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-bn-rBD/strings.xml
rename to tools/recovery_l10n/res/values-bn/strings.xml
diff --git a/tools/recovery_l10n/res/values-bs/strings.xml b/tools/recovery_l10n/res/values-bs/strings.xml
new file mode 100644
index 0000000..412cf02
--- /dev/null
+++ b/tools/recovery_l10n/res/values-bs/strings.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="recovery_installing" msgid="2013591905463558223">"Ažuriranje sistema…"</string>
+    <string name="recovery_erasing" msgid="7334826894904037088">"Brisanje u toku"</string>
+    <string name="recovery_no_command" msgid="4465476568623024327">"Nema komande"</string>
+    <string name="recovery_error" msgid="5748178989622716736">"Greška!"</string>
+    <string name="recovery_installing_security" msgid="9184031299717114342">"Instaliranje sigurnosnog ažuriranja…"</string>
+</resources>
diff --git a/tools/recovery_l10n/res/values-et-rEE/strings.xml b/tools/recovery_l10n/res/values-et/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-et-rEE/strings.xml
rename to tools/recovery_l10n/res/values-et/strings.xml
diff --git a/tools/recovery_l10n/res/values-eu-rES/strings.xml b/tools/recovery_l10n/res/values-eu/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-eu-rES/strings.xml
rename to tools/recovery_l10n/res/values-eu/strings.xml
diff --git a/tools/recovery_l10n/res/values-gl-rES/strings.xml b/tools/recovery_l10n/res/values-gl/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-gl-rES/strings.xml
rename to tools/recovery_l10n/res/values-gl/strings.xml
diff --git a/tools/recovery_l10n/res/values-gu-rIN/strings.xml b/tools/recovery_l10n/res/values-gu/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-gu-rIN/strings.xml
rename to tools/recovery_l10n/res/values-gu/strings.xml
diff --git a/tools/recovery_l10n/res/values-hy-rAM/strings.xml b/tools/recovery_l10n/res/values-hy/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-hy-rAM/strings.xml
rename to tools/recovery_l10n/res/values-hy/strings.xml
diff --git a/tools/recovery_l10n/res/values-is-rIS/strings.xml b/tools/recovery_l10n/res/values-is/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-is-rIS/strings.xml
rename to tools/recovery_l10n/res/values-is/strings.xml
diff --git a/tools/recovery_l10n/res/values-ka-rGE/strings.xml b/tools/recovery_l10n/res/values-ka/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-ka-rGE/strings.xml
rename to tools/recovery_l10n/res/values-ka/strings.xml
diff --git a/tools/recovery_l10n/res/values-kk-rKZ/strings.xml b/tools/recovery_l10n/res/values-kk/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-kk-rKZ/strings.xml
rename to tools/recovery_l10n/res/values-kk/strings.xml
diff --git a/tools/recovery_l10n/res/values-km-rKH/strings.xml b/tools/recovery_l10n/res/values-km/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-km-rKH/strings.xml
rename to tools/recovery_l10n/res/values-km/strings.xml
diff --git a/tools/recovery_l10n/res/values-kn-rIN/strings.xml b/tools/recovery_l10n/res/values-kn/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-kn-rIN/strings.xml
rename to tools/recovery_l10n/res/values-kn/strings.xml
diff --git a/tools/recovery_l10n/res/values-ky-rKG/strings.xml b/tools/recovery_l10n/res/values-ky/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-ky-rKG/strings.xml
rename to tools/recovery_l10n/res/values-ky/strings.xml
diff --git a/tools/recovery_l10n/res/values-lo-rLA/strings.xml b/tools/recovery_l10n/res/values-lo/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-lo-rLA/strings.xml
rename to tools/recovery_l10n/res/values-lo/strings.xml
diff --git a/tools/recovery_l10n/res/values-mk-rMK/strings.xml b/tools/recovery_l10n/res/values-mk/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-mk-rMK/strings.xml
rename to tools/recovery_l10n/res/values-mk/strings.xml
diff --git a/tools/recovery_l10n/res/values-ml-rIN/strings.xml b/tools/recovery_l10n/res/values-ml/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-ml-rIN/strings.xml
rename to tools/recovery_l10n/res/values-ml/strings.xml
diff --git a/tools/recovery_l10n/res/values-mn-rMN/strings.xml b/tools/recovery_l10n/res/values-mn/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-mn-rMN/strings.xml
rename to tools/recovery_l10n/res/values-mn/strings.xml
diff --git a/tools/recovery_l10n/res/values-mr-rIN/strings.xml b/tools/recovery_l10n/res/values-mr/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-mr-rIN/strings.xml
rename to tools/recovery_l10n/res/values-mr/strings.xml
diff --git a/tools/recovery_l10n/res/values-ms-rMY/strings.xml b/tools/recovery_l10n/res/values-ms/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-ms-rMY/strings.xml
rename to tools/recovery_l10n/res/values-ms/strings.xml
diff --git a/tools/recovery_l10n/res/values-my-rMM/strings.xml b/tools/recovery_l10n/res/values-my/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-my-rMM/strings.xml
rename to tools/recovery_l10n/res/values-my/strings.xml
diff --git a/tools/recovery_l10n/res/values-ne-rNP/strings.xml b/tools/recovery_l10n/res/values-ne/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-ne-rNP/strings.xml
rename to tools/recovery_l10n/res/values-ne/strings.xml
diff --git a/tools/recovery_l10n/res/values-pa-rIN/strings.xml b/tools/recovery_l10n/res/values-pa/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-pa-rIN/strings.xml
rename to tools/recovery_l10n/res/values-pa/strings.xml
diff --git a/tools/recovery_l10n/res/values-si-rLK/strings.xml b/tools/recovery_l10n/res/values-si/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-si-rLK/strings.xml
rename to tools/recovery_l10n/res/values-si/strings.xml
diff --git a/tools/recovery_l10n/res/values-sq-rAL/strings.xml b/tools/recovery_l10n/res/values-sq/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-sq-rAL/strings.xml
rename to tools/recovery_l10n/res/values-sq/strings.xml
diff --git a/tools/recovery_l10n/res/values-ta-rIN/strings.xml b/tools/recovery_l10n/res/values-ta/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-ta-rIN/strings.xml
rename to tools/recovery_l10n/res/values-ta/strings.xml
diff --git a/tools/recovery_l10n/res/values-te-rIN/strings.xml b/tools/recovery_l10n/res/values-te/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-te-rIN/strings.xml
rename to tools/recovery_l10n/res/values-te/strings.xml
diff --git a/tools/recovery_l10n/res/values-ur-rPK/strings.xml b/tools/recovery_l10n/res/values-ur/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-ur-rPK/strings.xml
rename to tools/recovery_l10n/res/values-ur/strings.xml
diff --git a/tools/recovery_l10n/res/values-uz-rUZ/strings.xml b/tools/recovery_l10n/res/values-uz/strings.xml
similarity index 100%
rename from tools/recovery_l10n/res/values-uz-rUZ/strings.xml
rename to tools/recovery_l10n/res/values-uz/strings.xml
diff --git a/uncrypt/uncrypt.cpp b/uncrypt/uncrypt.cpp
index 35998bc..7a2ccbc 100644
--- a/uncrypt/uncrypt.cpp
+++ b/uncrypt/uncrypt.cpp
@@ -625,12 +625,12 @@
     }
 
     if (action == UNCRYPT_DEBUG) {
-        LOG(INFO) << "uncrypt called in debug mode, skip socket communication\n";
+        LOG(INFO) << "uncrypt called in debug mode, skip socket communication";
         bool success = uncrypt_wrapper(input_path, map_file, -1);
         if (success) {
-            LOG(INFO) << "uncrypt succeeded\n";
+            LOG(INFO) << "uncrypt succeeded";
         } else{
-            LOG(INFO) << "uncrypt failed\n";
+            LOG(INFO) << "uncrypt failed";
         }
         return success ? 0 : 1;
     }
diff --git a/updater/updater.cpp b/updater/updater.cpp
index f5ff6df..1d8fa8e 100644
--- a/updater/updater.cpp
+++ b/updater/updater.cpp
@@ -25,6 +25,7 @@
 
 #include <android-base/logging.h>
 #include <android-base/strings.h>
+#include <selinux/android.h>
 #include <selinux/label.h>
 #include <selinux/selinux.h>
 #include <ziparchive/zip_archive.h>
@@ -139,9 +140,8 @@
     return 6;
   }
 
-  struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "/file_contexts" } };
-
-  sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);
+  sehandle = selinux_android_file_context_handle();
+  selinux_android_set_sehandle(sehandle);
 
   if (!sehandle) {
     fprintf(cmd_pipe, "ui_print Warning: No file_contexts\n");