Merge "Eliminate false positive static analyzer warnings."
diff --git a/adb/test_device.py b/adb/test_device.py
index 9e1a2ec..ddceda9 100644
--- a/adb/test_device.py
+++ b/adb/test_device.py
@@ -1237,7 +1237,7 @@
                 return m.group(2)
         return None
 
-    def test_killed_when_pushing_a_large_file(self):
+    def disabled_test_killed_when_pushing_a_large_file(self):
         """
            While running adb push with a large file, kill adb server.
            Occasionally the device becomes offline. Because the device is still
@@ -1268,7 +1268,7 @@
         # 4. The device should be online
         self.assertEqual(self._get_device_state(serialno), 'device')
 
-    def test_killed_when_pulling_a_large_file(self):
+    def disabled_test_killed_when_pulling_a_large_file(self):
         """
            While running adb pull with a large file, kill adb server.
            Occasionally the device can't be connected. Because the device is trying to
diff --git a/adb/transport.cpp b/adb/transport.cpp
index 1b597fd..34cc026 100644
--- a/adb/transport.cpp
+++ b/adb/transport.cpp
@@ -748,9 +748,6 @@
 }
 
 int atransport::Write(apacket* p) {
-#if ADB_HOST
-    std::lock_guard<std::mutex> lock(write_msg_lock_);
-#endif
     return write_func_(p, this);
 }
 
@@ -758,11 +755,6 @@
     if (!kicked_) {
         kicked_ = true;
         CHECK(kick_func_ != nullptr);
-#if ADB_HOST
-        // On host, adb server should avoid writing part of a packet, so don't
-        // kick a transport whiling writing a packet.
-        std::lock_guard<std::mutex> lock(write_msg_lock_);
-#endif
         kick_func_(this);
     }
 }
diff --git a/adb/transport.h b/adb/transport.h
index 374bfc3..79e3075 100644
--- a/adb/transport.h
+++ b/adb/transport.h
@@ -181,7 +181,6 @@
     std::atomic<ConnectionState> connection_state_;
 #if ADB_HOST
     std::deque<std::shared_ptr<RSA>> keys_;
-    std::mutex write_msg_lock_;
     bool has_send_connect_on_error_ = false;
 #endif
 
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index 7c0b15e..17986b9 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -204,6 +204,7 @@
     {"reboot,shell", 66},
     {"reboot,adb", 67},
     {"reboot,userrequested", 68},
+    {"shutdown,container", 69},  // Host OS asking Android Container to shutdown
 };
 
 // Converts a string value representing the reason the system booted to an
diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp
index eeac697..9f52fdf 100644
--- a/fs_mgr/fs_mgr_fstab.cpp
+++ b/fs_mgr/fs_mgr_fstab.cpp
@@ -791,11 +791,12 @@
  * Returns the 1st matching fstab_rec that follows the start_rec.
  * start_rec is the result of a previous search or NULL.
  */
