Merge "adb: clean up handle_host_request."
diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp
index 8b46d64..f87a3b1 100644
--- a/fs_mgr/fs_mgr_fstab.cpp
+++ b/fs_mgr/fs_mgr_fstab.cpp
@@ -117,21 +117,17 @@
 #define EM_ICE          2
 #define EM_AES_256_CTS  3
 #define EM_AES_256_HEH  4
-#define EM_SPECK_128_256_XTS 5
-#define EM_SPECK_128_256_CTS 6
 
 static const struct flag_list file_contents_encryption_modes[] = {
     {"aes-256-xts", EM_AES_256_XTS},
-    {"speck128/256-xts", EM_SPECK_128_256_XTS},
     {"software", EM_AES_256_XTS}, /* alias for backwards compatibility */
-    {"ice", EM_ICE},              /* hardware-specific inline cryptographic engine */
+    {"ice", EM_ICE}, /* hardware-specific inline cryptographic engine */
     {0, 0},
 };
 
 static const struct flag_list file_names_encryption_modes[] = {
     {"aes-256-cts", EM_AES_256_CTS},
     {"aes-256-heh", EM_AES_256_HEH},
-    {"speck128/256-cts", EM_SPECK_128_256_CTS},
     {0, 0},
 };
 
diff --git a/libsync/Android.bp b/libsync/Android.bp
index dbee596..e56f8ba 100644
--- a/libsync/Android.bp
+++ b/libsync/Android.bp
@@ -20,8 +20,9 @@
     cflags: ["-Werror"],
 }
 
-cc_library_shared {
+cc_library {
     name: "libsync",
+    recovery_available: true,
     defaults: ["libsync_defaults"],
 }
 
@@ -31,15 +32,6 @@
     export_include_dirs: ["include"],
 }
 
