Merge "core/init.rc: Add /data/cache/* directory creation" into nyc-mr1-dev
diff --git a/adb/shell_service.cpp b/adb/shell_service.cpp
index f98394d..104f399 100644
--- a/adb/shell_service.cpp
+++ b/adb/shell_service.cpp
@@ -155,7 +155,7 @@
const std::string& command() const { return command_; }
- int local_socket_fd() const { return local_socket_sfd_.fd(); }
+ int ReleaseLocalSocket() { return local_socket_sfd_.Release(); }
pid_t pid() const { return pid_; }
@@ -450,7 +450,7 @@
Subprocess* subprocess = reinterpret_cast<Subprocess*>(userdata);
adb_thread_setname(android::base::StringPrintf(
- "shell srvc %d", subprocess->local_socket_fd()));
+ "shell srvc %d", subprocess->pid()));
D("passing data streams for PID %d", subprocess->pid());
subprocess->PassDataStreams();
@@ -761,14 +761,13 @@
return ReportError(protocol, error);
}
- unique_fd local_socket(dup(subprocess->local_socket_fd()));
- D("subprocess creation successful: local_socket_fd=%d, pid=%d", local_socket.get(),
- subprocess->pid());
+ int local_socket = subprocess->ReleaseLocalSocket();
+ D("subprocess creation successful: local_socket_fd=%d, pid=%d", local_socket, subprocess->pid());
if (!Subprocess::StartThread(std::move(subprocess), &error)) {
LOG(ERROR) << "failed to start subprocess management thread: " << error;
return ReportError(protocol, error);
}
- return local_socket.release();
+ return local_socket;
}
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 142a5e8..3b2999b 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -49,6 +49,7 @@
#include <android-base/parseint.h>
#include <android-base/parsenetaddress.h>
+#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <sparse/sparse.h>
#include <ziparchive/zip_archive.h>
@@ -101,25 +102,39 @@
static struct {
char img_name[17];
char sig_name[17];
- char item_name[17];
char part_name[9];
- bool active_slot;
bool is_optional;
+ bool is_secondary;
} images[] = {
- {"boot.img", "boot.sig", "boot", "boot", true, false},
- {"boot_other.img", "boot_other.sig", "boot_other", "boot", false, true},
- {"recovery.img", "recovery.sig", "recovery", "recovery", true, true},
- {"system.img", "system.sig", "system", "system", true, false},
- {"system_other.img", "system_other.sig", "system_other", "system", false, true},
- {"vendor.img", "vendor.sig", "vendor", "vendor", true, true},
- {"vendor_other.img", "vendor_other.sig", "vendor_other", "vendor", false, true},
+ {"boot.img", "boot.sig", "boot", false, false},
+ {"boot_other.img", "boot.sig", "boot", true, true},
+ {"recovery.img", "recovery.sig", "recovery", true, false},
+ {"system.img", "system.sig", "system", false, false},
+ {"system_other.img", "system.sig", "system", true, true},
+ {"vendor.img", "vendor.sig", "vendor", true, false},
+ {"vendor_other.img", "vendor.sig", "vendor", true, true},
};
-static char* find_item(const char* item, const char* product) {
+static std::string find_item_given_name(const char* img_name, const char* product) {
char *dir;
- const char *fn;
char path[PATH_MAX + 128];
+ if(product) {
+ get_my_path(path);
+ return android::base::StringPrintf("../../../target/product/%s/%s", product, img_name);
+ }
+
+ dir = getenv("ANDROID_PRODUCT_OUT");
+ if((dir == 0) || (dir[0] == 0)) {
+ die("neither -p product specified nor ANDROID_PRODUCT_OUT set");
+ }
+
+ return android::base::StringPrintf("%s/%s", dir, img_name);
+}
+
+std::string find_item(const char* item, const char* product) {
+ const char *fn;
+
if(!strcmp(item,"boot")) {
fn = "boot.img";
} else if(!strcmp(item,"recovery")) {
@@ -134,32 +149,12 @@
fn = "cache.img";
} else if(!strcmp(item,"info")) {
fn = "android-info.txt";
- } else if(!strcmp(item,"system_other")) {
- fn = "system_other.img";
- } else if(!strcmp(item,"boot_other")) {
- fn = "boot_other.img";
- } else if(!strcmp(item,"vendor_other")) {
- fn = "vendor_other.img";
} else {
fprintf(stderr,"unknown partition '%s'\n", item);
- return 0;
+ return "";
}
- if(product) {
- get_my_path(path);
- sprintf(path + strlen(path),
- "../../../target/product/%s/%s", product, fn);
- return strdup(path);
- }
-
- dir = getenv("ANDROID_PRODUCT_OUT");
- if((dir == 0) || (dir[0] == 0)) {
- die("neither -p product specified nor ANDROID_PRODUCT_OUT set");
- return 0;
- }
-
- sprintf(path, "%s/%s", dir, fn);
- return strdup(path);
+ return find_item_given_name(fn, product);
}
static int64_t get_file_size(int fd) {
@@ -325,8 +320,16 @@
"\n"
"commands:\n"
" update <filename> Reflash device from update.zip.\n"
+ " Sets the flashed slot as active.\n"
" flashall Flash boot, system, vendor, and --\n"
- " if found -- recovery.\n"
+ " if found -- recovery. If the device\n"
+ " supports slots, the slot that has\n"
+ " been flashed to is set as active.\n"
+ " Secondary images may be flashed to\n"
+ " an inactive slot.\n"
+ " flash-primary Same as flashall, but do not flash\n"
+ " secondary images.\n"
+ " flash-secondary Only flashes the secondary images.\n"
" flash <partition> [ <filename> ] Write a file to a flash partition.\n"
" flashing lock Locks the device. Prevents flashing.\n"
" flashing unlock Unlocks the device. Allows flashing\n"
@@ -349,7 +352,7 @@
" override the fs type and/or size\n"
" the bootloader reports.\n"
" getvar <variable> Display a bootloader variable.\n"
- " set_active <suffix> Sets the active slot. If slots are\n"
+ " set_active <slot> Sets the active slot. If slots are\n"
" not supported, this does nothing.\n"
" boot <kernel> [ <ramdisk> [ <second> ] ] Download and boot kernel.\n"
" flash:raw boot <kernel> [ <ramdisk> [ <second> ] ]\n"
@@ -368,8 +371,8 @@
" formatting.\n"
" -s <specific device> Specify a device. For USB, provide either\n"
" a serial number or path to device port.\n"
- " For ethernet, provide an address in the"
- " form <protocol>:<hostname>[:port] where"
+ " For ethernet, provide an address in the\n"
+ " form <protocol>:<hostname>[:port] where\n"
" <protocol> is either tcp or udp.\n"
" -p <product> Specify product name.\n"
" -c <cmdline> Override kernel commandline.\n"
@@ -386,20 +389,21 @@
" (default: 2048).\n"
" -S <size>[K|M|G] Automatically sparse files greater\n"
" than 'size'. 0 to disable.\n"
- " --slot <suffix> Specify slot suffix to be used if the\n"
- " device supports slots. This will be\n"
- " added to all partition names that use\n"
- " slots. 'all' can be given to refer\n"
- " to all slots. 'other' can be given to\n"
- " refer to a non-current slot. 'active' can\n"
- " be given to refer to a current slot only.\n"
- " If this flag is not given slots will be\n"
- " written to based on the filename.\n"
- " -a, --set-active[=<suffix>] Sets the active slot. If no suffix is\n"
+ " --slot <slot> Specify slot name to be used if the\n"
+ " device supports slots. All operations\n"
+ " on partitions that support slots will\n"
+ " be done on the slot specified.\n"
+ " 'all' can be given to refer to all slots.\n"
+ " 'other' can be given to refer to a\n"
+ " non-current slot. If this flag is not\n"
+ " used, slotted partitions will default\n"
+ " to the current active slot.\n"
+ " -a, --set-active[=<slot>] Sets the active slot. If no slot is\n"
" provided, this will default to the value\n"
" given by --slot. If slots are not\n"
- " supported, this does nothing. This will\n"
- " run after all non-reboot commands.\n"
+ " supported, this sets the current slot\n"
+ " to be active. This will run after all\n"
+ " non-reboot commands.\n"
#if !defined(_WIN32)
" --wipe-and-use-fbe On devices which support it,\n"
" erase userdata and cache, and\n"
@@ -860,101 +864,138 @@
}
}
-static bool has_slots(Transport* transport) {
- std::string suffix_list_unused;
- return fb_getvar(transport, "slot-suffixes", &suffix_list_unused);
-}
-
-static std::vector<std::string> get_suffixes(Transport* transport) {
- std::vector<std::string> suffixes;
- std::string suffix_list;
- if (!fb_getvar(transport, "slot-suffixes", &suffix_list)) {
- die("Could not get suffixes.\n");
- }
- return android::base::Split(suffix_list, ",");
-}
-
-// Returns a std::string of the slot name 'active_offset' after the active slot
-static std::string get_slot_name(Transport* transport, size_t active_offset) {
- std::vector<std::string> suffixes = get_suffixes(transport);
+static std::string get_current_slot(Transport* transport)
+{
std::string current_slot;
- if (!fb_getvar(transport, "current-slot", ¤t_slot)) {
- die("Failed to identify current slot.");
+ if (fb_getvar(transport, "current-slot", ¤t_slot)) {
+ if (current_slot == "_a") return "a"; // Legacy support
+ if (current_slot == "_b") return "b"; // Legacy support
+ return current_slot;
}
- if (active_offset >= suffixes.size()) {
- die("active slot offset larger than total number of slots!");
- }
- if (!suffixes.empty()) {
- for (size_t i = 0; i < suffixes.size(); i++) {
- if (current_slot == suffixes[i])
- return suffixes[(i + active_offset) % suffixes.size()];
- }
- } else {
- die("No known slots.");
- }
- die("Unable to find current slot");
return "";
}
-static std::string verify_slot(Transport* transport, const char *slot, bool allow_all) {
- if (strcmp(slot, "all") == 0) {
+// Legacy support
+static std::vector<std::string> get_suffixes_obsolete(Transport* transport) {
+ std::vector<std::string> suffixes;
+ std::string suffix_list;
+ if (!fb_getvar(transport, "slot-suffixes", &suffix_list)) {
+ return suffixes;
+ }
+ suffixes = android::base::Split(suffix_list, ",");
+ // Unfortunately some devices will return an error message in the
+ // guise of a valid value. If we only see only one suffix, it's probably
+ // not real.
+ if (suffixes.size() == 1) {
+ suffixes.clear();
+ }
+ return suffixes;
+}
+
+// Legacy support
+static bool supports_AB_obsolete(Transport* transport) {
+ return !get_suffixes_obsolete(transport).empty();
+}
+
+static int get_slot_count(Transport* transport) {
+ std::string var;
+ int count;
+ if (!fb_getvar(transport, "slot-count", &var)) {
+ if (supports_AB_obsolete(transport)) return 2; // Legacy support
+ }
+ if (!android::base::ParseInt(var.c_str(), &count)) return 0;
+ return count;
+}
+
+static bool supports_AB(Transport* transport) {
+ return get_slot_count(transport) >= 2;
+}
+
+// Given a current slot, this returns what the 'other' slot is.
+static std::string get_other_slot(const std::string& current_slot, int count) {
+ if (count == 0) return "";
+
+ char next = (current_slot[0] - 'a' + 1)%count + 'a';
+ return std::string(1, next);
+}
+
+static std::string get_other_slot(Transport* transport, const std::string& current_slot) {
+ return get_other_slot(current_slot, get_slot_count(transport));
+}
+
+static std::string get_other_slot(Transport* transport, int count) {
+ return get_other_slot(get_current_slot(transport), count);
+}
+
+static std::string get_other_slot(Transport* transport) {
+ return get_other_slot(get_current_slot(transport), get_slot_count(transport));
+}
+
+static std::string verify_slot(Transport* transport, const std::string& slot_name, bool allow_all) {
+ std::string slot = slot_name;
+ if (slot == "_a") slot = "a"; // Legacy support
+ if (slot == "_b") slot = "b"; // Legacy support
+ if (slot == "all") {
if (allow_all) {
return "all";
} else {
- std::vector<std::string> suffixes = get_suffixes(transport);
- if (!suffixes.empty()) {
- return suffixes[0];
+ int count = get_slot_count(transport);
+ if (count > 0) {
+ return "a";
} else {
die("No known slots.");
}
}
}
- std::vector<std::string> suffixes = get_suffixes(transport);
+ int count = get_slot_count(transport);
+ if (count == 0) die("Device does not support slots.\n");
- if (strcmp(slot, "other") == 0) {
- return get_slot_name(transport, 1);
- } else if (strcmp(slot, "active") == 0) {
- return get_slot_name(transport, 0);
+ if (slot == "other") {
+ std::string other = get_other_slot(transport, count);
+ if (other == "") {
+ die("No known slots.");
+ }
+ return other;
}
- for (const std::string &suffix : suffixes) {
- if (suffix == slot)
- return slot;
+ if (slot.size() == 1 && (slot[0]-'a' >= 0 && slot[0]-'a' < count)) return slot;
+
+ fprintf(stderr, "Slot %s does not exist. supported slots are:\n", slot.c_str());
+ for (int i=0; i<count; i++) {
+ fprintf(stderr, "%c\n", (char)(i + 'a'));
}
- fprintf(stderr, "Slot %s does not exist. supported slots are:\n", slot);
- for (const std::string &suffix : suffixes) {
- fprintf(stderr, "%s\n", suffix.c_str());
- }
+
exit(1);
}
-static std::string verify_slot(Transport* transport, const char *slot) {
+static std::string verify_slot(Transport* transport, const std::string& slot) {
return verify_slot(transport, slot, true);
}
-static void do_for_partition(Transport* transport, const char *part, const char *slot,
+static void do_for_partition(Transport* transport, const std::string& part, const std::string& slot,
std::function<void(const std::string&)> func, bool force_slot) {
std::string has_slot;
std::string current_slot;
- if (!fb_getvar(transport, std::string("has-slot:")+part, &has_slot)) {
+ if (!fb_getvar(transport, "has-slot:" + part, &has_slot)) {
/* If has-slot is not supported, the answer is no. */
has_slot = "no";
}
if (has_slot == "yes") {
- if (!slot || slot[0] == 0) {
- if (!fb_getvar(transport, "current-slot", ¤t_slot)) {
+ if (slot == "") {
+ current_slot = get_current_slot(transport);
+ if (current_slot == "") {
die("Failed to identify current slot.\n");
}
- func(std::string(part) + current_slot);
+ func(part + "_" + current_slot);
} else {
- func(std::string(part) + slot);
+ func(part + '_' + slot);
}
} else {
- if (force_slot && slot && slot[0]) {
+ if (force_slot && slot != "") {
fprintf(stderr, "Warning: %s does not support slots, and slot %s was requested.\n",
- part, slot);
+ part.c_str(), slot.c_str());
}
func(part);
}
@@ -965,18 +1006,17 @@
* partition names. If force_slot is true, it will fail if a slot is specified, and the given
* partition does not support slots.
*/
-static void do_for_partitions(Transport* transport, const char *part, const char *slot,
+static void do_for_partitions(Transport* transport, const std::string& part, const std::string& slot,
std::function<void(const std::string&)> func, bool force_slot) {
std::string has_slot;
- if (slot && strcmp(slot, "all") == 0) {
- if (!fb_getvar(transport, std::string("has-slot:") + part, &has_slot)) {
- die("Could not check if partition %s has slot.", part);
+ if (slot == "all") {
+ if (!fb_getvar(transport, "has-slot:" + part, &has_slot)) {
+ die("Could not check if partition %s has slot.", part.c_str());
}
if (has_slot == "yes") {
- std::vector<std::string> suffixes = get_suffixes(transport);
- for (std::string &suffix : suffixes) {
- do_for_partition(transport, part, suffix.c_str(), func, force_slot);
+ for (int i=0; i < get_slot_count(transport); i++) {
+ do_for_partition(transport, part, std::string(1, (char)(i + 'a')), func, force_slot);
}
} else {
do_for_partition(transport, part, "", func, force_slot);
@@ -1003,7 +1043,28 @@
fb_queue_command("signature", "installing signature");
}
-static void do_update(Transport* transport, const char* filename, const char* slot_override, bool erase_first) {
+// Sets slot_override as the active slot. If slot_override is blank,
+// set current slot as active instead. This clears slot-unbootable.
+static void set_active(Transport* transport, const std::string& slot_override) {
+ std::string separator = "";
+ if (!supports_AB(transport)) {
+ if (supports_AB_obsolete(transport)) {
+ separator = "_"; // Legacy support
+ } else {
+ return;
+ }
+ }
+ if (slot_override != "") {
+ fb_set_active((separator + slot_override).c_str());
+ } else {
+ std::string current_slot = get_current_slot(transport);
+ if (current_slot != "") {
+ fb_set_active((separator + current_slot).c_str());
+ }
+ }
+}
+
+static void do_update(Transport* transport, const char* filename, const std::string& slot_override, bool erase_first) {
queue_info_dump();
fb_queue_query_save("product", cur_product, sizeof(cur_product));
@@ -1024,7 +1085,31 @@
setup_requirements(reinterpret_cast<char*>(data), sz);
+ std::string secondary;
+ bool update_secondary = slot_override != "all";
+ if (update_secondary) {
+ if (slot_override != "") {
+ secondary = get_other_slot(transport, slot_override);
+ } else {
+ secondary = get_other_slot(transport);
+ }
+ if (secondary == "") {
+ if (supports_AB(transport)) {
+ fprintf(stderr, "Warning: Could not determine slot for secondary images. Ignoring.\n");
+ }
+ update_secondary = false;
+ }
+ }
for (size_t i = 0; i < ARRAY_SIZE(images); ++i) {
+ const char* slot = slot_override.c_str();
+ if (images[i].is_secondary) {
+ if (update_secondary) {
+ slot = secondary.c_str();
+ } else {
+ continue;
+ }
+ }
+
int fd = unzip_to_file(zip, images[i].img_name);
if (fd == -1) {
if (images[i].is_optional) {
@@ -1048,65 +1133,70 @@
* program exits.
*/
};
- do_for_partitions(transport, images[i].part_name, slot_override, update, false);
+ do_for_partitions(transport, images[i].part_name, slot, update, false);
}
CloseArchive(zip);
+ set_active(transport, slot_override);
}
-static void do_send_signature(char* fn) {
- char* xtn = strrchr(fn, '.');
- if (!xtn) return;
+static void do_send_signature(const std::string& fn) {
+ std::size_t extension_loc = fn.find(".img");
+ if (extension_loc == std::string::npos) return;
- if (strcmp(xtn, ".img")) return;
-
- strcpy(xtn, ".sig");
+ std::string fs_sig = fn.substr(0, extension_loc) + ".sig";
int64_t sz;
- void* data = load_file(fn, &sz);
- strcpy(xtn, ".img");
+ void* data = load_file(fs_sig.c_str(), &sz);
if (data == nullptr) return;
fb_queue_download("signature", data, sz);
fb_queue_command("signature", "installing signature");
}
-static void do_flashall(Transport* transport, const char* slot_override, int erase_first) {
- queue_info_dump();
- const bool device_has_slots = has_slots(transport);
- const bool has_slot_override = slot_override != nullptr && strcmp(slot_override, "") != 0;
- const bool should_ignore_slots = !device_has_slots || has_slot_override;
+static void do_flashall(Transport* transport, const std::string& slot_override, int erase_first, bool flash_primary, bool flash_secondary) {
+ std::string fname;
+ if (flash_primary) {
+ queue_info_dump();
- fb_queue_query_save("product", cur_product, sizeof(cur_product));
+ fb_queue_query_save("product", cur_product, sizeof(cur_product));
- char* fname = find_item("info", product);
- if (fname == nullptr) die("cannot find android-info.txt");
+ fname = find_item("info", product);
+ if (fname == "") die("cannot find android-info.txt");
- int64_t sz;
- void* data = load_file(fname, &sz);
- if (data == nullptr) die("could not load android-info.txt: %s", strerror(errno));
+ int64_t sz;
+ void* data = load_file(fname.c_str(), &sz);
+ if (data == nullptr) die("could not load android-info.txt: %s", strerror(errno));
- setup_requirements(reinterpret_cast<char*>(data), sz);
+ setup_requirements(reinterpret_cast<char*>(data), sz);
+ }
+ std::string secondary;
+ if (flash_secondary) {
+ if (slot_override != "") {
+ secondary = get_other_slot(transport, slot_override);
+ } else {
+ secondary = get_other_slot(transport);
+ }
+ if (secondary == "") {
+ if (supports_AB(transport)) {
+ fprintf(stderr, "Warning: Could not determine slot for secondary images. Ignoring.\n");
+ }
+ flash_secondary = false;
+ }
+ }
for (size_t i = 0; i < ARRAY_SIZE(images); i++) {
- if (should_ignore_slots && !images[i].active_slot) {
- // We will not do anything with _other files if we are given an explicit slot to use.
- continue;
- }
- fname = find_item(images[i].item_name, product);
- fastboot_buffer buf;
- if (load_buf(transport, fname, &buf)) {
- if (images[i].is_optional)
- continue;
- die("could not load %s\n", images[i].img_name);
- }
- // Get the actual slot we are writing to based on the filename. This is because we need to
- // sometimes write the 'active + 1'th slot for first boot optimization reasons. This is
- // defined by the images array unless one is explicitly provided.
- std::string real_slot_override;
- if (should_ignore_slots) {
- real_slot_override = slot_override;
+ const char* slot = NULL;
+ if (images[i].is_secondary) {
+ if (flash_secondary) slot = secondary.c_str();
} else {
- real_slot_override = get_slot_name(transport, images[i].active_slot ? 0 : 1);
+ if (flash_primary) slot = slot_override.c_str();
+ }
+ if (!slot) continue;
+ fname = find_item_given_name(images[i].img_name, product);
+ fastboot_buffer buf;
+ if (load_buf(transport, fname.c_str(), &buf)) {
+ if (images[i].is_optional) continue;
+ die("could not load %s\n", images[i].img_name);
}
auto flashall = [&](const std::string &partition) {
@@ -1116,12 +1206,10 @@
}
flash_buf(partition.c_str(), &buf);
};
- do_for_partitions(transport,
- images[i].part_name,
- real_slot_override.c_str(),
- flashall,
- false);
+ do_for_partitions(transport, images[i].part_name, slot, flashall, false);
}
+
+ if (flash_primary) set_active(transport, slot_override);
}
#define skip(n) do { argc -= (n); argv += (n); } while (0)
@@ -1448,17 +1536,23 @@
return 1;
}
- if (slot_override != "")
- slot_override = verify_slot(transport, slot_override.c_str());
- if (next_active != "")
- next_active = verify_slot(transport, next_active.c_str(), false);
+ if (!supports_AB(transport) && supports_AB_obsolete(transport)) {
+ fprintf(stderr, "Warning: Device A/B support is outdated. Bootloader update required.\n");
+ }
+ if (slot_override != "") slot_override = verify_slot(transport, slot_override);
+ if (next_active != "") next_active = verify_slot(transport, next_active, false);
if (wants_set_active) {
if (next_active == "") {
if (slot_override == "") {
- wants_set_active = false;
+ std::string current_slot;
+ if (fb_getvar(transport, "current-slot", ¤t_slot)) {
+ next_active = verify_slot(transport, current_slot, false);
+ } else {
+ wants_set_active = false;
+ }
} else {
- next_active = verify_slot(transport, slot_override.c_str(), false);
+ next_active = verify_slot(transport, slot_override, false);
}
}
}
@@ -1481,7 +1575,7 @@
fb_queue_erase(partition.c_str());
};
- do_for_partitions(transport, argv[1], slot_override.c_str(), erase, true);
+ do_for_partitions(transport, argv[1], slot_override, erase, true);
skip(2);
} else if(!strncmp(*argv, "format", strlen("format"))) {
char *overrides;
@@ -1517,7 +1611,7 @@
fb_perform_format(transport, partition.c_str(), 0,
type_override, size_override, "");
};
- do_for_partitions(transport, argv[1], slot_override.c_str(), format, true);
+ do_for_partitions(transport, argv[1], slot_override, format, true);
skip(2);
} else if(!strcmp(*argv, "signature")) {
require(2);
@@ -1567,7 +1661,7 @@
fb_queue_command("boot", "booting");
} else if(!strcmp(*argv, "flash")) {
char *pname = argv[1];
- char *fname = 0;
+ std::string fname;
require(2);
if (argc > 2) {
fname = argv[2];
@@ -1576,15 +1670,15 @@
fname = find_item(pname, product);
skip(2);
}
- if (fname == 0) die("cannot determine image filename for '%s'", pname);
+ if (fname == "") die("cannot determine image filename for '%s'", pname);
auto flash = [&](const std::string &partition) {
if (erase_first && needs_erase(transport, partition.c_str())) {
fb_queue_erase(partition.c_str());
}
- do_flash(transport, partition.c_str(), fname);
+ do_flash(transport, partition.c_str(), fname.c_str());
};
- do_for_partitions(transport, pname, slot_override.c_str(), flash, true);
+ do_for_partitions(transport, pname, slot_override, flash, true);
} else if(!strcmp(*argv, "flash:raw")) {
char *kname = argv[2];
char *rname = 0;
@@ -1604,23 +1698,36 @@
auto flashraw = [&](const std::string &partition) {
fb_queue_flash(partition.c_str(), data, sz);
};
- do_for_partitions(transport, argv[1], slot_override.c_str(), flashraw, true);
+ do_for_partitions(transport, argv[1], slot_override, flashraw, true);
} else if(!strcmp(*argv, "flashall")) {
skip(1);
- do_flashall(transport, slot_override.c_str(), erase_first);
+ if (slot_override == "all") {
+ fprintf(stderr, "Warning: slot set to 'all'. Secondary slots will not be flashed.");
+ do_flashall(transport, slot_override, erase_first, true, false);
+ } else {
+ do_flashall(transport, slot_override, erase_first, true, true);
+ }
+ wants_reboot = true;
+ } else if(!strcmp(*argv, "flash-primary")) {
+ skip(1);
+ do_flashall(transport, slot_override, erase_first, true, false);
+ wants_reboot = true;
+ } else if(!strcmp(*argv, "flash-secondary")) {
+ skip(1);
+ do_flashall(transport, slot_override, erase_first, false, true);
wants_reboot = true;
} else if(!strcmp(*argv, "update")) {
if (argc > 1) {
- do_update(transport, argv[1], slot_override.c_str(), erase_first);
+ do_update(transport, argv[1], slot_override, erase_first);
skip(2);
} else {
- do_update(transport, "update.zip", slot_override.c_str(), erase_first);
+ do_update(transport, "update.zip", slot_override, erase_first);
skip(1);
}
wants_reboot = 1;
} else if(!strcmp(*argv, "set_active")) {
require(2);
- std::string slot = verify_slot(transport, argv[1], false);
+ std::string slot = verify_slot(transport, std::string(argv[1]), false);
fb_set_active(slot.c_str());
skip(2);
} else if(!strcmp(*argv, "oem")) {
diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
index c220a0c..5ccd80e 100644
--- a/include/private/android_filesystem_config.h
+++ b/include/private/android_filesystem_config.h
@@ -89,6 +89,12 @@
#define AID_DEBUGGERD 1045 /* debuggerd unprivileged user */
#define AID_MEDIA_CODEC 1046 /* mediacodec process */
#define AID_CAMERASERVER 1047 /* cameraserver process */
+#define AID_FIREWALL 1048 /* firewalld process */
+#define AID_TRUNKS 1049 /* trunksd process (TPM daemon) */
+#define AID_NVRAM 1050 /* Access-controlled NVRAM */
+#define AID_DNS 1051 /* DNS resolution daemon (system: netd) */
+#define AID_DNS_TETHER 1052 /* DNS resolution daemon (tether: dnsmasq) */
+/* Changes to this file must be made in AOSP, *not* in internal branches. */
#define AID_SHELL 2000 /* adb and debug shell user */
#define AID_CACHE 2001 /* cache access */
@@ -196,6 +202,11 @@
{ "debuggerd", AID_DEBUGGERD, },
{ "mediacodec", AID_MEDIA_CODEC, },
{ "cameraserver", AID_CAMERASERVER, },
+ { "firewall", AID_FIREWALL, },
+ { "trunks", AID_TRUNKS, },
+ { "nvram", AID_NVRAM, },
+ { "dns", AID_DNS, },
+ { "dns_tether", AID_DNS_TETHER, },
{ "shell", AID_SHELL, },
{ "cache", AID_CACHE, },
diff --git a/include/system/graphics.h b/include/system/graphics.h
index 1ac1a00..529a562 100644
--- a/include/system/graphics.h
+++ b/include/system/graphics.h
@@ -1135,6 +1135,236 @@
} android_dataspace_t;
/*
+ * Color modes that may be supported by a display.
+ *
+ * Definitions:
+ * Rendering intent generally defines the goal in mapping a source (input)
+ * color to a destination device color for a given color mode.
+ *
+ * It is important to keep in mind three cases where mapping may be applied:
+ * 1. The source gamut is much smaller than the destination (display) gamut
+ * 2. The source gamut is much larger than the destination gamut (this will
+ * ordinarily be handled using colorimetric rendering, below)
+ * 3. The source and destination gamuts are roughly equal, although not
+ * completely overlapping
+ * Also, a common requirement for mappings is that skin tones should be
+ * preserved, or at least remain natural in appearance.
+ *
+ * Colorimetric Rendering Intent (All cases):
+ * Colorimetric indicates that colors should be preserved. In the case
+ * that the source gamut lies wholly within the destination gamut or is
+ * about the same (#1, #3), this will simply mean that no manipulations
+ * (no saturation boost, for example) are applied. In the case where some
+ * source colors lie outside the destination gamut (#2, #3), those will
+ * need to be mapped to colors that are within the destination gamut,
+ * while the already in-gamut colors remain unchanged.
+ *
+ * Non-colorimetric transforms can take many forms. There are no hard
+ * rules and it's left to the implementation to define.
+ * Two common intents are described below.
+ *
+ * Stretched-Gamut Enhancement Intent (Source < Destination):
+ * When the destination gamut is much larger than the source gamut (#1), the
+ * source primaries may be redefined to reflect the full extent of the
+ * destination space, or to reflect an intermediate gamut.
+ * Skin-tone preservation would likely be applied. An example might be sRGB
+ * input displayed on a DCI-P3 capable device, with skin-tone preservation.
+ *
+ * Within-Gamut Enhancement Intent (Source >= Destination):
+ * When the device (destination) gamut is not larger than the source gamut
+ * (#2 or #3), but the appearance of a larger gamut is desired, techniques
+ * such as saturation boost may be applied to the source colors. Skin-tone
+ * preservation may be applied. There is no unique method for within-gamut
+ * enhancement; it would be defined within a flexible color mode.
+ *
+ */
+typedef enum android_color_mode {
+
+ /*
+ * HAL_COLOR_MODE_DEFAULT is the "native" gamut of the display.
+ * White Point: Vendor/OEM defined
+ * Panel Gamma: Vendor/OEM defined (typically 2.2)
+ * Rendering Intent: Vendor/OEM defined (typically 'enhanced')
+ */
+ HAL_COLOR_MODE_NATIVE = 0,
+
+ /*
+ * HAL_COLOR_MODE_STANDARD_BT601_625 corresponds with display
+ * settings that implement the ITU-R Recommendation BT.601
+ * or Rec 601. Using 625 line version
+ * Rendering Intent: Colorimetric
+ * Primaries:
+ * x y
+ * green 0.290 0.600
+ * blue 0.150 0.060
+ * red 0.640 0.330
+ * white (D65) 0.3127 0.3290
+ *
+ * KR = 0.299, KB = 0.114. This adjusts the luminance interpretation
+ * for RGB conversion from the one purely determined by the primaries
+ * to minimize the color shift into RGB space that uses BT.709
+ * primaries.
+ *
+ * Gamma Correction (GC):
+ *
+ * if Vlinear < 0.018
+ * Vnonlinear = 4.500 * Vlinear
+ * else
+ * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099
+ */
+ HAL_COLOR_MODE_STANDARD_BT601_625 = 1,
+
+ /*
+ * Primaries:
+ * x y
+ * green 0.290 0.600
+ * blue 0.150 0.060
+ * red 0.640 0.330
+ * white (D65) 0.3127 0.3290
+ *
+ * Use the unadjusted KR = 0.222, KB = 0.071 luminance interpretation
+ * for RGB conversion.
+ *
+ * Gamma Correction (GC):
+ *
+ * if Vlinear < 0.018
+ * Vnonlinear = 4.500 * Vlinear
+ * else
+ * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099
+ */
+ HAL_COLOR_MODE_STANDARD_BT601_625_UNADJUSTED = 2,
+
+ /*
+ * Primaries:
+ * x y
+ * green 0.310 0.595
+ * blue 0.155 0.070
+ * red 0.630 0.340
+ * white (D65) 0.3127 0.3290
+ *
+ * KR = 0.299, KB = 0.114. This adjusts the luminance interpretation
+ * for RGB conversion from the one purely determined by the primaries
+ * to minimize the color shift into RGB space that uses BT.709
+ * primaries.
+ *
+ * Gamma Correction (GC):
+ *
+ * if Vlinear < 0.018
+ * Vnonlinear = 4.500 * Vlinear
+ * else
+ * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099
+ */
+ HAL_COLOR_MODE_STANDARD_BT601_525 = 3,
+
+ /*
+ * Primaries:
+ * x y
+ * green 0.310 0.595
+ * blue 0.155 0.070
+ * red 0.630 0.340
+ * white (D65) 0.3127 0.3290
+ *
+ * Use the unadjusted KR = 0.212, KB = 0.087 luminance interpretation
+ * for RGB conversion (as in SMPTE 240M).
+ *
+ * Gamma Correction (GC):
+ *
+ * if Vlinear < 0.018
+ * Vnonlinear = 4.500 * Vlinear
+ * else
+ * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099
+ */
+ HAL_COLOR_MODE_STANDARD_BT601_525_UNADJUSTED = 4,
+
+ /*
+ * HAL_COLOR_MODE_REC709 corresponds with display settings that implement
+ * the ITU-R Recommendation BT.709 / Rec. 709 for high-definition television.
+ * Rendering Intent: Colorimetric
+ * Primaries:
+ * x y
+ * green 0.300 0.600
+ * blue 0.150 0.060
+ * red 0.640 0.330
+ * white (D65) 0.3127 0.3290
+ *
+ * HDTV REC709 Inverse Gamma Correction (IGC): V represents normalized
+ * (with [0 to 1] range) value of R, G, or B.
+ *
+ * if Vnonlinear < 0.081
+ * Vlinear = Vnonlinear / 4.5
+ * else
+ * Vlinear = ((Vnonlinear + 0.099) / 1.099) ^ (1/0.45)
+ *
+ * HDTV REC709 Gamma Correction (GC):
+ *
+ * if Vlinear < 0.018
+ * Vnonlinear = 4.5 * Vlinear
+ * else
+ * Vnonlinear = 1.099 * (Vlinear) ^ 0.45 – 0.099
+ */
+ HAL_COLOR_MODE_STANDARD_BT709 = 5,
+
+ /*
+ * HAL_COLOR_MODE_DCI_P3 corresponds with display settings that implement
+ * SMPTE EG 432-1 and SMPTE RP 431-2
+ * Rendering Intent: Colorimetric
+ * Primaries:
+ * x y
+ * green 0.265 0.690
+ * blue 0.150 0.060
+ * red 0.680 0.320
+ * white (D65) 0.3127 0.3290
+ *
+ * Gamma: 2.2
+ */
+ HAL_COLOR_MODE_DCI_P3 = 6,
+
+ /*
+ * HAL_COLOR_MODE_SRGB corresponds with display settings that implement
+ * the sRGB color space. Uses the same primaries as ITU-R Recommendation
+ * BT.709
+ * Rendering Intent: Colorimetric
+ * Primaries:
+ * x y
+ * green 0.300 0.600
+ * blue 0.150 0.060
+ * red 0.640 0.330
+ * white (D65) 0.3127 0.3290
+ *
+ * PC/Internet (sRGB) Inverse Gamma Correction (IGC):
+ *
+ * if Vnonlinear ≤ 0.03928
+ * Vlinear = Vnonlinear / 12.92
+ * else
+ * Vlinear = ((Vnonlinear + 0.055)/1.055) ^ 2.4
+ *
+ * PC/Internet (sRGB) Gamma Correction (GC):
+ *
+ * if Vlinear ≤ 0.0031308
+ * Vnonlinear = 12.92 * Vlinear
+ * else
+ * Vnonlinear = 1.055 * (Vlinear)^(1/2.4) – 0.055
+ */
+ HAL_COLOR_MODE_SRGB = 7,
+
+ /*
+ * HAL_COLOR_MODE_ADOBE_RGB corresponds with the RGB color space developed
+ * by Adobe Systems, Inc. in 1998.
+ * Rendering Intent: Colorimetric
+ * Primaries:
+ * x y
+ * green 0.210 0.710
+ * blue 0.150 0.060
+ * red 0.640 0.330
+ * white (D65) 0.3127 0.3290
+ *
+ * Gamma: 2.2
+ */
+ HAL_COLOR_MODE_ADOBE_RGB = 8
+
+} android_color_mode_t;
+
+/*
* Color transforms that may be applied by hardware composer to the whole
* display.
*/
diff --git a/include/system/window.h b/include/system/window.h
index 44bfc9b..33b7c3d 100644
--- a/include/system/window.h
+++ b/include/system/window.h
@@ -278,6 +278,16 @@
* age will be 0.
*/
NATIVE_WINDOW_BUFFER_AGE = 13,
+
+ /*
+ * Returns the duration of the last dequeueBuffer call in microseconds
+ */
+ NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14,
+
+ /*
+ * Returns the duration of the last queueBuffer call in microseconds
+ */
+ NATIVE_WINDOW_LAST_QUEUE_DURATION = 15,
};
/* Valid operations for the (*perform)() hook.
diff --git a/include/utils/Unicode.h b/include/utils/Unicode.h
index a006082..cddbab4 100644
--- a/include/utils/Unicode.h
+++ b/include/utils/Unicode.h
@@ -88,7 +88,7 @@
* "dst" becomes \xE3\x81\x82\xE3\x81\x84
* (note that "dst" is NOT null-terminated, like strncpy)
*/
-void utf32_to_utf8(const char32_t* src, size_t src_len, char* dst);
+void utf32_to_utf8(const char32_t* src, size_t src_len, char* dst, size_t dst_len);
/**
* Returns the unicode value at "index".
@@ -110,7 +110,7 @@
* enough to fit the UTF-16 as measured by utf16_to_utf8_length with an added
* NULL terminator.
*/
-void utf16_to_utf8(const char16_t* src, size_t src_len, char* dst);
+void utf16_to_utf8(const char16_t* src, size_t src_len, char* dst, size_t dst_len);
/**
* Returns the length of "src" when "src" is valid UTF-8 string.
diff --git a/init/Android.mk b/init/Android.mk
index 4827fa3..67541b8 100644
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -83,7 +83,7 @@
LOCAL_STATIC_LIBRARIES := \
libinit \
- libbootloader_message_writer \
+ libbootloader_message \
libfs_mgr \
libfec \
libfec_rs \
diff --git a/init/builtins.cpp b/init/builtins.cpp
index f3f04c2..5631877 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -46,7 +46,7 @@
#include <android-base/file.h>
#include <android-base/parseint.h>
#include <android-base/stringprintf.h>
-#include <bootloader_message_writer.h>
+#include <bootloader_message/bootloader_message.h>
#include <cutils/partition_utils.h>
#include <cutils/android_reboot.h>
#include <logwrap/logwrap.h>
@@ -345,6 +345,11 @@
return 0;
}
+/* umount <path> */
+static int do_umount(const std::vector<std::string>& args) {
+ return umount(args[1].c_str());
+}
+
static struct {
const char *name;
unsigned flag;
@@ -958,6 +963,7 @@
{"mkdir", {1, 4, do_mkdir}},
{"mount_all", {1, kMax, do_mount_all}},
{"mount", {3, kMax, do_mount}},
+ {"umount", {1, 1, do_umount}},
{"powerctl", {1, 1, do_powerctl}},
{"restart", {1, 1, do_restart}},
{"restorecon", {1, kMax, do_restorecon}},
diff --git a/init/readme.txt b/init/readme.txt
index ef85ccf..4481e24 100644
--- a/init/readme.txt
+++ b/init/readme.txt
@@ -355,6 +355,9 @@
Trigger an event. Used to queue an action from another
action.
+umount <path>
+ Unmount the filesystem mounted at that path.
+
verity_load_state
Internal implementation detail used to load dm-verity state.
diff --git a/init/service.cpp b/init/service.cpp
index f1ffa18..3149f8e 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -460,13 +460,21 @@
}
}
+ std::vector<std::string> expanded_args;
std::vector<char*> strs;
- for (const auto& s : args_) {
- strs.push_back(const_cast<char*>(s.c_str()));
+ expanded_args.resize(args_.size());
+ strs.push_back(const_cast<char*>(args_[0].c_str()));
+ for (std::size_t i = 1; i < args_.size(); ++i) {
+ if (!expand_props(args_[i], &expanded_args[i])) {
+ ERROR("%s: cannot expand '%s'\n", args_[0].c_str(), args_[i].c_str());
+ _exit(127);
+ }
+ strs.push_back(const_cast<char*>(expanded_args[i].c_str()));
}
strs.push_back(nullptr);
- if (execve(args_[0].c_str(), (char**) &strs[0], (char**) ENV) < 0) {
- ERROR("cannot execve('%s'): %s\n", args_[0].c_str(), strerror(errno));
+
+ if (execve(strs[0], (char**) &strs[0], (char**) ENV) < 0) {
+ ERROR("cannot execve('%s'): %s\n", strs[0], strerror(errno));
}
_exit(127);
diff --git a/init/util.cpp b/init/util.cpp
index 84b4155..683f6d8 100644
--- a/init/util.cpp
+++ b/init/util.cpp
@@ -504,6 +504,7 @@
* - will accept $$ as a literal $.
* - no nested property expansion, i.e. ${foo.${bar}} is not supported,
* bad things will happen
+ * - ${x.y:-default} will return default value if property empty.
*/
while (*src_ptr) {
const char* c;
@@ -526,6 +527,7 @@
}
std::string prop_name;
+ std::string def_val;
if (*c == '{') {
c++;
const char* end = strchr(c, '}');
@@ -536,6 +538,11 @@
}
prop_name = std::string(c, end);
c = end + 1;
+ size_t def = prop_name.find(":-");
+ if (def < prop_name.size()) {
+ def_val = prop_name.substr(def + 2);
+ prop_name = prop_name.substr(0, def);
+ }
} else {
prop_name = c;
ERROR("using deprecated syntax for specifying property '%s', use ${name} instead\n",
@@ -550,9 +557,12 @@
std::string prop_val = property_get(prop_name.c_str());
if (prop_val.empty()) {
- ERROR("property '%s' doesn't exist while expanding '%s'\n",
- prop_name.c_str(), src.c_str());
- return false;
+ if (def_val.empty()) {
+ ERROR("property '%s' doesn't exist while expanding '%s'\n",
+ prop_name.c_str(), src.c_str());
+ return false;
+ }
+ prop_val = def_val;
}
dst->append(prop_val);
diff --git a/libcutils/fs_config.c b/libcutils/fs_config.c
index 840ac86..08db7dc 100644
--- a/libcutils/fs_config.c
+++ b/libcutils/fs_config.c
@@ -142,6 +142,9 @@
{ 00750, AID_ROOT, AID_SHELL, CAP_MASK_LONG(CAP_SETUID) | CAP_MASK_LONG(CAP_SETGID), "system/bin/run-as" },
{ 00700, AID_SYSTEM, AID_SHELL, CAP_MASK_LONG(CAP_BLOCK_SUSPEND), "system/bin/inputflinger" },
+ /* Support FIFO scheduling mode in SurfaceFlinger. */
+ { 00755, AID_SYSTEM, AID_GRAPHICS, CAP_MASK_LONG(CAP_SYS_NICE), "system/bin/surfaceflinger" },
+
{ 00750, AID_ROOT, AID_ROOT, 0, "system/bin/uncrypt" },
{ 00750, AID_ROOT, AID_ROOT, 0, "system/bin/install-recovery.sh" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" },
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index 2b21efe..05a2048 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -66,9 +66,12 @@
static int bg_cpuset_fd = -1;
static int fg_cpuset_fd = -1;
static int ta_cpuset_fd = -1; // special cpuset for top app
+#endif
+
+// File descriptors open to /dev/stune/../tasks, setup by initialize, or -1 on error
static int bg_schedboost_fd = -1;
static int fg_schedboost_fd = -1;
-#endif
+static int ta_schedboost_fd = -1;
/* Add tid to the scheduling group defined by the policy */
static int add_tid_to_cgroup(int tid, int fd)
@@ -138,9 +141,11 @@
ta_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
#ifdef USE_SCHEDBOOST
+ filename = "/dev/stune/top-app/tasks";
+ ta_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC);
filename = "/dev/stune/foreground/tasks";
fg_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC);
- filename = "/dev/stune/tasks";
+ filename = "/dev/stune/background/tasks";
bg_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC);
#endif
}
@@ -294,15 +299,14 @@
case SP_AUDIO_APP:
case SP_AUDIO_SYS:
fd = fg_cpuset_fd;
- boost_fd = bg_schedboost_fd;
+ boost_fd = fg_schedboost_fd;
break;
case SP_TOP_APP :
fd = ta_cpuset_fd;
- boost_fd = fg_schedboost_fd;
+ boost_fd = ta_schedboost_fd;
break;
case SP_SYSTEM:
fd = system_bg_cpuset_fd;
- boost_fd = bg_schedboost_fd;
break;
default:
boost_fd = fd = -1;
@@ -314,10 +318,12 @@
return -errno;
}
+#ifdef USE_SCHEDBOOST
if (boost_fd > 0 && add_tid_to_cgroup(tid, boost_fd) != 0) {
if (errno != ESRCH && errno != ENOENT)
return -errno;
}
+#endif
return 0;
#endif
@@ -374,19 +380,26 @@
#endif
if (__sys_supports_schedgroups) {
- int fd;
+ int fd = -1;
+ int boost_fd = -1;
switch (policy) {
case SP_BACKGROUND:
fd = bg_cgroup_fd;
+ boost_fd = bg_schedboost_fd;
break;
case SP_FOREGROUND:
case SP_AUDIO_APP:
case SP_AUDIO_SYS:
+ fd = fg_cgroup_fd;
+ boost_fd = fg_schedboost_fd;
+ break;
case SP_TOP_APP:
fd = fg_cgroup_fd;
+ boost_fd = ta_schedboost_fd;
break;
default:
fd = -1;
+ boost_fd = -1;
break;
}
@@ -395,6 +408,13 @@
if (errno != ESRCH && errno != ENOENT)
return -errno;
}
+
+#ifdef USE_SCHEDBOOST
+ if (boost_fd > 0 && add_tid_to_cgroup(tid, boost_fd) != 0) {
+ if (errno != ESRCH && errno != ENOENT)
+ return -errno;
+ }
+#endif
} else {
struct sched_param param;
diff --git a/liblog/logger.h b/liblog/logger.h
index c727f29..0964756 100644
--- a/liblog/logger.h
+++ b/liblog/logger.h
@@ -146,11 +146,13 @@
/* OS specific dribs and drabs */
#if defined(_WIN32)
+#include <private/android_filesystem_config.h>
typedef uint32_t uid_t;
+static inline uid_t __android_log_uid() { return AID_SYSTEM; }
+#else
+static inline uid_t __android_log_uid() { return getuid(); }
#endif
-LIBLOG_HIDDEN uid_t __android_log_uid();
-LIBLOG_HIDDEN pid_t __android_log_pid();
LIBLOG_HIDDEN void __android_log_lock();
LIBLOG_HIDDEN int __android_log_trylock();
LIBLOG_HIDDEN void __android_log_unlock();
diff --git a/liblog/logger_lock.c b/liblog/logger_lock.c
index ee979bd..14feee0 100644
--- a/liblog/logger_lock.c
+++ b/liblog/logger_lock.c
@@ -22,34 +22,8 @@
#include <pthread.h>
#endif
-#include <private/android_filesystem_config.h>
-
#include "logger.h"
-LIBLOG_HIDDEN uid_t __android_log_uid()
-{
-#if defined(_WIN32)
- return AID_SYSTEM;
-#else
- static uid_t last_uid = AID_ROOT; /* logd *always* starts up as AID_ROOT */
-
- if (last_uid == AID_ROOT) { /* have we called to get the UID yet? */
- last_uid = getuid();
- }
- return last_uid;
-#endif
-}
-
-LIBLOG_HIDDEN pid_t __android_log_pid()
-{
- static pid_t last_pid = (pid_t) -1;
-
- if (last_pid == (pid_t) -1) {
- last_pid = getpid();
- }
- return last_pid;
-}
-
#if !defined(_WIN32)
static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
diff --git a/liblog/pmsg_writer.c b/liblog/pmsg_writer.c
index 2ba31fa..944feba 100644
--- a/liblog/pmsg_writer.c
+++ b/liblog/pmsg_writer.c
@@ -142,7 +142,7 @@
pmsgHeader.magic = LOGGER_MAGIC;
pmsgHeader.len = sizeof(pmsgHeader) + sizeof(header);
pmsgHeader.uid = __android_log_uid();
- pmsgHeader.pid = __android_log_pid();
+ pmsgHeader.pid = getpid();
header.id = logId;
header.tid = gettid();
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp
index 6484743..e35ed60 100644
--- a/libnativeloader/native_loader.cpp
+++ b/libnativeloader/native_loader.cpp
@@ -127,9 +127,10 @@
std::string public_native_libraries_system_config =
root_dir + kPublicNativeLibrariesSystemConfigPathFromRoot;
- LOG_ALWAYS_FATAL_IF(!ReadConfig(public_native_libraries_system_config, &sonames),
+ std::string error_msg;
+ LOG_ALWAYS_FATAL_IF(!ReadConfig(public_native_libraries_system_config, &sonames, &error_msg),
"Error reading public native library list from \"%s\": %s",
- public_native_libraries_system_config.c_str(), strerror(errno));
+ public_native_libraries_system_config.c_str(), error_msg.c_str());
// For debuggable platform builds use ANDROID_ADDITIONAL_PUBLIC_LIBRARIES environment
// variable to add libraries to the list. This is intended for platform tests only.
@@ -166,20 +167,42 @@
}
private:
- bool ReadConfig(const std::string& configFile, std::vector<std::string>* sonames) {
+ bool ReadConfig(const std::string& configFile, std::vector<std::string>* sonames,
+ std::string* error_msg = nullptr) {
// Read list of public native libraries from the config file.
std::string file_content;
if(!base::ReadFileToString(configFile, &file_content)) {
+ if (error_msg) *error_msg = strerror(errno);
return false;
}
std::vector<std::string> lines = base::Split(file_content, "\n");
- for (const auto& line : lines) {
+ for (auto& line : lines) {
auto trimmed_line = base::Trim(line);
if (trimmed_line[0] == '#' || trimmed_line.empty()) {
continue;
}
+ size_t space_pos = trimmed_line.rfind(' ');
+ if (space_pos != std::string::npos) {
+ std::string type = trimmed_line.substr(space_pos + 1);
+ if (type != "32" && type != "64") {
+ if (error_msg) *error_msg = "Malformed line: " + line;
+ return false;
+ }
+#if defined(__LP64__)
+ // Skip 32 bit public library.
+ if (type == "32") {
+ continue;
+ }
+#else
+ // Skip 64 bit public library.
+ if (type == "64") {
+ continue;
+ }
+#endif
+ trimmed_line.resize(space_pos);
+ }
sonames->push_back(trimmed_line);
}
diff --git a/libutils/String8.cpp b/libutils/String8.cpp
index 771d312..755e0d1 100644
--- a/libutils/String8.cpp
+++ b/libutils/String8.cpp
@@ -104,20 +104,21 @@
{
if (len == 0) return getEmptyString();
- const ssize_t bytes = utf16_to_utf8_length(in, len);
- if (bytes < 0) {
+ // Allow for closing '\0'
+ const ssize_t resultStrLen = utf16_to_utf8_length(in, len) + 1;
+ if (resultStrLen < 1) {
return getEmptyString();
}
- SharedBuffer* buf = SharedBuffer::alloc(bytes+1);
+ SharedBuffer* buf = SharedBuffer::alloc(resultStrLen);
ALOG_ASSERT(buf, "Unable to allocate shared buffer");
if (!buf) {
return getEmptyString();
}
- char* str = (char*)buf->data();
- utf16_to_utf8(in, len, str);
- return str;
+ char* resultStr = (char*)buf->data();
+ utf16_to_utf8(in, len, resultStr, resultStrLen);
+ return resultStr;
}
static char* allocFromUTF32(const char32_t* in, size_t len)
@@ -126,21 +127,21 @@
return getEmptyString();
}
- const ssize_t bytes = utf32_to_utf8_length(in, len);
- if (bytes < 0) {
+ const ssize_t resultStrLen = utf32_to_utf8_length(in, len) + 1;
+ if (resultStrLen < 1) {
return getEmptyString();
}
- SharedBuffer* buf = SharedBuffer::alloc(bytes+1);
+ SharedBuffer* buf = SharedBuffer::alloc(resultStrLen);
ALOG_ASSERT(buf, "Unable to allocate shared buffer");
if (!buf) {
return getEmptyString();
}
- char* str = (char*) buf->data();
- utf32_to_utf8(in, len, str);
+ char* resultStr = (char*) buf->data();
+ utf32_to_utf8(in, len, resultStr, resultStrLen);
- return str;
+ return resultStr;
}
// ---------------------------------------------------------------------------
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp
index f1f8bc9..ba084f6 100644
--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <log/log.h>
#include <utils/Unicode.h>
#include <stddef.h>
@@ -182,7 +183,7 @@
return ret;
}
-void utf32_to_utf8(const char32_t* src, size_t src_len, char* dst)
+void utf32_to_utf8(const char32_t* src, size_t src_len, char* dst, size_t dst_len)
{
if (src == NULL || src_len == 0 || dst == NULL) {
return;
@@ -193,9 +194,12 @@
char *cur = dst;
while (cur_utf32 < end_utf32) {
size_t len = utf32_codepoint_utf8_length(*cur_utf32);
+ LOG_ALWAYS_FATAL_IF(dst_len < len, "%zu < %zu", dst_len, len);
utf32_codepoint_to_utf8((uint8_t *)cur, *cur_utf32++, len);
cur += len;
+ dst_len -= len;
}
+ LOG_ALWAYS_FATAL_IF(dst_len < 1, "dst_len < 1: %zu < 1", dst_len);
*cur = '\0';
}
@@ -348,7 +352,7 @@
: 0);
}
-void utf16_to_utf8(const char16_t* src, size_t src_len, char* dst)
+void utf16_to_utf8(const char16_t* src, size_t src_len, char* dst, size_t dst_len)
{
if (src == NULL || src_len == 0 || dst == NULL) {
return;
@@ -369,9 +373,12 @@
utf32 = (char32_t) *cur_utf16++;
}
const size_t len = utf32_codepoint_utf8_length(utf32);
+ LOG_ALWAYS_FATAL_IF(dst_len < len, "%zu < %zu", dst_len, len);
utf32_codepoint_to_utf8((uint8_t*)cur, utf32, len);
cur += len;
+ dst_len -= len;
}
+ LOG_ALWAYS_FATAL_IF(dst_len < 1, "%zu < 1", dst_len);
*cur = '\0';
}
@@ -432,10 +439,10 @@
const char16_t* const end = src + src_len;
while (src < end) {
if ((*src & 0xFC00) == 0xD800 && (src + 1) < end
- && (*++src & 0xFC00) == 0xDC00) {
+ && (*(src + 1) & 0xFC00) == 0xDC00) {
// surrogate pairs are always 4 bytes.
ret += 4;
- src++;
+ src += 2;
} else {
ret += utf32_codepoint_utf8_length((char32_t) *src++);
}
diff --git a/libutils/tests/String8_test.cpp b/libutils/tests/String8_test.cpp
index 01e64f6..3947a5f 100644
--- a/libutils/tests/String8_test.cpp
+++ b/libutils/tests/String8_test.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "String8_test"
#include <utils/Log.h>
#include <utils/String8.h>
+#include <utils/String16.h>
#include <gtest/gtest.h>
@@ -77,4 +78,22 @@
EXPECT_EQ(NO_MEMORY, String8("").setTo(in, SIZE_MAX));
}
+// http://b/29250543
+TEST_F(String8Test, CorrectInvalidSurrogate) {
+ // d841d8 is an invalid start for a surrogate pair. Make sure this is handled by ignoring the
+ // first character in the pair and handling the rest correctly.
+ String16 string16(u"\xd841\xd841\xdc41\x0000");
+ String8 string8(string16);
+
+ EXPECT_EQ(4U, string8.length());
+}
+
+TEST_F(String8Test, CheckUtf32Conversion) {
+ // Since bound checks were added, check the conversion can be done without fatal errors.
+ // The utf8 lengths of these are chars are 1 + 2 + 3 + 4 = 10.
+ const char32_t string32[] = U"\x0000007f\x000007ff\x0000911\x0010fffe";
+ String8 string8(string32);
+ EXPECT_EQ(10U, string8.length());
+}
+
}
diff --git a/logcat/logcatd.rc b/logcat/logcatd.rc
index 1fbd020..70d1dd4 100644
--- a/logcat/logcatd.rc
+++ b/logcat/logcatd.rc
@@ -2,10 +2,10 @@
# all exec/services are called with umask(077), so no gain beyond 0700
mkdir /data/misc/logd 0700 logd log
# logd for write to /data/misc/logd, log group for read from pstore (-L)
- # exec - logd log -- /system/bin/logcat -L -b all -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 1024 -n 256
+ exec - logd log -- /system/bin/logcat -L -b ${persist.logd.logpersistd.buffer:-all} -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 1024 -n ${persist.logd.logpersistd.size:-256}
start logcatd
-service logcatd /system/bin/logcat -b all -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 1024 -n 256
+service logcatd /system/bin/logcat -b ${persist.logd.logpersistd.buffer:-all} -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 1024 -n ${persist.logd.logpersistd.size:-256}
class late_start
disabled
# logd for write to /data/misc/logd, log group for read from log daemon
diff --git a/logcat/logpersist b/logcat/logpersist
index dab466d..923c5fb 100755
--- a/logcat/logpersist
+++ b/logcat/logpersist
@@ -1,5 +1,5 @@
#! /system/bin/sh
-# logpersist cat start and stop handlers
+# logpersist cat, start and stop handlers
progname="${0##*/}"
case `getprop ro.build.type` in
userdebug|eng) ;;
@@ -7,36 +7,134 @@
exit 1
;;
esac
+
data=/data/misc/logd
property=persist.logd.logpersistd
service=logcatd
-if [ X"${1}" = X"-h" -o X"${1}" = X"--help" ]; then
- echo "${progname%.*}.cat - dump current ${service%d} logs"
- echo "${progname%.*}.start - start ${service} service"
- echo "${progname%.*}.stop [--clear] - stop ${service} service"
- exit 0
+size_default=256
+buffer_default=all
+args="${@}"
+
+size=${size_default}
+buffer=${buffer_default}
+clear=false
+while [ ${#} -gt 0 ]; do
+ case ${1} in
+ -c|--clear) clear=true ;;
+ --size=*) size="${1#--size=}" ;;
+ --rotate-count=*) size="${1#--rotate-count=}" ;;
+ -n|--size|--rotate-count) size="${2}" ; shift ;;
+ --buffer=*) buffer="${1#--buffer=}" ;;
+ -b|--buffer) buffer="${2}" ; shift ;;
+ -h|--help|*)
+ LEAD_SPACE_="`echo ${progname%.*} | tr '[ -~]' ' '`"
+ echo "${progname%.*}.cat - dump current ${service%d} logs"
+ echo "${progname%.*}.start [--size=<size_in_kb>] [--buffer=<buffers>] [--clear]"
+ echo "${LEAD_SPACE_} - start ${service} service"
+ echo "${progname%.*}.stop [--clear] - stop ${service} service"
+ case ${1} in
+ -h|--help) exit 0 ;;
+ *) echo ERROR: bad argument ${@} >&2 ; exit 1 ;;
+ esac
+ ;;
+ esac
+ shift
+done
+
+if [ -z "${size}" -o "${size_default}" = "${size}" ]; then
+ unset size
fi
+if [ -n "${size}" ] &&
+ ! ( [ 0 -lt "${size}" ] && [ 2048 -ge "${size}" ] ) >/dev/null 2>&1; then
+ echo ERROR: Invalid --size ${size} >&2
+ exit 1
+fi
+if [ -z "${buffer}" -o "${buffer_default}" = "${buffer}" ]; then
+ unset buffer
+fi
+if [ -n "${buffer}" ] && ! logcat -b ${buffer} -g >/dev/null 2>&1; then
+ echo ERROR: Invalid --buffer ${buffer} >&2
+ exit 1
+fi
+
case ${progname} in
*.cat)
- su 1036 ls "${data}" |
+ if [ -n "${size}${buffer}" -o "true" = "${clear}" ]; then
+ echo WARNING: Can not use --clear, --size or --buffer with ${progname%.*}.cat >&2
+ fi
+ su logd ls "${data}" |
tr -d '\r' |
sort -ru |
sed "s#^#${data}/#" |
- su 1036 xargs cat
+ su logd xargs cat
;;
*.start)
- su 0 setprop ${property} ${service}
+ current_buffer="`getprop ${property}.buffer`"
+ current_size="`getprop ${property}.size`"
+ if [ "${service}" = "`getprop ${property}`" ]; then
+ if [ "true" = "${clear}" ]; then
+ su root stop ${service}
+ su root setprop ${property} ""
+ # 20ms done, guarantees content stop before rm
+ sleep 1
+ elif [ "${buffer}|${size}" != "${current_buffer}|${current_size}" ]; then
+ echo "ERROR: Changing existing collection parameters from" >&2
+ if [ "${buffer}" != "${current_buffer}" ]; then
+ a=${current_buffer}
+ b=${buffer}
+ if [ -z "${a}" ]; then a="${default_buffer}"; fi
+ if [ -z "${b}" ]; then b="${default_buffer}"; fi
+ echo " --buffer ${a} to ${b}" >&2
+ fi
+ if [ "${size}" != "${current_size}" ]; then
+ a=${current_size}
+ b=${size}
+ if [ -z "${a}" ]; then a="${default_size}"; fi
+ if [ -z "${b}" ]; then b="${default_size}"; fi
+ echo " --size ${a} to ${b}" >&2
+ fi
+ echo " Are you sure you want to do this?" >&2
+ echo " Suggest add --clear to erase data and restart with new settings." >&2
+ echo " To blindly override and retain data, ${progname%.*}.stop first." >&2
+ exit 1
+ fi
+ fi
+ if [ "true" = "${clear}" ]; then
+ su logd,misc rm -rf "${data}"
+ fi
+ if [ -n "${buffer}${current_buffer}" ]; then
+ su root setprop ${property}.buffer "${buffer}"
+ fi
+ if [ -n "${size}${current_size}" ]; then
+ su root setprop ${property}.size "${size}"
+ fi
+ # ${service}.rc does the heavy lifting with the following trigger
+ su root setprop ${property} ${service}
getprop ${property}
+ # 20ms done, to permit process feedback check
sleep 1
+ # also generate an error return code if not found running, bonus
ps -t | grep "${data##*/}.*${service%d}"
;;
*.stop)
- su 0 stop ${service}
- su 0 setprop ${property} ""
- [ X"${1}" != X"-c" -a X"${1}" != X"--clear" ] ||
- ( sleep 1 ; su 1036,9998 rm -rf "${data}" )
+ if [ -n "${size}${buffer}" ]; then
+ echo "WARNING: Can not use --size or --buffer with ${progname%.*}.stop" >&2
+ fi
+ su root stop ${service}
+ su root setprop ${property} ""
+ if [ -n "`getprop ${property}.buffer`" ]; then
+ su root setprop ${property}.buffer ""
+ fi
+ if [ -n "`getprop ${property}.size`" ]; then
+ su root setprop ${property}.size ""
+ fi
+ if [ "true" = "${clear}" ]; then
+ # 20ms done, guarantees content stop before rm
+ sleep 1
+ su logd,misc rm -rf "${data}"
+ fi
;;
*)
- echo "Unexpected command ${0##*/} ${@}" >&2
+ echo "ERROR: Unexpected command ${0##*/} ${args}" >&2
exit 1
esac
diff --git a/rootdir/Android.mk b/rootdir/Android.mk
index fd2b8b0..94f5cb7 100644
--- a/rootdir/Android.mk
+++ b/rootdir/Android.mk
@@ -26,6 +26,7 @@
#######################################
# asan.options
ifneq ($(filter address,$(SANITIZE_TARGET)),)
+
include $(CLEAR_VARS)
LOCAL_MODULE := asan.options
@@ -34,6 +35,72 @@
LOCAL_MODULE_PATH := $(TARGET_OUT)
include $(BUILD_PREBUILT)
+
+# Modules for asan.options.X files.
+
+ASAN_OPTIONS_FILES :=
+
+define create-asan-options-module
+include $$(CLEAR_VARS)
+LOCAL_MODULE := asan.options.$(1)
+ASAN_OPTIONS_FILES += asan.options.$(1)
+LOCAL_MODULE_CLASS := ETC
+# The asan.options.off.template tries to turn off as much of ASAN as is possible.
+LOCAL_SRC_FILES := asan.options.off.template
+LOCAL_MODULE_PATH := $(TARGET_OUT)
+include $$(BUILD_PREBUILT)
+endef
+
+# Pretty comprehensive set of native services. This list is helpful if all that's to be checked is an
+# app.
+ifeq ($(SANITIZE_LITE),true)
+SANITIZE_ASAN_OPTIONS_FOR := \
+ adbd \
+ ATFWD-daemon \
+ audioserver \
+ bridgemgrd \
+ cameraserver \
+ cnd \
+ debuggerd \
+ debuggerd64 \
+ dex2oat \
+ drmserver \
+ fingerprintd \
+ gatekeeperd \
+ installd \
+ keystore \
+ lmkd \
+ logcat \
+ logd \
+ lowi-server \
+ media.codec \
+ mediadrmserver \
+ media.extractor \
+ mediaserver \
+ mm-qcamera-daemon \
+ mpdecision \
+ netmgrd \
+ perfd \
+ perfprofd \
+ qmuxd \
+ qseecomd \
+ rild \
+ sdcard \
+ servicemanager \
+ slim_daemon \
+ surfaceflinger \
+ thermal-engine \
+ time_daemon \
+ update_engine \
+ vold \
+ wpa_supplicant \
+ zip
+endif
+
+ifneq ($(SANITIZE_ASAN_OPTIONS_FOR),)
+ $(foreach binary, $(SANITIZE_ASAN_OPTIONS_FOR), $(eval $(call create-asan-options-module,$(binary))))
+endif
+
endif
#######################################
@@ -47,7 +114,7 @@
EXPORT_GLOBAL_ASAN_OPTIONS :=
ifneq ($(filter address,$(SANITIZE_TARGET)),)
EXPORT_GLOBAL_ASAN_OPTIONS := export ASAN_OPTIONS include=/system/asan.options
- LOCAL_REQUIRED_MODULES := asan.options
+ LOCAL_REQUIRED_MODULES := asan.options $(ASAN_OPTIONS_FILES)
endif
# Put it here instead of in init.rc module definition,
# because init.rc is conditionally included.
diff --git a/rootdir/asan.options b/rootdir/asan.options
index 43896a1..70e0eca 100644
--- a/rootdir/asan.options
+++ b/rootdir/asan.options
@@ -3,3 +3,4 @@
alloc_dealloc_mismatch=0
allocator_may_return_null=1
detect_container_overflow=0
+include_if_exists=/system/asan.options.%b
diff --git a/rootdir/asan.options.off.template b/rootdir/asan.options.off.template
new file mode 100644
index 0000000..59a1249
--- /dev/null
+++ b/rootdir/asan.options.off.template
@@ -0,0 +1,7 @@
+quarantine_size_mb=0
+max_redzone=16
+poison_heap=false
+poison_partial=false
+poison_array_cookie=false
+alloc_dealloc_mismatch=false
+new_delete_type_mismatch=false
diff --git a/rootdir/init.rc b/rootdir/init.rc
index ec9f252..bf11227 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -50,12 +50,20 @@
mkdir /dev/stune
mount cgroup none /dev/stune schedtune
mkdir /dev/stune/foreground
+ mkdir /dev/stune/background
+ mkdir /dev/stune/top-app
chown system system /dev/stune
chown system system /dev/stune/foreground
+ chown system system /dev/stune/background
+ chown system system /dev/stune/top-app
chown system system /dev/stune/tasks
chown system system /dev/stune/foreground/tasks
+ chown system system /dev/stune/background/tasks
+ chown system system /dev/stune/top-app/tasks
chmod 0664 /dev/stune/tasks
chmod 0664 /dev/stune/foreground/tasks
+ chmod 0664 /dev/stune/background/tasks
+ chmod 0664 /dev/stune/top-app/tasks
# Mount staging areas for devices managed by vold
# See storage config details at http://source.android.com/tech/storage/
@@ -107,7 +115,6 @@
write /proc/sys/kernel/sched_tunable_scaling 0
write /proc/sys/kernel/sched_latency_ns 10000000
write /proc/sys/kernel/sched_wakeup_granularity_ns 2000000
- write /proc/sys/kernel/sched_compat_yield 1
write /proc/sys/kernel/sched_child_runs_first 0
write /proc/sys/kernel/randomize_va_space 2
@@ -135,17 +142,17 @@
chown system system /dev/cpuctl
chown system system /dev/cpuctl/tasks
chmod 0666 /dev/cpuctl/tasks
- write /dev/cpuctl/cpu.shares 1024
- write /dev/cpuctl/cpu.rt_runtime_us 800000
write /dev/cpuctl/cpu.rt_period_us 1000000
+ write /dev/cpuctl/cpu.rt_runtime_us 950000
mkdir /dev/cpuctl/bg_non_interactive
chown system system /dev/cpuctl/bg_non_interactive/tasks
chmod 0666 /dev/cpuctl/bg_non_interactive/tasks
# 5.0 %
write /dev/cpuctl/bg_non_interactive/cpu.shares 52
- write /dev/cpuctl/bg_non_interactive/cpu.rt_runtime_us 700000
write /dev/cpuctl/bg_non_interactive/cpu.rt_period_us 1000000
+ # active FIFO threads will never be in BG
+ write /dev/cpuctl/bg_non_interactive/cpu.rt_runtime_us 10000
# sets up initial cpusets for ActivityManager
mkdir /dev/cpuset