Merge "[gwp-asan] fix tests under clang coverage, and extend invariants"
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 799c9f9..5172530 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -1099,7 +1099,9 @@
unique_fd fd(TEMP_FAILURE_RETRY(open(fname, O_RDONLY | O_BINARY)));
if (fd == -1) {
- return false;
+ auto path = find_item_given_name(fname);
+ fd = unique_fd(TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_BINARY)));
+ if (fd == -1) return false;
}
struct stat s;
@@ -2143,10 +2145,6 @@
android::base::InitLogging(argv, FastbootLogger, FastbootAborter);
bool wants_wipe = false;
- bool wants_reboot = false;
- bool wants_reboot_bootloader = false;
- bool wants_reboot_recovery = false;
- bool wants_reboot_fastboot = false;
bool skip_reboot = false;
bool wants_set_active = false;
bool skip_secondary = false;
@@ -2335,7 +2333,7 @@
}
}
}
-
+ std::unique_ptr<Task> reboot_task = nullptr;
std::vector<std::string> args(argv, argv + argc);
while (!args.empty()) {
std::string command = next_arg(&args);
@@ -2387,30 +2385,19 @@
fb->Download("signature", data);
fb->RawCommand("signature", "installing signature");
} else if (command == FB_CMD_REBOOT) {
- wants_reboot = true;
-
if (args.size() == 1) {
- std::string what = next_arg(&args);
- if (what == "bootloader") {
- wants_reboot = false;
- wants_reboot_bootloader = true;
- } else if (what == "recovery") {
- wants_reboot = false;
- wants_reboot_recovery = true;
- } else if (what == "fastboot") {
- wants_reboot = false;
- wants_reboot_fastboot = true;
- } else {
- syntax_error("unknown reboot target %s", what.c_str());
- }
+ std::string reboot_target = next_arg(&args);
+ reboot_task = std::make_unique<RebootTask>(fb, reboot_target);
+ } else {
+ reboot_task = std::make_unique<RebootTask>(fb);
}
if (!args.empty()) syntax_error("junk after reboot command");
} else if (command == FB_CMD_REBOOT_BOOTLOADER) {
- wants_reboot_bootloader = true;
+ reboot_task = std::make_unique<RebootTask>(fb, "bootloader");
} else if (command == FB_CMD_REBOOT_RECOVERY) {
- wants_reboot_recovery = true;
+ reboot_task = std::make_unique<RebootTask>(fb, "recovery");
} else if (command == FB_CMD_REBOOT_FASTBOOT) {
- wants_reboot_fastboot = true;
+ reboot_task = std::make_unique<RebootTask>(fb, "fastboot");
} else if (command == FB_CMD_CONTINUE) {
fb->Continue();
} else if (command == FB_CMD_BOOT) {
@@ -2454,7 +2441,7 @@
} else {
do_flashall(slot_override, skip_secondary, wants_wipe, force_flash);
}
- wants_reboot = true;
+ reboot_task = std::make_unique<RebootTask>(fb);
} else if (command == "update") {
bool slot_all = (slot_override == "all");
if (slot_all) {
@@ -2466,7 +2453,7 @@
filename = next_arg(&args);
}
do_update(filename.c_str(), slot_override, skip_secondary || slot_all, force_flash);
- wants_reboot = true;
+ reboot_task = std::make_unique<RebootTask>(fb);
} else if (command == FB_CMD_SET_ACTIVE) {
std::string slot = verify_slot(next_arg(&args), false);
fb->SetActive(slot);
@@ -2538,7 +2525,6 @@
syntax_error("unknown command %s", command.c_str());
}
}
-
if (wants_wipe) {
if (force_flash) {
CancelSnapshotIfNeeded();
@@ -2557,19 +2543,9 @@
if (wants_set_active) {
fb->SetActive(next_active);
}
- if (wants_reboot && !skip_reboot) {
- fb->Reboot();
- fb->WaitForDisconnect();
- } else if (wants_reboot_bootloader) {
- fb->RebootTo("bootloader");
- fb->WaitForDisconnect();
- } else if (wants_reboot_recovery) {
- fb->RebootTo("recovery");
- fb->WaitForDisconnect();
- } else if (wants_reboot_fastboot) {
- reboot_to_userspace_fastboot();
+ if (reboot_task && !skip_reboot) {
+ reboot_task->Run();
}
-
fprintf(stderr, "Finished. Total time: %.3fs\n", (now() - start));
auto* old_transport = fb->set_transport(nullptr);
diff --git a/fastboot/task.cpp b/fastboot/task.cpp
index 3f33c76..94dd5c3 100644
--- a/fastboot/task.cpp
+++ b/fastboot/task.cpp
@@ -14,6 +14,8 @@
// limitations under the License.
//
#include "task.h"
+#include "fastboot.h"
+#include "util.h"
#include "fastboot.h"
#include "util.h"
@@ -44,3 +46,27 @@
};
do_for_partitions(pname_, slot_, flash, true);
}
+
+RebootTask::RebootTask(fastboot::FastBootDriver* _fb) : fb_(_fb){};
+RebootTask::RebootTask(fastboot::FastBootDriver* _fb, std::string _reboot_target)
+ : reboot_target_(std::move(_reboot_target)), fb_(_fb){};
+
+void RebootTask::Run() {
+ if ((reboot_target_ == "userspace" || reboot_target_ == "fastboot")) {
+ if (!is_userspace_fastboot()) {
+ reboot_to_userspace_fastboot();
+ fb_->WaitForDisconnect();
+ }
+ } else if (reboot_target_ == "recovery") {
+ fb_->RebootTo("recovery");
+ fb_->WaitForDisconnect();
+ } else if (reboot_target_ == "bootloader") {
+ fb_->RebootTo("bootloader");
+ fb_->WaitForDisconnect();
+ } else if (reboot_target_ == "") {
+ fb_->Reboot();
+ fb_->WaitForDisconnect();
+ } else {
+ syntax_error("unknown reboot target %s", reboot_target_.c_str());
+ }
+}
diff --git a/fastboot/task.h b/fastboot/task.h
index 216e658..582fa2f 100644
--- a/fastboot/task.h
+++ b/fastboot/task.h
@@ -18,9 +18,7 @@
#include <sstream>
#include <string>
-#include "fastboot.h"
#include "fastboot_driver.h"
-#include "util.h"
class Task {
public:
@@ -46,3 +44,15 @@
const std::string slot_;
bool force_flash_ = false;
};
+
+class RebootTask : public Task {
+ public:
+ RebootTask(fastboot::FastBootDriver* _fb);
+ RebootTask(fastboot::FastBootDriver* _fb, const std::string _reboot_target);
+ void Run() override;
+ ~RebootTask() {}
+
+ private:
+ const std::string reboot_target_ = "";
+ fastboot::FastBootDriver* fb_;
+};
\ No newline at end of file
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp
index b180a58..66e1e63 100644
--- a/healthd/BatteryMonitor.cpp
+++ b/healthd/BatteryMonitor.cpp
@@ -392,12 +392,13 @@
mHealthInfo->batteryFullChargeDesignCapacityUah =
getIntField(mHealthdConfig->batteryFullChargeDesignCapacityUahPath);
- if (!mHealthdConfig->batteryStateOfHealthPath.isEmpty())
- mHealthInfo->batteryStateOfHealth = getIntField(mHealthdConfig->batteryStateOfHealthPath);
-
if (!mHealthdConfig->batteryHealthStatusPath.isEmpty())
mBatteryHealthStatus = getIntField(mHealthdConfig->batteryHealthStatusPath);
+ if (!mHealthdConfig->batteryStateOfHealthPath.isEmpty())
+ mHealthInfo->batteryHealthData->batteryStateOfHealth =
+ getIntField(mHealthdConfig->batteryStateOfHealthPath);
+
if (!mHealthdConfig->batteryManufacturingDatePath.isEmpty())
mHealthInfo->batteryHealthData->batteryManufacturingDateSeconds =
getIntField(mHealthdConfig->batteryManufacturingDatePath);
@@ -591,6 +592,10 @@
if (!mHealthdConfig->batteryFirstUsageDatePath.isEmpty())
return getIntField(mHealthdConfig->batteryFirstUsageDatePath);
}
+ if (id == BATTERY_PROP_STATE_OF_HEALTH) {
+ if (!mHealthdConfig->batteryStateOfHealthPath.isEmpty())
+ return getIntField(mHealthdConfig->batteryStateOfHealthPath);
+ }
return 0;
}
@@ -669,6 +674,11 @@
ret = OK;
break;
+ case BATTERY_PROP_STATE_OF_HEALTH:
+ val->valueInt64 = getBatteryHealthData(BATTERY_PROP_STATE_OF_HEALTH);
+ ret = OK;
+ break;
+
default:
break;
}
diff --git a/init/init.cpp b/init/init.cpp
index f964c60..c965fe6 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -51,6 +51,7 @@
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include <android-base/thread_annotations.h>
#include <fs_avb/fs_avb.h>
#include <fs_mgr_vendor_overlay.h>
#include <keyutils.h>
@@ -211,16 +212,16 @@
}
private:
- void ResetWaitForPropLocked() {
+ void ResetWaitForPropLocked() EXCLUSIVE_LOCKS_REQUIRED(lock_) {
wait_prop_name_.clear();
wait_prop_value_.clear();
waiting_for_prop_.reset();
}
std::mutex lock_;
- std::unique_ptr<Timer> waiting_for_prop_{nullptr};
- std::string wait_prop_name_;
- std::string wait_prop_value_;
+ GUARDED_BY(lock_) std::unique_ptr<Timer> waiting_for_prop_{nullptr};
+ GUARDED_BY(lock_) std::string wait_prop_name_;
+ GUARDED_BY(lock_) std::string wait_prop_value_;
} prop_waiter_state;
@@ -259,7 +260,7 @@
private:
std::mutex shutdown_command_lock_;
- std::string shutdown_command_;
+ std::string shutdown_command_ GUARDED_BY(shutdown_command_lock_);
bool do_shutdown_ = false;
} shutdown_state;
diff --git a/init/selinux.cpp b/init/selinux.cpp
index 4cc00fe..062ed39 100644
--- a/init/selinux.cpp
+++ b/init/selinux.cpp
@@ -897,29 +897,31 @@
continue;
}
- auto system_entry = GetEntryForMountPoint(&fstab, "/system");
- if (!system_entry) {
- LOG(ERROR) << "Could not find mount entry for /system";
- break;
- }
- if (!system_entry->fs_mgr_flags.logical) {
- LOG(INFO) << "Skipping mount of " << name << ", system is not dynamic.";
- break;
- }
+ auto system_entries = GetEntriesForMountPoint(&fstab, "/system");
+ for (auto& system_entry : system_entries) {
+ if (!system_entry) {
+ LOG(ERROR) << "Could not find mount entry for /system";
+ break;
+ }
+ if (!system_entry->fs_mgr_flags.logical) {
+ LOG(INFO) << "Skipping mount of " << name << ", system is not dynamic.";
+ break;
+ }
- auto entry = *system_entry;
- auto partition_name = name + fs_mgr_get_slot_suffix();
- auto replace_name = "system"s + fs_mgr_get_slot_suffix();
+ auto entry = *system_entry;
+ auto partition_name = name + fs_mgr_get_slot_suffix();
+ auto replace_name = "system"s + fs_mgr_get_slot_suffix();
- entry.mount_point = "/"s + name;
- entry.blk_device =
+ entry.mount_point = "/"s + name;
+ entry.blk_device =
android::base::StringReplace(entry.blk_device, replace_name, partition_name, false);
- if (!fs_mgr_update_logical_partition(&entry)) {
- LOG(ERROR) << "Could not update logical partition";
- continue;
- }
+ if (!fs_mgr_update_logical_partition(&entry)) {
+ LOG(ERROR) << "Could not update logical partition";
+ continue;
+ }
- extra_fstab.emplace_back(std::move(entry));
+ extra_fstab.emplace_back(std::move(entry));
+ }
}
SkipMountingPartitions(&extra_fstab, true /* verbose */);
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 2929da4..68191bb 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -925,6 +925,10 @@
mkdir /data/system/dropbox 0700 system system
mkdir /data/system/heapdump 0700 system system
mkdir /data/system/users 0775 system system
+ # Mkdir and set SELinux security contexts for shutdown-checkpoints.
+ # TODO(b/270286197): remove these after couple releases.
+ mkdir /data/system/shutdown-checkpoints 0700 system system
+ restorecon_recursive /data/system/shutdown-checkpoints
# Create the parent directories of the user CE and DE storage directories.
# These parent directories must use encryption=None, since each of their