-// libsync_recovery is only intended for the recovery binary.
-// Future versions of the kernel WILL require an updated libsync, and will break
-// anything statically linked against the current libsync.
-cc_library_static {
-    name: "libsync_recovery",
-    recovery_available: true,
-    defaults: ["libsync_defaults"],
-}
-
 cc_test {
     name: "sync-unit-tests",
     shared_libs: ["libsync"],
diff --git a/libunwindstack/DexFile.cpp b/libunwindstack/DexFile.cpp
index 3d982f6..8ec560c 100644
--- a/libunwindstack/DexFile.cpp
+++ b/libunwindstack/DexFile.cpp
@@ -24,6 +24,7 @@
 
 #include <android-base/unique_fd.h>
 
+#include <dex/class_accessor-inl.h>
 #include <dex/code_item_accessors-inl.h>
 #include <dex/compact_dex_file.h>
 #include <dex/dex_file-inl.h>
@@ -98,38 +99,20 @@
 
   // Check the methods we haven't cached.
   for (; class_def_index_ < dex_file_->NumClassDefs(); class_def_index_++) {
-    const art::DexFile::ClassDef& class_def = dex_file_->GetClassDef(class_def_index_);
-    const uint8_t* class_data = dex_file_->GetClassData(class_def);
-    if (class_data == nullptr) {
-      continue;
-    }
+    art::ClassAccessor accessor(*dex_file_, dex_file_->GetClassDef(class_def_index_));
 
-    if (class_it_.get() == nullptr || !class_it_->HasNext()) {
-      class_it_.reset(new art::ClassDataItemIterator(*dex_file_.get(), class_data));
-    }
-
-    for (; class_it_->HasNext(); class_it_->Next()) {
-      if (!class_it_->IsAtMethod()) {
-        continue;
-      }
-      const art::DexFile::CodeItem* code_item = class_it_->GetMethodCodeItem();
-      if (code_item == nullptr) {
-        continue;
-      }
-      art::CodeItemInstructionAccessor code(*dex_file_.get(), code_item);
+    for (const art::ClassAccessor::Method& method : accessor.GetMethods()) {
+      art::CodeItemInstructionAccessor code = method.GetInstructions();
       if (!code.HasCodeItem()) {
         continue;
       }
-
       uint32_t offset = reinterpret_cast<const uint8_t*>(code.Insns()) - dex_file_->Begin();
-      uint32_t offset_end = offset + code.InsnsSizeInCodeUnits() * sizeof(uint16_t);
-      uint32_t member_index = class_it_->GetMemberIndex();
+      uint32_t offset_end = offset + code.InsnsSizeInBytes();
+      uint32_t member_index = method.GetIndex();
       method_cache_[offset_end] = std::make_pair(offset, member_index);
       if (offset <= dex_offset && dex_offset < offset_end) {
         *method_name = dex_file_->PrettyMethod(member_index, false);
         *method_offset = dex_offset - offset;
-        // Move past this element.
-        class_it_->Next();
         return true;
       }
     }
diff --git a/libunwindstack/DexFile.h b/libunwindstack/DexFile.h
index 508692d..c123158 100644
--- a/libunwindstack/DexFile.h
+++ b/libunwindstack/DexFile.h
@@ -45,7 +45,6 @@
   std::map<uint32_t, std::pair<uint64_t, uint32_t>> method_cache_;  // dex offset to method index.
 
   uint32_t class_def_index_ = 0;
-  std::unique_ptr<art::ClassDataItemIterator> class_it_;
 };
 
 class DexFileFromFile : public DexFile {
diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c
index 8fda563..3b45db7 100644
--- a/lmkd/lmkd.c
+++ b/lmkd/lmkd.c
@@ -82,6 +82,9 @@
 /* Defined as ProcessList.SYSTEM_ADJ in ProcessList.java */
 #define SYSTEM_ADJ (-900)
 
+#define STRINGIFY(x) STRINGIFY_INTERNAL(x)
+#define STRINGIFY_INTERNAL(x) #x
+
 /* default to old in-kernel interface if no memory pressure events */
 static bool use_inkernel_interface = true;
 static bool has_inkernel_module;
@@ -730,10 +733,10 @@
 
 #ifdef LMKD_LOG_STATS
 static void memory_stat_parse_line(char *line, struct memory_stat *mem_st) {
-    char key[LINE_MAX];
+    char key[LINE_MAX + 1];
     int64_t value;
 
-    sscanf(line,"%s  %" SCNd64 "", key, &value);
+    sscanf(line, "%" STRINGIFY(LINE_MAX) "s  %" SCNd64 "", key, &value);
 
     if (strcmp(key, "total_") < 0) {
         return;
@@ -752,24 +755,31 @@
 }
 
 static int memory_stat_parse(struct memory_stat *mem_st,  int pid, uid_t uid) {
-   FILE *fp;
-   char buf[PATH_MAX];
+    FILE *fp;
+    char buf[PATH_MAX];
 
-   snprintf(buf, sizeof(buf), MEMCG_PROCESS_MEMORY_STAT_PATH, uid, pid);
+    /*
+     * Per-application memory.stat files are available only when
+     * per-application memcgs are enabled.
+     */
+    if (!per_app_memcg)
+        return -1;
 
-   fp = fopen(buf, "r");
+    snprintf(buf, sizeof(buf), MEMCG_PROCESS_MEMORY_STAT_PATH, uid, pid);
 
-   if (fp == NULL) {
-       ALOGE("%s open failed: %s", buf, strerror(errno));
-       return -1;
-   }
+    fp = fopen(buf, "r");
 
-   while (fgets(buf, PAGE_SIZE, fp) != NULL ) {
-       memory_stat_parse_line(buf, mem_st);
-   }
-   fclose(fp);
+    if (fp == NULL) {
+        ALOGE("%s open failed: %s", buf, strerror(errno));
+        return -1;
+    }
 
-   return 0;
+    while (fgets(buf, PAGE_SIZE, fp) != NULL ) {
+        memory_stat_parse_line(buf, mem_st);
+    }
+    fclose(fp);
+
+    return 0;
 }
 #endif