-struct fstab_rec *fs_mgr_get_entry_for_mount_point_after(struct fstab_rec *start_rec, struct fstab *fstab, const char *path)
-{
+struct fstab_rec* fs_mgr_get_entry_for_mount_point_after(struct fstab_rec* start_rec,
+                                                         struct fstab* fstab,
+                                                         const std::string& path) {
     int i;
     if (!fstab) {
-        return NULL;
+        return nullptr;
     }
 
     if (start_rec) {
@@ -808,14 +809,14 @@
     } else {
         i = 0;
     }
+
     for (; i < fstab->num_entries; i++) {
-        int len = strlen(fstab->recs[i].mount_point);
-        if (strncmp(path, fstab->recs[i].mount_point, len) == 0 &&
-            (path[len] == '\0' || path[len] == '/')) {
+        if (fstab->recs[i].mount_point && path == fstab->recs[i].mount_point) {
             return &fstab->recs[i];
         }
     }
-    return NULL;
+
+    return nullptr;
 }
 
 /*
diff --git a/init/init.cpp b/init/init.cpp
index 817b33e..ad045b1 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -417,8 +417,7 @@
         return;
     }
 
-    LOG(INFO) << "Handling SIGTERM, shutting system down";
-    HandlePowerctlMessage("shutdown");
+    HandlePowerctlMessage("shutdown,container");
 }
 
 static void InstallSigtermHandler() {
@@ -569,8 +568,7 @@
 
     epoll_fd = epoll_create1(EPOLL_CLOEXEC);
     if (epoll_fd == -1) {
-        PLOG(ERROR) << "epoll_create1 failed";
-        exit(1);
+        PLOG(FATAL) << "epoll_create1 failed";
     }
 
     sigchld_handler_init();
diff --git a/init/persistent_properties.cpp b/init/persistent_properties.cpp
index 71f2355..21adce9 100644
--- a/init/persistent_properties.cpp
+++ b/init/persistent_properties.cpp
@@ -43,7 +43,6 @@
 
 namespace {
 
-constexpr const uint32_t kMagic = 0x8495E0B4;
 constexpr const char kLegacyPersistentPropertyDir[] = "/data/property";
 
 void AddPersistentProperty(const std::string& name, const std::string& value,
@@ -140,85 +139,6 @@
     return persistent_properties;
 }
 
-class PersistentPropertyFileParser {
-  public:
-    PersistentPropertyFileParser(const std::string& contents) : contents_(contents), position_(0) {}
-    Result<PersistentProperties> Parse();
-
-  private:
-    Result<std::string> ReadString();
-    Result<uint32_t> ReadUint32();
-
-    const std::string& contents_;
-    size_t position_;
-};
-
-Result<PersistentProperties> PersistentPropertyFileParser::Parse() {
-    if (auto magic = ReadUint32(); magic) {
-        if (*magic != kMagic) {
-            return Error() << "Magic value '0x" << std::hex << *magic
-                           << "' does not match expected value '0x" << kMagic << "'";
-        }
-    } else {
-        return Error() << "Could not read magic value: " << magic.error();
-    }
-
-    if (auto version = ReadUint32(); version) {
-        if (*version != 1) {
-            return Error() << "Version '" << *version
-                           << "' does not match any compatible version: (1)";
-        }
-    } else {
-        return Error() << "Could not read version: " << version.error();
-    }
-
-    auto num_properties = ReadUint32();
-    if (!num_properties) {
-        return Error() << "Could not read num_properties: " << num_properties.error();
-    }
-
-    PersistentProperties result;
-    while (position_ < contents_.size()) {
-        auto name = ReadString();
-        if (!name) {
-            return Error() << "Could not read name: " << name.error();
-        }
-        if (!StartsWith(*name, "persist.")) {
-            return Error() << "Property '" << *name << "' does not starts with 'persist.'";
-        }
-        auto value = ReadString();
-        if (!value) {
-            return Error() << "Could not read value: " << value.error();
-        }
-        AddPersistentProperty(*name, *value, &result);
-    }
-
-    return result;
-}
-
-Result<std::string> PersistentPropertyFileParser::ReadString() {
-    auto string_length = ReadUint32();
-    if (!string_length) {
-        return Error() << "Could not read size for string";
-    }
-
-    if (position_ + *string_length > contents_.size()) {
-        return Error() << "String size would cause it to overflow the input buffer";
-    }
-    auto result = std::string(contents_, position_, *string_length);
-    position_ += *string_length;
-    return result;
-}
-
-Result<uint32_t> PersistentPropertyFileParser::ReadUint32() {
-    if (position_ + 3 > contents_.size()) {
-        return Error() << "Input buffer not large enough to read uint32_t";
-    }
-    uint32_t result = *reinterpret_cast<const uint32_t*>(&contents_[position_]);
-    position_ += sizeof(uint32_t);
-    return result;
-}
-
 Result<std::string> ReadPersistentPropertyFile() {
     const std::string temp_filename = persistent_property_filename + ".tmp";
     if (access(temp_filename.c_str(), F_OK) == 0) {
@@ -240,24 +160,13 @@
     auto file_contents = ReadPersistentPropertyFile();
     if (!file_contents) return file_contents.error();
 
-    // Check the intermediate "I should have used protobufs from the start" format.
-    // TODO: Remove this.
-    auto parsed_contents = PersistentPropertyFileParser(*file_contents).Parse();
-    if (parsed_contents) {
-        LOG(INFO) << "Intermediate format persistent property file found, converting to protobuf";
-
-        // Update to the protobuf format
-        WritePersistentPropertyFile(*parsed_contents);
-        return parsed_contents;
-    }
-
     PersistentProperties persistent_properties;
     if (persistent_properties.ParseFromString(*file_contents)) return persistent_properties;
 
     // If the file cannot be parsed in either format, then we don't have any recovery
     // mechanisms, so we delete it to allow for future writes to take place successfully.
     unlink(persistent_property_filename.c_str());
-    return Error() << "Unable to parse persistent property file: " << parsed_contents.error();
+    return Error() << "Unable to parse persistent property file: Could not parse protobuf";
 }
 
 Result<Success> WritePersistentPropertyFile(const PersistentProperties& persistent_properties) {
@@ -288,25 +197,24 @@
 // Persistent properties are not written often, so we rather not keep any data in memory and read
 // then rewrite the persistent property file for each update.
 void WritePersistentProperty(const std::string& name, const std::string& value) {
-    auto file_contents = ReadPersistentPropertyFile();
-    PersistentProperties persistent_properties;
+    auto persistent_properties = LoadPersistentPropertyFile();
 
-    if (!file_contents || !persistent_properties.ParseFromString(*file_contents)) {
+    if (!persistent_properties) {
         LOG(ERROR) << "Recovering persistent properties from memory: "
-                   << (!file_contents ? file_contents.error_string() : "Could not parse protobuf");
+                   << persistent_properties.error();
         persistent_properties = LoadPersistentPropertiesFromMemory();
     }
-    auto it = std::find_if(persistent_properties.mutable_properties()->begin(),
-                           persistent_properties.mutable_properties()->end(),
+    auto it = std::find_if(persistent_properties->mutable_properties()->begin(),
+                           persistent_properties->mutable_properties()->end(),
                            [&name](const auto& record) { return record.name() == name; });
-    if (it != persistent_properties.mutable_properties()->end()) {
+    if (it != persistent_properties->mutable_properties()->end()) {
         it->set_name(name);
         it->set_value(value);
     } else {
-        AddPersistentProperty(name, value, &persistent_properties);
+        AddPersistentProperty(name, value, &persistent_properties.value());
     }
 
-    if (auto result = WritePersistentPropertyFile(persistent_properties); !result) {
+    if (auto result = WritePersistentPropertyFile(*persistent_properties); !result) {
         LOG(ERROR) << "Could not store persistent property: " << result.error();
     }
 }
diff --git a/init/property_service.cpp b/init/property_service.cpp
index 01f41e1..6321fb2 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -73,8 +73,7 @@
 
 void property_init() {
     if (__system_property_area_init()) {
-        LOG(ERROR) << "Failed to initialize property area";
-        exit(1);
+        LOG(FATAL) << "Failed to initialize property area";
     }
 }
 
@@ -216,7 +215,7 @@
             LOG(ERROR) << "property_set_async(\"" << info.name << "\", \"" << info.value
                        << "\") failed";
         }
-        exit(0);
+        _exit(0);
     }
 }
 
@@ -719,8 +718,7 @@
     property_set_fd = CreateSocket(PROP_SERVICE_NAME, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
                                    false, 0666, 0, 0, nullptr);
     if (property_set_fd == -1) {
-        PLOG(ERROR) << "start_property_service socket creation failed";
-        exit(1);
+        PLOG(FATAL) << "start_property_service socket creation failed";
     }
 
     listen(property_set_fd, 8);
diff --git a/init/reboot.cpp b/init/reboot.cpp
index 049c952..18f493a 100644
--- a/init/reboot.cpp
+++ b/init/reboot.cpp
@@ -483,6 +483,8 @@
                 // Run fsck once the file system is remounted in read-only mode.
                 run_fsck = true;
             } else if (cmd_params[1] == "thermal") {
+                // Turn off sources of heat immediately.
+                TurnOffBacklight();
                 // run_fsck is false to avoid delay
                 cmd = ANDROID_RB_THERMOFF;
             }
diff --git a/init/sigchld_handler.cpp b/init/sigchld_handler.cpp
index 8fc9956..fa67199 100644
--- a/init/sigchld_handler.cpp
+++ b/init/sigchld_handler.cpp
@@ -119,8 +119,7 @@
     // Create a signalling mechanism for SIGCHLD.
     int s[2];
     if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0, s) == -1) {
-        PLOG(ERROR) << "socketpair failed";
-        exit(1);
+        PLOG(FATAL) << "socketpair failed in sigchld_handler_init";
     }
 
     signal_write_fd = s[0];
diff --git a/libsync/tests/sync_test.cpp b/libsync/tests/sync_test.cpp
index f08e97e..0fb86d6 100644
--- a/libsync/tests/sync_test.cpp
+++ b/libsync/tests/sync_test.cpp
@@ -448,6 +448,41 @@
     ASSERT_EQ(mergedFence.wait(100), 0);
 }
 
+TEST(FenceTest, GetInfoActive) {
+    SyncTimeline timeline;
+    ASSERT_TRUE(timeline.isValid());
+
+    SyncFence fence(timeline, 1);
+    ASSERT_TRUE(fence.isValid());
+
+    vector<SyncPointInfo> info = fence.getInfo();
+    ASSERT_EQ(info.size(), 1);
+
+    ASSERT_FALSE(info[0].driverName.empty());
+    ASSERT_FALSE(info[0].objectName.empty());
+    ASSERT_EQ(info[0].timeStampNs, 0);
+    ASSERT_EQ(info[0].status, 0);
+}
+
+TEST(FenceTest, GetInfoSignaled) {
+    SyncTimeline timeline;
+    ASSERT_TRUE(timeline.isValid());
+
+    SyncFence fence(timeline, 1);
+    ASSERT_TRUE(fence.isValid());
+
+    ASSERT_EQ(timeline.inc(1), 0);
+    ASSERT_EQ(fence.wait(), 0);
+
+    vector<SyncPointInfo> info = fence.getInfo();
+    ASSERT_EQ(info.size(), 1);
+
+    ASSERT_FALSE(info[0].driverName.empty());
+    ASSERT_FALSE(info[0].objectName.empty());
+    ASSERT_GT(info[0].timeStampNs, 0);
+    ASSERT_EQ(info[0].status, 1);
+}
+
 TEST(StressTest, TwoThreadsSharedTimeline) {
     const int iterations = 1 << 16;
     int counter = 0;