Merge "Include ldd in /system/bin."
diff --git a/adb/client/usb_linux.cpp b/adb/client/usb_linux.cpp
index 81b8306..17b4db1 100644
--- a/adb/client/usb_linux.cpp
+++ b/adb/client/usb_linux.cpp
@@ -324,7 +324,7 @@
h->urb_out_busy = true;
while (true) {
- auto now = std::chrono::system_clock::now();
+ auto now = std::chrono::steady_clock::now();
if (h->cv.wait_until(lock, now + 5s) == std::cv_status::timeout || h->dead) {
// TODO: call USBDEVFS_DISCARDURB?
errno = ETIMEDOUT;
diff --git a/base/include/android-base/unique_fd.h b/base/include/android-base/unique_fd.h
index a39245b..6e11b4e 100644
--- a/base/include/android-base/unique_fd.h
+++ b/base/include/android-base/unique_fd.h
@@ -92,6 +92,8 @@
explicit unique_fd_impl(int fd) { reset(fd); }
~unique_fd_impl() { reset(); }
+ unique_fd_impl(const unique_fd_impl&) = delete;
+ void operator=(const unique_fd_impl&) = delete;
unique_fd_impl(unique_fd_impl&& other) noexcept { reset(other.release()); }
unique_fd_impl& operator=(unique_fd_impl&& s) noexcept {
int fd = s.fd_;
@@ -118,6 +120,8 @@
// Catch bogus error checks (i.e.: "!fd" instead of "fd != -1").
bool operator!() const = delete;
+ bool ok() const { return get() != -1; }
+
int release() __attribute__((warn_unused_result)) {
tag(fd_, this, nullptr);
int ret = fd_;
@@ -167,9 +171,6 @@
static auto close(int fd, void*) -> decltype(T::Close(fd), void()) {
T::Close(fd);
}
-
- unique_fd_impl(const unique_fd_impl&);
- void operator=(const unique_fd_impl&);
};
using unique_fd = unique_fd_impl<DefaultCloser>;
diff --git a/fs_mgr/README.overlayfs.md b/fs_mgr/README.overlayfs.md
index d204bfd..fe2e052 100644
--- a/fs_mgr/README.overlayfs.md
+++ b/fs_mgr/README.overlayfs.md
@@ -95,8 +95,8 @@
- Kernel must have CONFIG_OVERLAY_FS=y and will need to be patched
with "*overlayfs: override_creds=off option bypass creator_cred*"
if kernel is 4.4 or higher.
- The patch is available on the upstream mailing list and the latest as of
- Feb 8 2019 is https://lore.kernel.org/patchwork/patch/1009299/.
+ The patch series is available on the upstream mailing list and the latest as
+ of Jul 24 2019 is https://lore.kernel.org/patchwork/patch/1104577/.
This patch adds an override_creds _mount_ option to overlayfs that
permits legacy behavior for systems that do not have overlapping
sepolicy rules, principals of least privilege, which is how Android behaves.
diff --git a/fs_mgr/liblp/builder.cpp b/fs_mgr/liblp/builder.cpp
index 25a042f..c12e3b2 100644
--- a/fs_mgr/liblp/builder.cpp
+++ b/fs_mgr/liblp/builder.cpp
@@ -30,8 +30,8 @@
namespace android {
namespace fs_mgr {
-bool MetadataBuilder::sABOverrideSet;
-bool MetadataBuilder::sABOverrideValue;
+std::optional<bool> MetadataBuilder::sABOverride;
+std::optional<bool> MetadataBuilder::sRetrofitDap;
static const std::string kDefaultGroup = "default";
@@ -169,7 +169,8 @@
// needed. On the other hand, for retrofit devices, we'll need to
// translate block device and group names to update their slot suffixes.
auto super_device = GetMetadataSuperBlockDevice(*metadata.get());
- if (GetBlockDevicePartitionName(*super_device) == "super") {
+ if (GetBlockDevicePartitionName(*super_device) == "super" ||
+ !IsRetrofitDynamicPartitionsDevice()) {
return New(*metadata.get(), &opener);
}
@@ -210,8 +211,11 @@
}
void MetadataBuilder::OverrideABForTesting(bool ab_device) {
- sABOverrideSet = true;
- sABOverrideValue = ab_device;
+ sABOverride = ab_device;
+}
+
+void MetadataBuilder::OverrideRetrofitDynamicParititonsForTesting(bool retrofit) {
+ sRetrofitDap = retrofit;
}
MetadataBuilder::MetadataBuilder() : auto_slot_suffixing_(false) {
@@ -580,7 +584,8 @@
CHECK_NE(sectors_per_block, 0);
CHECK(sectors_needed % sectors_per_block == 0);
- if (IsABDevice() && !IsRetrofitDevice() && GetPartitionSlotSuffix(partition->name()) == "_b") {
+ if (IsABDevice() && !IsRetrofitMetadata() &&
+ GetPartitionSlotSuffix(partition->name()) == "_b") {
// Allocate "a" partitions top-down and "b" partitions bottom-up, to
// minimize fragmentation during OTA.
free_regions = PrioritizeSecondHalfOfSuper(free_regions);
@@ -1044,14 +1049,21 @@
auto_slot_suffixing_ = true;
}
-bool MetadataBuilder::IsABDevice() const {
- if (sABOverrideSet) {
- return sABOverrideValue;
+bool MetadataBuilder::IsABDevice() {
+ if (sABOverride.has_value()) {
+ return *sABOverride;
}
return !android::base::GetProperty("ro.boot.slot_suffix", "").empty();
}
-bool MetadataBuilder::IsRetrofitDevice() const {
+bool MetadataBuilder::IsRetrofitDynamicPartitionsDevice() {
+ if (sRetrofitDap.has_value()) {
+ return *sRetrofitDap;
+ }
+ return !android::base::GetBoolProperty("ro.boot.dynamic_partitions_retrofit", false);
+}
+
+bool MetadataBuilder::IsRetrofitMetadata() const {
return GetBlockDevicePartitionName(block_devices_[0]) != LP_METADATA_DEFAULT_PARTITION_NAME;
}
diff --git a/fs_mgr/liblp/builder_test.cpp b/fs_mgr/liblp/builder_test.cpp
index 34c68d4..377ec68 100644
--- a/fs_mgr/liblp/builder_test.cpp
+++ b/fs_mgr/liblp/builder_test.cpp
@@ -27,20 +27,28 @@
class Environment : public ::testing::Environment {
public:
- void SetUp() override { MetadataBuilder::OverrideABForTesting(false); }
+ void SetUp() override {
+ MetadataBuilder::OverrideABForTesting(false);
+ MetadataBuilder::OverrideRetrofitDynamicParititonsForTesting(false);
+ }
};
int main(int argc, char** argv) {
- std::unique_ptr<Environment> env(new Environment);
- ::testing::AddGlobalTestEnvironment(env.get());
+ ::testing::AddGlobalTestEnvironment(new Environment);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
class BuilderTest : public ::testing::Test {
public:
- void SetUp() override { MetadataBuilder::OverrideABForTesting(false); }
- void TearDown() override { MetadataBuilder::OverrideABForTesting(false); }
+ void SetUp() override {
+ MetadataBuilder::OverrideABForTesting(false);
+ MetadataBuilder::OverrideRetrofitDynamicParititonsForTesting(false);
+ }
+ void TearDown() override {
+ MetadataBuilder::OverrideABForTesting(false);
+ MetadataBuilder::OverrideRetrofitDynamicParititonsForTesting(false);
+ }
};
TEST_F(BuilderTest, BuildBasic) {
diff --git a/fs_mgr/liblp/include/liblp/builder.h b/fs_mgr/liblp/include/liblp/builder.h
index e70c552..a2221ef 100644
--- a/fs_mgr/liblp/include/liblp/builder.h
+++ b/fs_mgr/liblp/include/liblp/builder.h
@@ -199,6 +199,9 @@
// Used by the test harness to override whether the device is "A/B".
static void OverrideABForTesting(bool ab_device);
+ // Used by the test harness to override whether the device is "retrofitting dynamic partitions".
+ static void OverrideRetrofitDynamicParititonsForTesting(bool retrofit);
+
// Define a new partition group. By default there is one group called
// "default", with an unrestricted size. A non-zero size will restrict the
// total space used by all partitions in the group.
@@ -306,8 +309,16 @@
void ImportExtents(Partition* dest, const LpMetadata& metadata,
const LpMetadataPartition& source);
bool ImportPartition(const LpMetadata& metadata, const LpMetadataPartition& source);
- bool IsABDevice() const;
- bool IsRetrofitDevice() const;
+
+ // Return true if the device is an AB device.
+ static bool IsABDevice();
+
+ // Return true if the device is retrofitting dynamic partitions.
+ static bool IsRetrofitDynamicPartitionsDevice();
+
+ // Return true if "this" metadata represents a metadata on a retrofit device.
+ bool IsRetrofitMetadata() const;
+
bool ValidatePartitionGroups() const;
struct Interval {
@@ -336,8 +347,8 @@
const std::vector<Interval>& free_list,
uint64_t sectors_needed) const;
- static bool sABOverrideValue;
- static bool sABOverrideSet;
+ static std::optional<bool> sABOverride;
+ static std::optional<bool> sRetrofitDap;
LpMetadataGeometry geometry_;
LpMetadataHeader header_;
diff --git a/fs_mgr/liblp/io_test.cpp b/fs_mgr/liblp/io_test.cpp
index fcef1f0..70dd85f 100644
--- a/fs_mgr/liblp/io_test.cpp
+++ b/fs_mgr/liblp/io_test.cpp
@@ -664,6 +664,8 @@
}
TEST(liblp, UpdateRetrofit) {
+ MetadataBuilder::OverrideRetrofitDynamicParititonsForTesting(true);
+
unique_ptr<MetadataBuilder> builder = CreateDefaultBuilder();
ASSERT_NE(builder, nullptr);
ASSERT_TRUE(AddDefaultPartitions(builder.get()));
@@ -693,6 +695,8 @@
}
TEST(liblp, UpdateNonRetrofit) {
+ MetadataBuilder::OverrideRetrofitDynamicParititonsForTesting(false);
+
unique_fd fd = CreateFlashedDisk();
ASSERT_GE(fd, 0);
diff --git a/healthd/Android.bp b/healthd/Android.bp
index 2cf6be9..53be526 100644
--- a/healthd/Android.bp
+++ b/healthd/Android.bp
@@ -110,3 +110,55 @@
"libutils",
],
}
+
+sysprop_library {
+ name: "charger_sysprop",
+ srcs: ["charger.sysprop"],
+ property_owner: "Platform",
+ api_packages: ["android.sysprop"],
+}
+
+cc_library_static {
+ name: "libhealthd_draw",
+ export_include_dirs: ["."],
+ static_libs: [
+ "libcharger_sysprop",
+ "libminui",
+ ],
+ shared_libs: [
+ "libbase",
+ ],
+ header_libs: ["libbatteryservice_headers"],
+
+ srcs: ["healthd_draw.cpp"],
+}
+
+cc_library_static {
+ name: "libhealthd_charger",
+ local_include_dirs: ["include"],
+ export_include_dirs: [".", "include"],
+
+ static_libs: [
+ "android.hardware.health@2.0-impl",
+ "android.hardware.health@1.0-convert",
+ "libcharger_sysprop",
+ "libhealthstoragedefault",
+ "libhealthd_draw",
+ "libminui",
+ ],
+
+ shared_libs: [
+ "android.hardware.health@2.0",
+ "libbase",
+ "libcutils",
+ "liblog",
+ "libpng",
+ "libsuspend",
+ "libutils",
+ ],
+
+ srcs: [
+ "healthd_mode_charger.cpp",
+ "AnimationParser.cpp",
+ ],
+}
diff --git a/healthd/Android.mk b/healthd/Android.mk
index d18f15a..b87f3c7 100644
--- a/healthd/Android.mk
+++ b/healthd/Android.mk
@@ -2,74 +2,6 @@
LOCAL_PATH := $(call my-dir)
-### libhealthd_draw ###
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libhealthd_draw
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-LOCAL_STATIC_LIBRARIES := libminui
-LOCAL_SHARED_LIBRARIES := libbase
-LOCAL_SRC_FILES := healthd_draw.cpp
-
-ifneq ($(TARGET_HEALTHD_DRAW_SPLIT_SCREEN),)
-LOCAL_CFLAGS += -DHEALTHD_DRAW_SPLIT_SCREEN=$(TARGET_HEALTHD_DRAW_SPLIT_SCREEN)
-else
-LOCAL_CFLAGS += -DHEALTHD_DRAW_SPLIT_SCREEN=0
-endif
-
-ifneq ($(TARGET_HEALTHD_DRAW_SPLIT_OFFSET),)
-LOCAL_CFLAGS += -DHEALTHD_DRAW_SPLIT_OFFSET=$(TARGET_HEALTHD_DRAW_SPLIT_OFFSET)
-else
-LOCAL_CFLAGS += -DHEALTHD_DRAW_SPLIT_OFFSET=0
-endif
-
-LOCAL_HEADER_LIBRARIES := libbatteryservice_headers
-
-include $(BUILD_STATIC_LIBRARY)
-
-### libhealthd_charger ###
-include $(CLEAR_VARS)
-
-LOCAL_CFLAGS := -Werror
-ifeq ($(strip $(BOARD_CHARGER_DISABLE_INIT_BLANK)),true)
-LOCAL_CFLAGS += -DCHARGER_DISABLE_INIT_BLANK
-endif
-ifeq ($(strip $(BOARD_CHARGER_ENABLE_SUSPEND)),true)
-LOCAL_CFLAGS += -DCHARGER_ENABLE_SUSPEND
-endif
-
-LOCAL_SRC_FILES := \
- healthd_mode_charger.cpp \
- AnimationParser.cpp
-
-LOCAL_MODULE := libhealthd_charger
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
-LOCAL_EXPORT_C_INCLUDE_DIRS := \
- $(LOCAL_PATH) \
- $(LOCAL_PATH)/include
-
-LOCAL_STATIC_LIBRARIES := \
- android.hardware.health@2.0-impl \
- android.hardware.health@1.0-convert \
- libhealthstoragedefault \
- libhealthd_draw \
- libminui \
-
-LOCAL_SHARED_LIBRARIES := \
- android.hardware.health@2.0 \
- libbase \
- libcutils \
- liblog \
- libpng \
- libutils \
-
-ifeq ($(strip $(BOARD_CHARGER_ENABLE_SUSPEND)),true)
-LOCAL_SHARED_LIBRARIES += libsuspend
-endif
-
-include $(BUILD_STATIC_LIBRARY)
-
### charger ###
include $(CLEAR_VARS)
ifeq ($(strip $(BOARD_CHARGER_NO_UI)),true)
@@ -83,18 +15,17 @@
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_CFLAGS := -Werror
-ifeq ($(strip $(LOCAL_CHARGER_NO_UI)),true)
-LOCAL_CFLAGS += -DCHARGER_NO_UI
-endif
CHARGER_STATIC_LIBRARIES := \
android.hardware.health@2.0-impl \
android.hardware.health@1.0-convert \
libbinderthreadstate \
+ libcharger_sysprop \
libhidltransport \
libhidlbase \
libhwbinder_noltopgo \
libhealthstoragedefault \
+ libminui \
libvndksupport \
libhealthd_charger \
libhealthd_charger_nops \
@@ -106,18 +37,12 @@
libbase \
libcutils \
libjsoncpp \
+ libpng \
libprocessgroup \
liblog \
libutils \
-ifneq ($(strip $(LOCAL_CHARGER_NO_UI)),true)
-CHARGER_STATIC_LIBRARIES += libminui
-CHARGER_SHARED_LIBRARIES += libpng
-endif
-
-ifeq ($(strip $(BOARD_CHARGER_ENABLE_SUSPEND)),true)
CHARGER_SHARED_LIBRARIES += libsuspend
-endif
LOCAL_STATIC_LIBRARIES := $(CHARGER_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES := $(CHARGER_SHARED_LIBRARIES)
@@ -141,8 +66,7 @@
LOCAL_MODULE_STEM := charger
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_CFLAGS += -DCHARGER_NO_UI
+LOCAL_CFLAGS := -Wall -Werror -DCHARGER_FORCE_NO_UI=1
# charger.recovery doesn't link against libhealthd_{charger,draw} or libminui, since it doesn't need
# any UI support.
@@ -150,6 +74,7 @@
android.hardware.health@2.0-impl \
android.hardware.health@1.0-convert \
libbinderthreadstate \
+ libcharger_sysprop \
libhidltransport \
libhidlbase \
libhwbinder_noltopgo \
@@ -176,7 +101,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := charger_test
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
-LOCAL_CFLAGS := -Wall -Werror -DCHARGER_NO_UI
+LOCAL_CFLAGS := -Wall -Werror
LOCAL_STATIC_LIBRARIES := $(CHARGER_STATIC_LIBRARIES)
LOCAL_SHARED_LIBRARIES := $(CHARGER_SHARED_LIBRARIES)
LOCAL_SRC_FILES := \
diff --git a/healthd/AnimationParser.cpp b/healthd/AnimationParser.cpp
index 864038b..fde3b95 100644
--- a/healthd/AnimationParser.cpp
+++ b/healthd/AnimationParser.cpp
@@ -84,7 +84,6 @@
static constexpr const char* fail_prefix = "fail: ";
static constexpr const char* clock_prefix = "clock_display: ";
static constexpr const char* percent_prefix = "percent_display: ";
- static constexpr const char* frame_prefix = "frame: ";
std::vector<animation::frame> frames;
diff --git a/healthd/api/current.txt b/healthd/api/current.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/healthd/api/current.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/healthd/api/removed.txt b/healthd/api/removed.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/healthd/api/removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/healthd/api/system-current.txt b/healthd/api/system-current.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/healthd/api/system-current.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/healthd/api/system-removed.txt b/healthd/api/system-removed.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/healthd/api/system-removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/healthd/api/test-current.txt b/healthd/api/test-current.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/healthd/api/test-current.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/healthd/api/test-removed.txt b/healthd/api/test-removed.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/healthd/api/test-removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/healthd/charger.cpp b/healthd/charger.cpp
index 085cceb..58ed416 100644
--- a/healthd/charger.cpp
+++ b/healthd/charger.cpp
@@ -14,13 +14,18 @@
* limitations under the License.
*/
+#include "charger.sysprop.h"
#include "healthd_mode_charger.h"
#include "healthd_mode_charger_nops.h"
-int main(int argc, char** argv) {
-#ifdef CHARGER_NO_UI
- return healthd_charger_nops(argc, argv);
-#else
- return healthd_charger_main(argc, argv);
+#ifndef CHARGER_FORCE_NO_UI
+#define CHARGER_FORCE_NO_UI 0
#endif
+
+int main(int argc, char** argv) {
+ if (CHARGER_FORCE_NO_UI || android::sysprop::ChargerProperties::no_ui().value_or(false)) {
+ return healthd_charger_nops(argc, argv);
+ } else {
+ return healthd_charger_main(argc, argv);
+ }
}
diff --git a/healthd/charger.sysprop b/healthd/charger.sysprop
new file mode 100644
index 0000000..b3f47a1
--- /dev/null
+++ b/healthd/charger.sysprop
@@ -0,0 +1,38 @@
+owner: Platform
+module: "android.sysprop.ChargerProperties"
+
+prop {
+ api_name: "draw_split_screen"
+ type: Boolean
+ prop_name: "ro.charger.draw_split_screen"
+ scope: Internal
+ access: Readonly
+}
+prop {
+ api_name: "draw_split_offset"
+ type: Long
+ prop_name: "ro.charger.draw_split_offset"
+ scope: Internal
+ access: Readonly
+}
+prop {
+ api_name: "disable_init_blank"
+ type: Boolean
+ prop_name: "ro.charger.disable_init_blank"
+ scope: Internal
+ access: Readonly
+}
+prop {
+ api_name: "enable_suspend"
+ type: Boolean
+ prop_name: "ro.charger.enable_suspend"
+ scope: Internal
+ access: Readonly
+}
+prop {
+ api_name: "no_ui"
+ type: Boolean
+ prop_name: "ro.charger.no_ui"
+ scope: Internal
+ access: Readonly
+}
diff --git a/healthd/healthd_draw.cpp b/healthd/healthd_draw.cpp
index 3da8bda..50eee19 100644
--- a/healthd/healthd_draw.cpp
+++ b/healthd/healthd_draw.cpp
@@ -18,15 +18,34 @@
#include <batteryservice/BatteryService.h>
#include <cutils/klog.h>
+#include "charger.sysprop.h"
#include "healthd_draw.h"
#define LOGE(x...) KLOG_ERROR("charger", x);
#define LOGW(x...) KLOG_WARNING("charger", x);
#define LOGV(x...) KLOG_DEBUG("charger", x);
+static bool get_split_screen() {
+ return android::sysprop::ChargerProperties::draw_split_screen().value_or(false);
+}
+
+static int get_split_offset() {
+ int64_t value = android::sysprop::ChargerProperties::draw_split_offset().value_or(0);
+ if (value < static_cast<int64_t>(std::numeric_limits<int>::min())) {
+ LOGW("draw_split_offset = %" PRId64 " overflow for an int; resetting to %d.\n", value,
+ std::numeric_limits<int>::min());
+ value = std::numeric_limits<int>::min();
+ }
+ if (value > static_cast<int64_t>(std::numeric_limits<int>::max())) {
+ LOGW("draw_split_offset = %" PRId64 " overflow for an int; resetting to %d.\n", value,
+ std::numeric_limits<int>::max());
+ value = std::numeric_limits<int>::max();
+ }
+ return static_cast<int>(value);
+}
+
HealthdDraw::HealthdDraw(animation* anim)
- : kSplitScreen(HEALTHD_DRAW_SPLIT_SCREEN),
- kSplitOffset(HEALTHD_DRAW_SPLIT_OFFSET) {
+ : kSplitScreen(get_split_screen()), kSplitOffset(get_split_offset()) {
int ret = gr_init();
if (ret < 0) {
diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp
index edf34f7..d676083 100644
--- a/healthd/healthd_mode_charger.cpp
+++ b/healthd/healthd_mode_charger.cpp
@@ -43,11 +43,10 @@
#include <cutils/uevent.h>
#include <sys/reboot.h>
-#ifdef CHARGER_ENABLE_SUSPEND
#include <suspend/autosuspend.h>
-#endif
#include "AnimationParser.h"
+#include "charger.sysprop.h"
#include "healthd_draw.h"
#include <health2/Health.h>
@@ -264,18 +263,16 @@
LOGW("\n");
}
-#ifdef CHARGER_ENABLE_SUSPEND
static int request_suspend(bool enable) {
+ if (!android::sysprop::ChargerProperties::enable_suspend().value_or(false)) {
+ return 0;
+ }
+
if (enable)
return autosuspend_enable();
else
return autosuspend_disable();
}
-#else
-static int request_suspend(bool /*enable*/) {
- return 0;
-}
-#endif
static void kick_animation(animation* anim) {
anim->run = true;
@@ -321,10 +318,10 @@
healthd_draw.reset(new HealthdDraw(batt_anim));
-#ifndef CHARGER_DISABLE_INIT_BLANK
- healthd_draw->blank_screen(true);
- charger->screen_blanked = true;
-#endif
+ if (android::sysprop::ChargerProperties::disable_init_blank().value_or(false)) {
+ healthd_draw->blank_screen(true);
+ charger->screen_blanked = true;
+ }
}
/* animation is over, blank screen and leave */
diff --git a/init/action.cpp b/init/action.cpp
index 8cf7645..0c476df 100644
--- a/init/action.cpp
+++ b/init/action.cpp
@@ -80,17 +80,20 @@
filename_(filename),
line_(line) {}
-const KeywordFunctionMap* Action::function_map_ = nullptr;
+const BuiltinFunctionMap* Action::function_map_ = nullptr;
Result<void> Action::AddCommand(std::vector<std::string>&& args, int line) {
if (!function_map_) {
return Error() << "no function map available";
}
- auto function = function_map_->FindFunction(args);
- if (!function) return Error() << function.error();
+ auto map_result = function_map_->Find(args);
+ if (!map_result) {
+ return Error() << map_result.error();
+ }
- commands_.emplace_back(function->second, function->first, std::move(args), line);
+ commands_.emplace_back(map_result->function, map_result->run_in_subcontext, std::move(args),
+ line);
return {};
}
diff --git a/init/action.h b/init/action.h
index 13b250a..80c1da4 100644
--- a/init/action.h
+++ b/init/action.h
@@ -75,7 +75,7 @@
bool oneshot() const { return oneshot_; }
const std::string& filename() const { return filename_; }
int line() const { return line_; }
- static void set_function_map(const KeywordFunctionMap* function_map) {
+ static void set_function_map(const BuiltinFunctionMap* function_map) {
function_map_ = function_map;
}
@@ -91,7 +91,7 @@
Subcontext* subcontext_;
std::string filename_;
int line_;
- static const KeywordFunctionMap* function_map_;
+ static const BuiltinFunctionMap* function_map_;
};
} // namespace init
diff --git a/init/builtins.cpp b/init/builtins.cpp
index ceab568..b6e26a1 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -1152,10 +1152,10 @@
}
// Builtin-function-map start
-const BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const {
+const BuiltinFunctionMap& GetBuiltinFunctionMap() {
constexpr std::size_t kMax = std::numeric_limits<std::size_t>::max();
// clang-format off
- static const Map builtin_functions = {
+ static const BuiltinFunctionMap builtin_functions = {
{"bootchart", {1, 1, {false, do_bootchart}}},
{"chmod", {2, 2, {true, do_chmod}}},
{"chown", {2, 3, {true, do_chown}}},
diff --git a/init/builtins.h b/init/builtins.h
index 7bbf6aa..f0ff1eb 100644
--- a/init/builtins.h
+++ b/init/builtins.h
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef _INIT_BUILTINS_H
-#define _INIT_BUILTINS_H
+#pragma once
#include <functional>
#include <map>
@@ -31,18 +30,16 @@
using BuiltinFunction = std::function<Result<void>(const BuiltinArguments&)>;
-using KeywordFunctionMap = KeywordMap<std::pair<bool, BuiltinFunction>>;
-class BuiltinFunctionMap : public KeywordFunctionMap {
- public:
- BuiltinFunctionMap() {}
-
- private:
- const Map& map() const override;
+struct BuiltinFunctionMapValue {
+ bool run_in_subcontext;
+ BuiltinFunction function;
};
+using BuiltinFunctionMap = KeywordMap<BuiltinFunctionMapValue>;
+
+const BuiltinFunctionMap& GetBuiltinFunctionMap();
+
extern std::vector<std::string> late_import_paths;
} // namespace init
} // namespace android
-
-#endif
diff --git a/init/host_init_verifier.cpp b/init/host_init_verifier.cpp
index 92c2aa5..dfde51b 100644
--- a/init/host_init_verifier.cpp
+++ b/init/host_init_verifier.cpp
@@ -221,7 +221,7 @@
return EXIT_FAILURE;
}
- const BuiltinFunctionMap function_map;
+ const BuiltinFunctionMap& function_map = GetBuiltinFunctionMap();
Action::set_function_map(&function_map);
ActionManager& am = ActionManager::GetInstance();
ServiceList& sl = ServiceList::GetInstance();
diff --git a/init/init.cpp b/init/init.cpp
index 5dba54d..18fb0c3 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -688,7 +688,7 @@
MountHandler mount_handler(&epoll);
set_usb_controller();
- const BuiltinFunctionMap function_map;
+ const BuiltinFunctionMap& function_map = GetBuiltinFunctionMap();
Action::set_function_map(&function_map);
if (!SetupMountNamespaces()) {
diff --git a/init/init_test.cpp b/init/init_test.cpp
index a09db18..0411214 100644
--- a/init/init_test.cpp
+++ b/init/init_test.cpp
@@ -22,6 +22,7 @@
#include "action.h"
#include "action_manager.h"
#include "action_parser.h"
+#include "builtin_arguments.h"
#include "builtins.h"
#include "import_parser.h"
#include "keyword_map.h"
@@ -29,7 +30,6 @@
#include "service.h"
#include "service_list.h"
#include "service_parser.h"
-#include "test_function_map.h"
#include "util.h"
namespace android {
@@ -37,7 +37,7 @@
using ActionManagerCommand = std::function<void(ActionManager&)>;
-void TestInit(const std::string& init_script_file, const TestFunctionMap& test_function_map,
+void TestInit(const std::string& init_script_file, const BuiltinFunctionMap& test_function_map,
const std::vector<ActionManagerCommand>& commands, ServiceList* service_list) {
ActionManager am;
@@ -60,7 +60,7 @@
}
}
-void TestInitText(const std::string& init_script, const TestFunctionMap& test_function_map,
+void TestInitText(const std::string& init_script, const BuiltinFunctionMap& test_function_map,
const std::vector<ActionManagerCommand>& commands, ServiceList* service_list) {
TemporaryFile tf;
ASSERT_TRUE(tf.fd != -1);
@@ -76,8 +76,13 @@
pass_test
)init";
- TestFunctionMap test_function_map;
- test_function_map.Add("pass_test", [&expect_true]() { expect_true = true; });
+ auto do_pass_test = [&expect_true](const BuiltinArguments&) {
+ expect_true = true;
+ return Result<void>{};
+ };
+ BuiltinFunctionMap test_function_map = {
+ {"pass_test", {0, 0, {false, do_pass_test}}},
+ };
ActionManagerCommand trigger_boot = [](ActionManager& am) { am.QueueEventTrigger("boot"); };
std::vector<ActionManagerCommand> commands{trigger_boot};
@@ -103,10 +108,24 @@
)init";
int num_executed = 0;
- TestFunctionMap test_function_map;
- test_function_map.Add("execute_first", [&num_executed]() { EXPECT_EQ(0, num_executed++); });
- test_function_map.Add("execute_second", [&num_executed]() { EXPECT_EQ(1, num_executed++); });
- test_function_map.Add("execute_third", [&num_executed]() { EXPECT_EQ(2, num_executed++); });
+ auto do_execute_first = [&num_executed](const BuiltinArguments&) {
+ EXPECT_EQ(0, num_executed++);
+ return Result<void>{};
+ };
+ auto do_execute_second = [&num_executed](const BuiltinArguments&) {
+ EXPECT_EQ(1, num_executed++);
+ return Result<void>{};
+ };
+ auto do_execute_third = [&num_executed](const BuiltinArguments&) {
+ EXPECT_EQ(2, num_executed++);
+ return Result<void>{};
+ };
+
+ BuiltinFunctionMap test_function_map = {
+ {"execute_first", {0, 0, {false, do_execute_first}}},
+ {"execute_second", {0, 0, {false, do_execute_second}}},
+ {"execute_third", {0, 0, {false, do_execute_third}}},
+ };
ActionManagerCommand trigger_boot = [](ActionManager& am) { am.QueueEventTrigger("boot"); };
std::vector<ActionManagerCommand> commands{trigger_boot};
@@ -127,7 +146,7 @@
)init";
ServiceList service_list;
- TestInitText(init_script, TestFunctionMap(), {}, &service_list);
+ TestInitText(init_script, BuiltinFunctionMap(), {}, &service_list);
ASSERT_EQ(1, std::distance(service_list.begin(), service_list.end()));
auto service = service_list.begin()->get();
@@ -186,8 +205,9 @@
return Result<void>{};
};
- TestFunctionMap test_function_map;
- test_function_map.Add("execute", 1, 1, false, execute_command);
+ BuiltinFunctionMap test_function_map = {
+ {"execute", {1, 1, {false, execute_command}}},
+ };
ActionManagerCommand trigger_boot = [](ActionManager& am) { am.QueueEventTrigger("boot"); };
std::vector<ActionManagerCommand> commands{trigger_boot};
diff --git a/init/keyword_map.h b/init/keyword_map.h
index 7837bb3..d92678f 100644
--- a/init/keyword_map.h
+++ b/init/keyword_map.h
@@ -18,36 +18,49 @@
#include <map>
#include <string>
+#include <vector>
#include "result.h"
namespace android {
namespace init {
-template <typename Function>
+// Every init builtin, init service option, and ueventd option has a minimum and maximum number of
+// arguments. These must be checked both at run time for safety and also at build time for
+// correctness in host_init_verifier. Instead of copying and pasting the boiler plate code that
+// does this check into each function, it is abstracted in KeywordMap<>. This class maps keywords
+// to functions and checks that the number of arguments provided falls in the correct range or
+// returns an error otherwise.
+
+// Value is the return value of Find(), which is typically either a single function or a struct with
+// additional information.
+template <typename Value>
class KeywordMap {
public:
- using FunctionInfo = std::tuple<std::size_t, std::size_t, Function>;
- using Map = std::map<std::string, FunctionInfo>;
+ struct MapValue {
+ size_t min_args;
+ size_t max_args;
+ Value value;
+ };
- virtual ~KeywordMap() {
- }
+ KeywordMap() {}
+ KeywordMap(std::initializer_list<std::pair<const std::string, MapValue>> init) : map_(init) {}
- const Result<Function> FindFunction(const std::vector<std::string>& args) const {
+ Result<Value> Find(const std::vector<std::string>& args) const {
if (args.empty()) return Error() << "Keyword needed, but not provided";
auto& keyword = args[0];
auto num_args = args.size() - 1;
- auto function_info_it = map().find(keyword);
- if (function_info_it == map().end()) {
+ auto result_it = map_.find(keyword);
+ if (result_it == map_.end()) {
return Errorf("Invalid keyword '{}'", keyword);
}
- auto function_info = function_info_it->second;
+ auto result = result_it->second;
- auto min_args = std::get<0>(function_info);
- auto max_args = std::get<1>(function_info);
+ auto min_args = result.min_args;
+ auto max_args = result.max_args;
if (min_args == max_args && num_args != min_args) {
return Errorf("{} requires {} argument{}", keyword, min_args,
(min_args > 1 || min_args == 0) ? "s" : "");
@@ -63,13 +76,11 @@
}
}
- return std::get<Function>(function_info);
+ return result.value;
}
private:
- // Map of keyword ->
- // (minimum number of arguments, maximum number of arguments, function pointer)
- virtual const Map& map() const = 0;
+ std::map<std::string, MapValue> map_;
};
} // namespace init
diff --git a/init/main.cpp b/init/main.cpp
index 2ce46ef..38bc74b 100644
--- a/init/main.cpp
+++ b/init/main.cpp
@@ -60,7 +60,7 @@
if (argc > 1) {
if (!strcmp(argv[1], "subcontext")) {
android::base::InitLogging(argv, &android::base::KernelLogger);
- const BuiltinFunctionMap function_map;
+ const BuiltinFunctionMap& function_map = GetBuiltinFunctionMap();
return SubcontextMain(argc, argv, &function_map);
}
diff --git a/init/service_parser.cpp b/init/service_parser.cpp
index 0fbbeb8..65d96c6 100644
--- a/init/service_parser.cpp
+++ b/init/service_parser.cpp
@@ -461,18 +461,10 @@
return {};
}
-class ServiceParser::OptionParserMap : public KeywordMap<OptionParser> {
- public:
- OptionParserMap() {}
-
- private:
- const Map& map() const override;
-};
-
-const ServiceParser::OptionParserMap::Map& ServiceParser::OptionParserMap::map() const {
+const KeywordMap<ServiceParser::OptionParser>& ServiceParser::GetParserMap() const {
constexpr std::size_t kMax = std::numeric_limits<std::size_t>::max();
// clang-format off
- static const Map option_parsers = {
+ static const KeywordMap<ServiceParser::OptionParser> parser_map = {
{"capabilities",
{0, kMax, &ServiceParser::ParseCapabilities}},
{"class", {1, kMax, &ServiceParser::ParseClass}},
@@ -518,7 +510,7 @@
{"writepid", {1, kMax, &ServiceParser::ParseWritepid}},
};
// clang-format on
- return option_parsers;
+ return parser_map;
}
Result<void> ServiceParser::ParseSection(std::vector<std::string>&& args,
@@ -561,8 +553,7 @@
return {};
}
- static const OptionParserMap parser_map;
- auto parser = parser_map.FindFunction(args);
+ auto parser = GetParserMap().Find(args);
if (!parser) return parser.error();
diff --git a/init/service_parser.h b/init/service_parser.h
index bca0739..98ab15a 100644
--- a/init/service_parser.h
+++ b/init/service_parser.h
@@ -45,7 +45,7 @@
private:
using OptionParser = Result<void> (ServiceParser::*)(std::vector<std::string>&& args);
- class OptionParserMap;
+ const KeywordMap<ServiceParser::OptionParser>& GetParserMap() const;
Result<void> ParseCapabilities(std::vector<std::string>&& args);
Result<void> ParseClass(std::vector<std::string>&& args);
diff --git a/init/subcontext.cpp b/init/subcontext.cpp
index 2f9541b..a13f0c7 100644
--- a/init/subcontext.cpp
+++ b/init/subcontext.cpp
@@ -27,6 +27,7 @@
#include <selinux/android.h>
#include "action.h"
+#include "builtins.h"
#include "util.h"
#if defined(__ANDROID__)
@@ -99,7 +100,7 @@
class SubcontextProcess {
public:
- SubcontextProcess(const KeywordFunctionMap* function_map, std::string context, int init_fd)
+ SubcontextProcess(const BuiltinFunctionMap* function_map, std::string context, int init_fd)
: function_map_(function_map), context_(std::move(context)), init_fd_(init_fd){};
void MainLoop();
@@ -109,7 +110,7 @@
void ExpandArgs(const SubcontextCommand::ExpandArgsCommand& expand_args_command,
SubcontextReply* reply) const;
- const KeywordFunctionMap* function_map_;
+ const BuiltinFunctionMap* function_map_;
const std::string context_;
const int init_fd_;
};
@@ -122,12 +123,12 @@
args.emplace_back(string);
}
- auto map_result = function_map_->FindFunction(args);
+ auto map_result = function_map_->Find(args);
Result<void> result;
if (!map_result) {
result = Error() << "Cannot find command: " << map_result.error();
} else {
- result = RunBuiltinFunction(map_result->second, args, context_);
+ result = RunBuiltinFunction(map_result->function, args, context_);
}
for (const auto& [name, value] : properties_to_set) {
@@ -215,7 +216,7 @@
} // namespace
-int SubcontextMain(int argc, char** argv, const KeywordFunctionMap* function_map) {
+int SubcontextMain(int argc, char** argv, const BuiltinFunctionMap* function_map) {
if (argc < 4) LOG(FATAL) << "Fewer than 4 args specified to subcontext (" << argc << ")";
auto context = std::string(argv[2]);
diff --git a/init/subcontext.h b/init/subcontext.h
index 16bd870..591521f 100644
--- a/init/subcontext.h
+++ b/init/subcontext.h
@@ -60,7 +60,7 @@
android::base::unique_fd socket_;
};
-int SubcontextMain(int argc, char** argv, const KeywordFunctionMap* function_map);
+int SubcontextMain(int argc, char** argv, const BuiltinFunctionMap* function_map);
std::vector<Subcontext>* InitializeSubcontexts();
bool SubcontextChildReap(pid_t pid);
void SubcontextTerminate();
diff --git a/init/subcontext_benchmark.cpp b/init/subcontext_benchmark.cpp
index fdbbc41..f6fee8a 100644
--- a/init/subcontext_benchmark.cpp
+++ b/init/subcontext_benchmark.cpp
@@ -19,8 +19,6 @@
#include <benchmark/benchmark.h>
#include <selinux/selinux.h>
-#include "test_function_map.h"
-
namespace android {
namespace init {
@@ -50,11 +48,11 @@
BENCHMARK(BenchmarkSuccess);
-TestFunctionMap BuildTestFunctionMap() {
- TestFunctionMap test_function_map;
- test_function_map.Add("return_success", 0, 0, true,
- [](const BuiltinArguments& args) { return Result<void>{}; });
-
+BuiltinFunctionMap BuildTestFunctionMap() {
+ auto function = [](const BuiltinArguments& args) { return Result<void>{}; };
+ BuiltinFunctionMap test_function_map = {
+ {"return_success", {0, 0, {true, function}}},
+ };
return test_function_map;
}
diff --git a/init/subcontext_test.cpp b/init/subcontext_test.cpp
index 55912d6..e120a62 100644
--- a/init/subcontext_test.cpp
+++ b/init/subcontext_test.cpp
@@ -26,7 +26,6 @@
#include <selinux/selinux.h>
#include "builtin_arguments.h"
-#include "test_function_map.h"
using namespace std::literals;
@@ -171,46 +170,53 @@
});
}
-TestFunctionMap BuildTestFunctionMap() {
- TestFunctionMap test_function_map;
+BuiltinFunctionMap BuildTestFunctionMap() {
// For CheckDifferentPid
- test_function_map.Add("return_pids_as_error", 0, 0, true,
- [](const BuiltinArguments& args) -> Result<void> {
- return Error() << getpid() << " " << getppid();
- });
+ auto do_return_pids_as_error = [](const BuiltinArguments& args) -> Result<void> {
+ return Error() << getpid() << " " << getppid();
+ };
// For SetProp
- test_function_map.Add("setprop", 2, 2, true, [](const BuiltinArguments& args) {
+ auto do_setprop = [](const BuiltinArguments& args) {
android::base::SetProperty(args[1], args[2]);
return Result<void>{};
- });
+ };
// For MultipleCommands
// Using a shared_ptr to extend lifetime of words to both lambdas
auto words = std::make_shared<std::vector<std::string>>();
- test_function_map.Add("add_word", 1, 1, true, [words](const BuiltinArguments& args) {
+ auto do_add_word = [words](const BuiltinArguments& args) {
words->emplace_back(args[1]);
return Result<void>{};
- });
- test_function_map.Add("return_words_as_error", 0, 0, true,
- [words](const BuiltinArguments& args) -> Result<void> {
- return Error() << Join(*words, " ");
- });
+ };
+ auto do_return_words_as_error = [words](const BuiltinArguments& args) -> Result<void> {
+ return Error() << Join(*words, " ");
+ };
// For RecoverAfterAbort
- test_function_map.Add("cause_log_fatal", 0, 0, true,
- [](const BuiltinArguments& args) -> Result<void> {
- return Error() << std::string(4097, 'f');
- });
- test_function_map.Add(
- "generate_sane_error", 0, 0, true,
- [](const BuiltinArguments& args) -> Result<void> { return Error() << "Sane error!"; });
+ auto do_cause_log_fatal = [](const BuiltinArguments& args) -> Result<void> {
+ return Error() << std::string(4097, 'f');
+ };
+ auto do_generate_sane_error = [](const BuiltinArguments& args) -> Result<void> {
+ return Error() << "Sane error!";
+ };
// For ContextString
- test_function_map.Add(
- "return_context_as_error", 0, 0, true,
- [](const BuiltinArguments& args) -> Result<void> { return Error() << args.context; });
+ auto do_return_context_as_error = [](const BuiltinArguments& args) -> Result<void> {
+ return Error() << args.context;
+ };
+ // clang-format off
+ BuiltinFunctionMap test_function_map = {
+ {"return_pids_as_error", {0, 0, {true, do_return_pids_as_error}}},
+ {"setprop", {2, 2, {true, do_setprop}}},
+ {"add_word", {1, 1, {true, do_add_word}}},
+ {"return_words_as_error", {0, 0, {true, do_return_words_as_error}}},
+ {"cause_log_fatal", {0, 0, {true, do_cause_log_fatal}}},
+ {"generate_sane_error", {0, 0, {true, do_generate_sane_error}}},
+ {"return_context_as_error", {0, 0, {true, do_return_context_as_error}}},
+ };
+ // clang-format on
return test_function_map;
}
diff --git a/init/test_function_map.h b/init/test_function_map.h
deleted file mode 100644
index 466836c..0000000
--- a/init/test_function_map.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <string>
-#include <vector>
-
-#include "builtin_arguments.h"
-#include "builtins.h"
-#include "keyword_map.h"
-
-namespace android {
-namespace init {
-
-class TestFunctionMap : public KeywordFunctionMap {
- public:
- // Helper for argument-less functions
- using BuiltinFunctionNoArgs = std::function<void(void)>;
- void Add(const std::string& name, BuiltinFunctionNoArgs function) {
- Add(name, 0, 0, false, [f = std::move(function)](const BuiltinArguments&) {
- f();
- return Result<void>{};
- });
- }
-
- void Add(const std::string& name, std::size_t min_parameters, std::size_t max_parameters,
- bool run_in_subcontext, BuiltinFunction function) {
- builtin_functions_[name] = make_tuple(min_parameters, max_parameters,
- make_pair(run_in_subcontext, std::move(function)));
- }
-
- private:
- Map builtin_functions_ = {};
-
- const Map& map() const override { return builtin_functions_; }
-};
-
-} // namespace init
-} // namespace android
diff --git a/init/ueventd_parser.cpp b/init/ueventd_parser.cpp
index 25bab93..8ee0cce 100644
--- a/init/ueventd_parser.cpp
+++ b/init/ueventd_parser.cpp
@@ -176,21 +176,14 @@
Result<void> SubsystemParser::ParseLineSection(std::vector<std::string>&& args, int line) {
using OptionParser = Result<void> (SubsystemParser::*)(std::vector<std::string> && args);
+ // clang-format off
+ static const KeywordMap<OptionParser> parser_map = {
+ {"devname", {1, 1, &SubsystemParser::ParseDevName}},
+ {"dirname", {1, 1, &SubsystemParser::ParseDirName}},
+ };
+ // clang-format on
- static class OptionParserMap : public KeywordMap<OptionParser> {
- private:
- const Map& map() const override {
- // clang-format off
- static const Map option_parsers = {
- {"devname", {1, 1, &SubsystemParser::ParseDevName}},
- {"dirname", {1, 1, &SubsystemParser::ParseDirName}},
- };
- // clang-format on
- return option_parsers;
- }
- } parser_map;
-
- auto parser = parser_map.FindFunction(args);
+ auto parser = parser_map.Find(args);
if (!parser) return Error() << parser.error();
diff --git a/libmeminfo/vts/AndroidTest.xml b/libmeminfo/vts/AndroidTest.xml
index 530d16e..9614025 100644
--- a/libmeminfo/vts/AndroidTest.xml
+++ b/libmeminfo/vts/AndroidTest.xml
@@ -24,6 +24,7 @@
<option name="binary-test-source" value="_32bit::DATA/nativetest/vts_meminfo_test/vts_meminfo_test" />
<option name="binary-test-source" value="_64bit::DATA/nativetest64/vts_meminfo_test/vts_meminfo_test" />
<option name="binary-test-type" value="gtest"/>
+ <option name="precondition-first-api-level" value="29" />
<option name="test-timeout" value="10m"/>
</test>
</configuration>
diff --git a/libnativeloader/library_namespaces.cpp b/libnativeloader/library_namespaces.cpp
index f7f972f..c22ce8a 100644
--- a/libnativeloader/library_namespaces.cpp
+++ b/libnativeloader/library_namespaces.cpp
@@ -43,6 +43,7 @@
constexpr const char* kVendorNamespaceName = "sphal";
constexpr const char* kVndkNamespaceName = "vndk";
constexpr const char* kRuntimeNamespaceName = "runtime";
+constexpr const char* kNeuralNetworksNamespaceName = "neuralnetworks";
// classloader-namespace is a linker namespace that is created for the loaded
// app. To be specific, it is created for the app classloader. When
@@ -238,6 +239,14 @@
}
}
+ // Give access to NNAPI libraries (apex-updated LLNDK library).
+ auto nnapi_ns =
+ NativeLoaderNamespace::GetExportedNamespace(kNeuralNetworksNamespaceName, is_bridged);
+ if (!app_ns.Link(nnapi_ns, neuralnetworks_public_libraries())) {
+ *error_msg = app_ns.GetError();
+ return nullptr;
+ }
+
// Give access to VNDK-SP libraries from the 'vndk' namespace.
if (unbundled_vendor_or_product_app && !vndksp_libraries().empty()) {
auto vndk_ns = NativeLoaderNamespace::GetExportedNamespace(kVndkNamespaceName, is_bridged);
diff --git a/libnativeloader/native_loader_test.cpp b/libnativeloader/native_loader_test.cpp
index 614188b..3232e4c 100644
--- a/libnativeloader/native_loader_test.cpp
+++ b/libnativeloader/native_loader_test.cpp
@@ -85,6 +85,7 @@
{"runtime", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("runtime"))},
{"sphal", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("sphal"))},
{"vndk", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("vndk"))},
+ {"neuralnetworks", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("neuralnetworks"))},
};
// The actual gmock object
@@ -339,11 +340,13 @@
bool expected_link_with_sphal_ns = !vendor_public_libraries().empty();
bool expected_link_with_vndk_ns = false;
bool expected_link_with_default_ns = false;
+ bool expected_link_with_neuralnetworks_ns = true;
std::string expected_shared_libs_to_platform_ns = default_public_libraries();
std::string expected_shared_libs_to_runtime_ns = runtime_public_libraries();
std::string expected_shared_libs_to_sphal_ns = vendor_public_libraries();
std::string expected_shared_libs_to_vndk_ns = vndksp_libraries();
std::string expected_shared_libs_to_default_ns = default_public_libraries();
+ std::string expected_shared_libs_to_neuralnetworks_ns = neuralnetworks_public_libraries();
void SetExpectations() {
NativeLoaderTest::SetExpectations();
@@ -394,6 +397,11 @@
StrEq(expected_shared_libs_to_default_ns)))
.WillOnce(Return(true));
}
+ if (expected_link_with_neuralnetworks_ns) {
+ EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("neuralnetworks"),
+ StrEq(expected_shared_libs_to_neuralnetworks_ns)))
+ .WillOnce(Return(true));
+ }
}
void RunTest() {
diff --git a/libnativeloader/public_libraries.cpp b/libnativeloader/public_libraries.cpp
index c205eb1..10e23fd 100644
--- a/libnativeloader/public_libraries.cpp
+++ b/libnativeloader/public_libraries.cpp
@@ -51,6 +51,8 @@
constexpr const char* kRuntimeApexLibPath = "/apex/com.android.runtime/" LIB;
+constexpr const char* kNeuralNetworksApexPublicLibrary = "libneuralnetworks.so";
+
// TODO(b/130388701): do we need this?
std::string root_dir() {
static const char* android_root_env = getenv("ANDROID_ROOT");
@@ -219,6 +221,12 @@
sonames.erase(it);
}
}
+
+ // Remove the public libs in the nnapi namespace.
+ auto it = std::find(sonames.begin(), sonames.end(), kNeuralNetworksApexPublicLibrary);
+ if (it != sonames.end()) {
+ sonames.erase(it);
+ }
return android::base::Join(sonames, ':');
}
@@ -267,6 +275,10 @@
return android::base::Join(sonames, ':');
}
+static std::string InitNeuralNetworksPublicLibraries() {
+ return kNeuralNetworksApexPublicLibrary;
+}
+
} // namespace
const std::string& default_public_libraries() {
@@ -289,6 +301,11 @@
return list;
}
+const std::string& neuralnetworks_public_libraries() {
+ static std::string list = InitNeuralNetworksPublicLibraries();
+ return list;
+}
+
const std::string& llndk_libraries() {
static std::string list = InitLlndkLibraries();
return list;
diff --git a/libnativeloader/public_libraries.h b/libnativeloader/public_libraries.h
index 9b6dea8..9bb3366 100644
--- a/libnativeloader/public_libraries.h
+++ b/libnativeloader/public_libraries.h
@@ -26,6 +26,7 @@
const std::string& runtime_public_libraries();
const std::string& vendor_public_libraries();
const std::string& extended_public_libraries();
+const std::string& neuralnetworks_public_libraries();
const std::string& llndk_libraries();
const std::string& vndksp_libraries();
diff --git a/libziparchive/Android.bp b/libziparchive/Android.bp
index 3843252..0253f2f 100644
--- a/libziparchive/Android.bp
+++ b/libziparchive/Android.bp
@@ -76,6 +76,10 @@
"liblog",
],
+ // for FRIEND_TEST
+ static_libs: ["libgtest_prod"],
+ export_static_lib_headers: ["libgtest_prod"],
+
export_include_dirs: ["include"],
}
diff --git a/libziparchive/include/ziparchive/zip_writer.h b/libziparchive/include/ziparchive/zip_writer.h
index a2a0dbf..d68683d 100644
--- a/libziparchive/include/ziparchive/zip_writer.h
+++ b/libziparchive/include/ziparchive/zip_writer.h
@@ -19,6 +19,7 @@
#include <cstdio>
#include <ctime>
+#include <gtest/gtest_prod.h>
#include <memory>
#include <string>
#include <string_view>
@@ -165,6 +166,7 @@
int32_t StoreBytes(FileEntry* file, const void* data, uint32_t len);
int32_t CompressBytes(FileEntry* file, const void* data, uint32_t len);
int32_t FlushCompressedBytes(FileEntry* file);
+ bool ShouldUseDataDescriptor() const;
enum class State {
kWritingZip,
@@ -182,4 +184,6 @@
std::unique_ptr<z_stream, void (*)(z_stream*)> z_stream_;
std::vector<uint8_t> buffer_;
+
+ FRIEND_TEST(zipwriter, WriteToUnseekableFile);
};
diff --git a/libziparchive/zip_writer.cc b/libziparchive/zip_writer.cc
index 198154b..67279a6 100644
--- a/libziparchive/zip_writer.cc
+++ b/libziparchive/zip_writer.cc
@@ -455,6 +455,11 @@
return kNoError;
}
+bool ZipWriter::ShouldUseDataDescriptor() const {
+ // Only use a trailing "data descriptor" if the output isn't seekable.
+ return !seekable_;
+}
+
int32_t ZipWriter::FinishEntry() {
if (state_ != State::kWritingEntry) {
return kInvalidState;
@@ -467,7 +472,7 @@
}
}
- if ((current_file_entry_.compression_method & kCompressDeflated) || !seekable_) {
+ if (ShouldUseDataDescriptor()) {
// Some versions of ZIP don't allow STORED data to have a trailing DataDescriptor.
// If this file is not seekable, or if the data is compressed, write a DataDescriptor.
const uint32_t sig = DataDescriptor::kOptSignature;
@@ -515,7 +520,7 @@
for (FileEntry& file : files_) {
CentralDirectoryRecord cdr = {};
cdr.record_signature = CentralDirectoryRecord::kSignature;
- if ((file.compression_method & kCompressDeflated) || !seekable_) {
+ if (ShouldUseDataDescriptor()) {
cdr.gpb_flags |= kGPBDDFlagMask;
}
cdr.compression_method = file.compression_method;
diff --git a/libziparchive/zip_writer_test.cc b/libziparchive/zip_writer_test.cc
index c3da23c..d324d4b 100644
--- a/libziparchive/zip_writer_test.cc
+++ b/libziparchive/zip_writer_test.cc
@@ -243,6 +243,7 @@
ZipEntry data;
ASSERT_EQ(0, FindEntry(handle, "file.txt", &data));
EXPECT_EQ(kCompressDeflated, data.method);
+ EXPECT_EQ(0u, data.has_data_descriptor);
ASSERT_EQ(4u, data.uncompressed_length);
ASSERT_TRUE(AssertFileEntryContentsEq("helo", handle, &data));
@@ -351,6 +352,29 @@
CloseArchive(handle);
}
+TEST_F(zipwriter, WriteToUnseekableFile) {
+ const char* expected = "hello";
+ ZipWriter writer(file_);
+ writer.seekable_ = false;
+
+ ASSERT_EQ(0, writer.StartEntry("file.txt", 0));
+ ASSERT_EQ(0, writer.WriteBytes(expected, strlen(expected)));
+ ASSERT_EQ(0, writer.FinishEntry());
+ ASSERT_EQ(0, writer.Finish());
+ ASSERT_GE(0, lseek(fd_, 0, SEEK_SET));
+
+ ZipArchiveHandle handle;
+ ASSERT_EQ(0, OpenArchiveFd(fd_, "temp", &handle, false));
+ ZipEntry data;
+ ASSERT_EQ(0, FindEntry(handle, "file.txt", &data));
+ EXPECT_EQ(kCompressStored, data.method);
+ EXPECT_EQ(1u, data.has_data_descriptor);
+ EXPECT_EQ(strlen(expected), data.compressed_length);
+ ASSERT_EQ(strlen(expected), data.uncompressed_length);
+ ASSERT_TRUE(AssertFileEntryContentsEq(expected, handle, &data));
+ CloseArchive(handle);
+}
+
TEST_F(zipwriter, TruncateFileAfterBackup) {
ZipWriter writer(file_);
diff --git a/logcat/logcatd.rc b/logcat/logcatd.rc
index 25104eb..26c9de3 100644
--- a/logcat/logcatd.rc
+++ b/logcat/logcatd.rc
@@ -13,28 +13,13 @@
# expect /init to report failure if property empty (default)
setprop persist.logd.logpersistd.size ${persist.logd.logpersistd.count}
-on property:persist.logd.logpersistd.size=256
- setprop persist.logd.logpersistd.size ""
- setprop logd.logpersistd.size ""
-
on property:persist.logd.logpersistd.size=*
- # expect /init to report failure if property empty (default)
setprop logd.logpersistd.size ${persist.logd.logpersistd.size}
-on property:persist.logd.logpersistd.rotate_kbytes=1024
- setprop persist.logd.logpersistd.rotate_kbytes ""
- setprop logd.logpersistd.rotate_kbytes ""
-
on property:persist.logd.logpersistd.rotate_kbytes=*
- # expect /init to report failure if property empty (default)
- setprop logd.logpersistd.rotate_kbytes ${persist.logd.logpersistd.rotate_kbytes}
-
-on property:persist.logd.logpersistd.buffer=all
- setprop persist.logd.logpersistd.buffer ""
- setprop logd.logpersistd.buffer ""
+ setprop logd.logpersistd.rotate_kbytes ${persist.logd.logpersistd.rotate_kbytes}
on property:persist.logd.logpersistd.buffer=*
- # expect /init to report failure if property empty (default)
setprop logd.logpersistd.buffer ${persist.logd.logpersistd.buffer}
on property:persist.logd.logpersistd=logcatd
diff --git a/rootdir/Android.mk b/rootdir/Android.mk
index 246f9ac..76d6f7e 100644
--- a/rootdir/Android.mk
+++ b/rootdir/Android.mk
@@ -378,6 +378,62 @@
echo $(lib).so >> $@;)
#######################################
+# vndkcore.libraries.txt
+include $(CLEAR_VARS)
+LOCAL_MODULE := vndkcore.libraries.txt
+LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)
+LOCAL_MODULE_STEM := $(call append_vndk_version,$(LOCAL_MODULE))
+include $(BUILD_SYSTEM)/base_rules.mk
+$(LOCAL_BUILT_MODULE): PRIVATE_VNDK_CORE_LIBRARIES := $(VNDK_CORE_LIBRARIES)
+$(LOCAL_BUILT_MODULE):
+ @echo "Generate: $@"
+ @mkdir -p $(dir $@)
+ $(hide) echo -n > $@
+ $(hide) $(foreach lib,$(PRIVATE_VNDK_CORE_LIBRARIES), \
+ echo $(lib).so >> $@;)
+
+#######################################
+# vndkprivate.libraries.txt
+include $(CLEAR_VARS)
+LOCAL_MODULE := vndkprivate.libraries.txt
+LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)
+LOCAL_MODULE_STEM := $(call append_vndk_version,$(LOCAL_MODULE))
+include $(BUILD_SYSTEM)/base_rules.mk
+$(LOCAL_BUILT_MODULE): PRIVATE_VNDK_PRIVATE_LIBRARIES := $(VNDK_PRIVATE_LIBRARIES)
+$(LOCAL_BUILT_MODULE):
+ @echo "Generate: $@"
+ @mkdir -p $(dir $@)
+ $(hide) echo -n > $@
+ $(hide) $(foreach lib,$(PRIVATE_VNDK_PRIVATE_LIBRARIES), \
+ echo $(lib).so >> $@;)
+
+#######################################
+# sanitizer.libraries.txt
+include $(CLEAR_VARS)
+LOCAL_MODULE := sanitizer.libraries.txt
+LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)
+LOCAL_MODULE_STEM := $(LOCAL_MODULE)
+include $(BUILD_SYSTEM)/base_rules.mk
+$(LOCAL_BUILT_MODULE): PRIVATE_SANITIZER_RUNTIME_LIBRARIES := $(addsuffix .so,\
+ $(ADDRESS_SANITIZER_RUNTIME_LIBRARY) \
+ $(HWADDRESS_SANITIZER_RUNTIME_LIBRARY) \
+ $(UBSAN_RUNTIME_LIBRARY) \
+ $(TSAN_RUNTIME_LIBRARY) \
+ $(2ND_ADDRESS_SANITIZER_RUNTIME_LIBRARY) \
+ $(2ND_HWADDRESS_SANITIZER_RUNTIME_LIBRARY) \
+ $(2ND_UBSAN_RUNTIME_LIBRARY) \
+ $(2ND_TSAN_RUNTIME_LIBRARY))
+$(LOCAL_BUILT_MODULE):
+ @echo "Generate: $@"
+ @mkdir -p $(dir $@)
+ $(hide) echo -n > $@
+ $(hide) $(foreach lib,$(PRIVATE_SANITIZER_RUNTIME_LIBRARIES), \
+ echo $(lib) >> $@;)
+
+#######################################
# adb_debug.prop in debug ramdisk
include $(CLEAR_VARS)
LOCAL_MODULE := adb_debug.prop
diff --git a/rootdir/etc/ld.config.legacy.txt b/rootdir/etc/ld.config.legacy.txt
index ad14493..f0b1fd2 100644
--- a/rootdir/etc/ld.config.legacy.txt
+++ b/rootdir/etc/ld.config.legacy.txt
@@ -42,7 +42,7 @@
# APEX related namespaces.
###############################################################################
-additional.namespaces = runtime,conscrypt,media,resolv
+additional.namespaces = runtime,conscrypt,media,neuralnetworks,resolv
# Keep in sync with the "platform" namespace in art/build/apex/ld.config.txt.
# If a shared library or an executable requests a shared library that
@@ -51,8 +51,8 @@
# shared library cannot be loaded from the runtime namespace either, the
# dynamic linker tries to load the shared library from the resolv namespace.
# Finally, if all attempts fail, the dynamic linker returns an error.
-namespace.default.links = runtime,resolv
-namespace.default.asan.links = runtime,resolv
+namespace.default.links = runtime,resolv,neuralnetworks
+namespace.default.asan.links = runtime,resolv,neuralnetworks
namespace.default.link.runtime.shared_libs = libandroidicu.so
namespace.default.link.runtime.shared_libs += libdexfile_external.so
namespace.default.link.runtime.shared_libs += libdexfiled_external.so
@@ -71,6 +71,9 @@
# to be loaded in the default namespace.
namespace.default.link.resolv.shared_libs = libnetd_resolv.so
+# LLNDK library moved into apex
+namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "runtime" APEX namespace
#
@@ -159,6 +162,27 @@
namespace.resolv.link.default.shared_libs += libvndksupport.so
###############################################################################
+# "neuralnetworks" APEX namespace
+#
+# This namespace is for libraries within the NNAPI APEX.
+###############################################################################
+namespace.neuralnetworks.isolated = true
+namespace.neuralnetworks.visible = true
+
+namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.links = default
+namespace.neuralnetworks.link.default.shared_libs = libc.so
+namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so
+namespace.neuralnetworks.link.default.shared_libs += libdl.so
+namespace.neuralnetworks.link.default.shared_libs += liblog.so
+namespace.neuralnetworks.link.default.shared_libs += libm.so
+namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so
+namespace.neuralnetworks.link.default.shared_libs += libsync.so
+namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so
+
+
+###############################################################################
# Namespace config for binaries under /postinstall.
# Only one default namespace is defined and it has no directories other than
# /system/lib and /product/lib in the search paths. This is because linker
diff --git a/rootdir/etc/ld.config.txt b/rootdir/etc/ld.config.txt
index a6ea2ab..3321425 100644
--- a/rootdir/etc/ld.config.txt
+++ b/rootdir/etc/ld.config.txt
@@ -35,7 +35,7 @@
dir.system = /data
[system]
-additional.namespaces = runtime,conscrypt,media,resolv,sphal,vndk,rs
+additional.namespaces = runtime,conscrypt,media,neuralnetworks,resolv,sphal,vndk,rs
###############################################################################
# "default" namespace
@@ -132,7 +132,7 @@
# shared library cannot be loaded from the runtime namespace either, the
# dynamic linker tries to load the shared library from the resolv namespace.
# Finally, if all attempts fail, the dynamic linker returns an error.
-namespace.default.links = runtime,resolv
+namespace.default.links = runtime,resolv,neuralnetworks
namespace.default.link.runtime.shared_libs = libandroidicu.so
namespace.default.link.runtime.shared_libs += libdexfile_external.so
namespace.default.link.runtime.shared_libs += libdexfiled_external.so
@@ -152,6 +152,9 @@
# to be loaded in the default namespace.
namespace.default.link.resolv.shared_libs = libnetd_resolv.so
+# LLNDK library moved into apex
+namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "runtime" APEX namespace
#
@@ -185,13 +188,16 @@
namespace.media.permitted.paths = /apex/com.android.media/${LIB}/extractors
-namespace.media.links = default
+namespace.media.links = default,neuralnetworks
namespace.media.link.default.shared_libs = %LLNDK_LIBRARIES%
namespace.media.link.default.shared_libs += libbinder_ndk.so
namespace.media.link.default.shared_libs += libcgrouprc.so
namespace.media.link.default.shared_libs += libmediametrics.so
namespace.media.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
+# LLNDK library moved into apex
+namespace.media.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "conscrypt" APEX namespace
#
@@ -269,7 +275,7 @@
# libs listed here can be used. Order is important here as the namespaces are
# tried in this order. rs should be before vndk because both are capable
# of loading libRS_internal.so
-namespace.sphal.links = rs,default,vndk
+namespace.sphal.links = rs,default,vndk,neuralnetworks
# Renderscript gets separate namespace
namespace.sphal.link.rs.shared_libs = libRS_internal.so
@@ -279,6 +285,10 @@
namespace.sphal.link.vndk.shared_libs = %VNDK_SAMEPROCESS_LIBRARIES%
+# LLNDK library moved into apex
+namespace.sphal.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
+
###############################################################################
# "rs" namespace
#
@@ -318,7 +328,7 @@
namespace.rs.asan.permitted.paths += /vendor/${LIB}
namespace.rs.asan.permitted.paths += /data
-namespace.rs.links = default,vndk
+namespace.rs.links = default,vndk,neuralnetworks
namespace.rs.link.default.shared_libs = %LLNDK_LIBRARIES%
namespace.rs.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
@@ -328,6 +338,10 @@
namespace.rs.link.vndk.shared_libs = %VNDK_SAMEPROCESS_LIBRARIES%
+# LLNDK library moved into apex
+namespace.rs.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
+
###############################################################################
# "vndk" namespace
#
@@ -373,7 +387,7 @@
# The "vndk" namespace links to "default" namespace for LLNDK libs and links to
# "sphal" namespace for vendor libs. The ordering matters. The "default"
# namespace has higher priority than the "sphal" namespace.
-namespace.vndk.links = default,sphal,runtime
+namespace.vndk.links = default,sphal,runtime,neuralnetworks
# When these NDK libs are required inside this namespace, then it is redirected
# to the default namespace. This is possible since their ABI is stable across
@@ -386,6 +400,28 @@
# Allow VNDK-SP extensions to use vendor libraries
namespace.vndk.link.sphal.allow_all_shared_libs = true
+# LLNDK library moved into apex
+namespace.vndk.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
+###############################################################################
+# "neuralnetworks" APEX namespace
+#
+# This namespace is for libraries within the NNAPI APEX.
+###############################################################################
+namespace.neuralnetworks.isolated = true
+namespace.neuralnetworks.visible = true
+
+namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.links = default
+namespace.neuralnetworks.link.default.shared_libs = libc.so
+namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so
+namespace.neuralnetworks.link.default.shared_libs += libdl.so
+namespace.neuralnetworks.link.default.shared_libs += liblog.so
+namespace.neuralnetworks.link.default.shared_libs += libm.so
+namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so
+namespace.neuralnetworks.link.default.shared_libs += libsync.so
+namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so
###############################################################################
# Namespace config for vendor processes. In O, no restriction is enforced for
@@ -394,7 +430,7 @@
# (LL-NDK only) access.
###############################################################################
[vendor]
-additional.namespaces = runtime,system,vndk%VNDK_IN_SYSTEM_NS%
+additional.namespaces = runtime,system,neuralnetworks,vndk%VNDK_IN_SYSTEM_NS%
###############################################################################
# "default" namespace
@@ -435,7 +471,7 @@
namespace.default.asan.permitted.paths += /data/asan/vendor
namespace.default.asan.permitted.paths += /vendor
-namespace.default.links = system,vndk%VNDK_IN_SYSTEM_NS%,runtime
+namespace.default.links = system,vndk%VNDK_IN_SYSTEM_NS%,runtime,neuralnetworks
namespace.default.link.runtime.shared_libs = %SANITIZER_RUNTIME_LIBRARIES%
namespace.default.link.system.shared_libs = %LLNDK_LIBRARIES%
namespace.default.link.system.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
@@ -443,6 +479,9 @@
namespace.default.link.vndk.shared_libs = %VNDK_SAMEPROCESS_LIBRARIES%
namespace.default.link.vndk.shared_libs += %VNDK_CORE_LIBRARIES%
+# LLNDK library moved into apex
+namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "runtime" APEX namespace
#
@@ -458,6 +497,7 @@
# classloader-namespace for oat files, and tighten this up.
namespace.runtime.link.system.allow_all_shared_libs = true
+
###############################################################################
# "vndk" namespace
#
@@ -491,7 +531,7 @@
# Android releases. The links here should be identical to that of the
# 'vndk_in_system' namespace, except for the link between 'vndk' and
# 'vndk_in_system'.
-namespace.vndk.links = system,default%VNDK_IN_SYSTEM_NS%,runtime
+namespace.vndk.links = system,default%VNDK_IN_SYSTEM_NS%,runtime,neuralnetworks
namespace.vndk.link.system.shared_libs = %LLNDK_LIBRARIES%
namespace.vndk.link.system.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
@@ -502,6 +542,9 @@
namespace.vndk.link.vndk_in_system.shared_libs = %VNDK_USING_CORE_VARIANT_LIBRARIES%
+# LLNDK library moved into apex
+namespace.vndk.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "system" namespace
#
@@ -571,14 +614,34 @@
# 1. 'vndk_in_system' needs to be freely linked back to 'vndk'.
# 2. 'vndk_in_system' does not need to link to 'default', as any library that
# requires anything vendor would not be a vndk_in_system library.
-namespace.vndk_in_system.links = vndk,system,runtime
+namespace.vndk_in_system.links = vndk,system,runtime,neuralnetworks
namespace.vndk_in_system.link.runtime.shared_libs = %SANITIZER_RUNTIME_LIBRARIES%
namespace.vndk_in_system.link.system.shared_libs = %LLNDK_LIBRARIES%
namespace.vndk_in_system.link.system.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
namespace.vndk_in_system.link.vndk.allow_all_shared_libs = true
+namespace.vndk_in_system.link.neuralnetworks.shared_libs = libneuralnetworks.so
+###############################################################################
+# "neuralnetworks" APEX namespace
+#
+# This namespace is for libraries within the NNAPI APEX.
+###############################################################################
+namespace.neuralnetworks.isolated = true
+namespace.neuralnetworks.visible = true
+
+namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.links = default
+namespace.neuralnetworks.link.default.shared_libs = libc.so
+namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so
+namespace.neuralnetworks.link.default.shared_libs += libdl.so
+namespace.neuralnetworks.link.default.shared_libs += liblog.so
+namespace.neuralnetworks.link.default.shared_libs += libm.so
+namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so
+namespace.neuralnetworks.link.default.shared_libs += libsync.so
+namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so
###############################################################################
# Namespace config for native tests that need access to both system and vendor
@@ -587,7 +650,7 @@
# includes the requisite namespace setup for APEXes.
###############################################################################
[unrestricted]
-additional.namespaces = runtime,media,conscrypt,resolv
+additional.namespaces = runtime,media,conscrypt,resolv,neuralnetworks
# Visible to allow links to be created at runtime, e.g. through
# android_link_namespaces in libnativeloader.
@@ -605,7 +668,7 @@
namespace.default.asan.search.paths += /vendor/${LIB}
# Keep in sync with the "platform" namespace in art/build/apex/ld.config.txt.
-namespace.default.links = runtime,resolv
+namespace.default.links = runtime,resolv,neuralnetworks
namespace.default.link.runtime.shared_libs = libandroidicu.so
namespace.default.link.runtime.shared_libs += libdexfile_external.so
namespace.default.link.runtime.shared_libs += libdexfiled_external.so
@@ -621,6 +684,7 @@
namespace.default.link.runtime.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
namespace.default.link.resolv.shared_libs = libnetd_resolv.so
+namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so
###############################################################################
# "runtime" APEX namespace
@@ -653,12 +717,16 @@
namespace.media.permitted.paths = /apex/com.android.media/${LIB}/extractors
-namespace.media.links = default
+namespace.media.links = default,neuralnetworks
namespace.media.link.default.shared_libs = %LLNDK_LIBRARIES%
namespace.media.link.default.shared_libs += libbinder_ndk.so
namespace.media.link.default.shared_libs += libmediametrics.so
namespace.media.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
+# LLNDK library moved into apex
+namespace.media.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
+
###############################################################################
# "conscrypt" APEX namespace
#
@@ -694,6 +762,25 @@
namespace.resolv.link.default.shared_libs += libbinder_ndk.so
namespace.resolv.link.default.shared_libs += liblog.so
+###############################################################################
+# "neuralnetworks" APEX namespace
+#
+# This namespace is for libraries within the NNAPI APEX.
+###############################################################################
+namespace.neuralnetworks.isolated = true
+namespace.neuralnetworks.visible = true
+
+namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.links = default
+namespace.neuralnetworks.link.default.shared_libs = libc.so
+namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so
+namespace.neuralnetworks.link.default.shared_libs += libdl.so
+namespace.neuralnetworks.link.default.shared_libs += liblog.so
+namespace.neuralnetworks.link.default.shared_libs += libm.so
+namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so
+namespace.neuralnetworks.link.default.shared_libs += libsync.so
+namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so
###############################################################################
# Namespace config for binaries under /postinstall.
diff --git a/rootdir/etc/ld.config.vndk_lite.txt b/rootdir/etc/ld.config.vndk_lite.txt
index 69535a9..0bb60ab 100644
--- a/rootdir/etc/ld.config.vndk_lite.txt
+++ b/rootdir/etc/ld.config.vndk_lite.txt
@@ -35,7 +35,7 @@
dir.system = /data
[system]
-additional.namespaces = runtime,conscrypt,media,resolv,sphal,vndk,rs
+additional.namespaces = runtime,conscrypt,media,neuralnetworks,resolv,sphal,vndk,rs
###############################################################################
# "default" namespace
@@ -72,7 +72,7 @@
# shared library cannot be loaded from the runtime namespace either, the
# dynamic linker tries to load the shared library from the resolv namespace.
# Finally, if all attempts fail, the dynamic linker returns an error.
-namespace.default.links = runtime,resolv
+namespace.default.links = runtime,resolv,neuralnetworks
namespace.default.link.runtime.shared_libs = libandroidicu.so
namespace.default.link.runtime.shared_libs += libdexfile_external.so
namespace.default.link.runtime.shared_libs += libdexfiled_external.so
@@ -91,6 +91,9 @@
# to be loaded in the default namespace.
namespace.default.link.resolv.shared_libs = libnetd_resolv.so
+# LLNDK library moved into apex
+namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "runtime" APEX namespace
#
@@ -124,12 +127,15 @@
namespace.media.permitted.paths = /apex/com.android.media/${LIB}/extractors
-namespace.media.links = default
+namespace.media.links = default,neuralnetworks
namespace.media.link.default.shared_libs = %LLNDK_LIBRARIES%
namespace.media.link.default.shared_libs += libbinder_ndk.so
namespace.media.link.default.shared_libs += libmediametrics.so
namespace.media.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
+# LLNDK library moved into apex
+namespace.media.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "conscrypt" APEX namespace
#
@@ -207,7 +213,7 @@
# libs listed here can be used. Order is important here as the namespaces are
# tried in this order. rs should be before vndk because both are capable
# of loading libRS_internal.so
-namespace.sphal.links = rs,default,vndk
+namespace.sphal.links = rs,default,vndk,neuralnetworks
# Renderscript gets separate namespace
namespace.sphal.link.rs.shared_libs = libRS_internal.so
@@ -217,6 +223,9 @@
namespace.sphal.link.vndk.shared_libs = %VNDK_SAMEPROCESS_LIBRARIES%
+# LLNDK library moved into apex
+namespace.sphal.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "rs" namespace
#
@@ -256,7 +265,7 @@
namespace.rs.asan.permitted.paths += /vendor/${LIB}
namespace.rs.asan.permitted.paths += /data
-namespace.rs.links = default,vndk
+namespace.rs.links = default,vndk,neuralnetworks
namespace.rs.link.default.shared_libs = %LLNDK_LIBRARIES%
namespace.rs.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
@@ -266,6 +275,9 @@
namespace.rs.link.vndk.shared_libs = %VNDK_SAMEPROCESS_LIBRARIES%
+# LLNDK library moved into apex
+namespace.rs.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "vndk" namespace
#
@@ -310,10 +322,31 @@
# When these NDK libs are required inside this namespace, then it is redirected
# to the default namespace. This is possible since their ABI is stable across
# Android releases.
-namespace.vndk.links = default
+namespace.vndk.links = default,neuralnetworks
namespace.vndk.link.default.shared_libs = %LLNDK_LIBRARIES%
namespace.vndk.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
+namespace.vndk.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
+###############################################################################
+# "neuralnetworks" APEX namespace
+#
+# This namespace is for libraries within the NNAPI APEX.
+###############################################################################
+namespace.neuralnetworks.isolated = true
+namespace.neuralnetworks.visible = true
+
+namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.links = default
+namespace.neuralnetworks.link.default.shared_libs = libc.so
+namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so
+namespace.neuralnetworks.link.default.shared_libs += libdl.so
+namespace.neuralnetworks.link.default.shared_libs += liblog.so
+namespace.neuralnetworks.link.default.shared_libs += libm.so
+namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so
+namespace.neuralnetworks.link.default.shared_libs += libsync.so
+namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so
###############################################################################
@@ -323,7 +356,7 @@
# (LL-NDK only) access.
###############################################################################
[vendor]
-additional.namespaces = runtime
+additional.namespaces = runtime,neuralnetworks
namespace.default.isolated = false
@@ -365,7 +398,7 @@
namespace.default.asan.search.paths += /data/asan/system/${LIB}/vndk%VNDK_VER%
namespace.default.asan.search.paths += /system/${LIB}/vndk%VNDK_VER%
-namespace.default.links = runtime
+namespace.default.links = runtime,neuralnetworks
namespace.default.link.runtime.shared_libs = libdexfile_external.so
namespace.default.link.runtime.shared_libs += libdexfiled_external.so
# TODO(b/120786417 or b/134659294): libicuuc.so and libicui18n.so are kept for app compat.
@@ -377,6 +410,9 @@
# Workaround for b/124772622
namespace.default.link.runtime.shared_libs += libandroidicu.so
+# LLNDK library moved into apex
+namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "runtime" APEX namespace
#
@@ -393,13 +429,34 @@
namespace.runtime.link.default.allow_all_shared_libs = true
###############################################################################
+# "neuralnetworks" APEX namespace
+#
+# This namespace is for libraries within the NNAPI APEX.
+###############################################################################
+namespace.neuralnetworks.isolated = true
+namespace.neuralnetworks.visible = true
+
+namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.links = default
+namespace.neuralnetworks.link.default.shared_libs = libc.so
+namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so
+namespace.neuralnetworks.link.default.shared_libs += libdl.so
+namespace.neuralnetworks.link.default.shared_libs += liblog.so
+namespace.neuralnetworks.link.default.shared_libs += libm.so
+namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so
+namespace.neuralnetworks.link.default.shared_libs += libsync.so
+namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so
+
+
+###############################################################################
# Namespace config for native tests that need access to both system and vendor
# libraries. This replicates the default linker config (done by
# init_default_namespace_no_config in bionic/linker/linker.cpp), except that it
# includes the requisite namespace setup for APEXes.
###############################################################################
[unrestricted]
-additional.namespaces = runtime,media,conscrypt,resolv
+additional.namespaces = runtime,media,conscrypt,resolv,neuralnetworks
# Visible to allow links to be created at runtime, e.g. through
# android_link_namespaces in libnativeloader.
@@ -417,7 +474,7 @@
namespace.default.asan.search.paths += /vendor/${LIB}
# Keep in sync with the "platform" namespace in art/build/apex/ld.config.txt.
-namespace.default.links = runtime,resolv
+namespace.default.links = runtime,resolv,neuralnetworks
namespace.default.link.runtime.shared_libs = libandroidicu.so
namespace.default.link.runtime.shared_libs += libdexfile_external.so
namespace.default.link.runtime.shared_libs += libdexfiled_external.so
@@ -434,6 +491,9 @@
namespace.default.link.resolv.shared_libs = libnetd_resolv.so
+# LLNDK library moved into apex
+namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "runtime" APEX namespace
#
@@ -450,7 +510,6 @@
namespace.runtime.links = default
# TODO(b/130340935): Use a dynamically created linker namespace similar to
# classloader-namespace for oat files, and tighten this up.
-namespace.runtime.link.default.allow_all_shared_libs = true
###############################################################################
# "media" APEX namespace
@@ -465,12 +524,15 @@
namespace.media.permitted.paths = /apex/com.android.media/${LIB}/extractors
-namespace.media.links = default
+namespace.media.links = default,neuralnetworks
namespace.media.link.default.shared_libs = %LLNDK_LIBRARIES%
namespace.media.link.default.shared_libs += libbinder_ndk.so
namespace.media.link.default.shared_libs += libmediametrics.so
namespace.media.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES%
+# LLNDK library moved into apex
+namespace.media.link.neuralnetworks.shared_libs = libneuralnetworks.so
+
###############################################################################
# "conscrypt" APEX namespace
#
@@ -506,6 +568,27 @@
namespace.resolv.link.default.shared_libs += libbinder_ndk.so
###############################################################################
+# "neuralnetworks" APEX namespace
+#
+# This namespace is for libraries within the NNAPI APEX.
+###############################################################################
+namespace.neuralnetworks.isolated = true
+namespace.neuralnetworks.visible = true
+
+namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB}
+namespace.neuralnetworks.links = default
+namespace.neuralnetworks.link.default.shared_libs = libc.so
+namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so
+namespace.neuralnetworks.link.default.shared_libs += libdl.so
+namespace.neuralnetworks.link.default.shared_libs += liblog.so
+namespace.neuralnetworks.link.default.shared_libs += libm.so
+namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so
+namespace.neuralnetworks.link.default.shared_libs += libsync.so
+namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so
+
+
+###############################################################################
# Namespace config for binaries under /postinstall.
# Only default namespace is defined and default has no directories
# other than /system/lib in the search paths. This is because linker calls
diff --git a/rootdir/update_and_install_ld_config.mk b/rootdir/update_and_install_ld_config.mk
index ee29afc..dbe60e5 100644
--- a/rootdir/update_and_install_ld_config.mk
+++ b/rootdir/update_and_install_ld_config.mk
@@ -40,6 +40,7 @@
vndksp_libraries_file := $(library_lists_dir)/vndksp.libraries.$(vndk_version).txt
vndkcore_libraries_file := $(library_lists_dir)/vndkcore.libraries.txt
vndkprivate_libraries_file := $(library_lists_dir)/vndkprivate.libraries.txt
+llndk_moved_to_apex_libraries_file := $(library_lists_dir)/llndkinapex.libraries.txt
ifeq ($(my_vndk_use_core_variant),true)
vndk_using_core_variant_libraries_file := $(library_lists_dir)/vndk_using_core_variant.libraries.$(vndk_version).txt
endif
@@ -65,6 +66,10 @@
vndksp_libraries_list := $(VNDK_SAMEPROCESS_LIBRARIES)
endif
+# LLNDK libraries that has been moved to an apex package and no longer are present on
+# /system image.
+llndk_libraries_moved_to_apex_list:=$(LLNDK_MOVED_TO_APEX_LIBRARIES)
+
# $(1): list of libraries
# $(2): output file to write the list of libraries to
define write-libs-to-file
@@ -91,6 +96,14 @@
while read -r privatelib; do sed -i.bak "s/$$privatelib//" $(2) ; done < $(PRIVATE_VNDK_PRIVATE_LIBRARIES_FILE) && \
sed -i.bak -e 's/::\+/:/g ; s/^:\+// ; s/:\+$$//' $(2) && \
rm -f $(2).bak
+
+# # Given a file with a list of libs in "a:b:c" format, filter-out the LLNDK libraries migrated into apex file
+# # and write resulting list to a new file in "a:b:c" format
+ $(LOCAL_BUILT_MODULE): private-filter-out-llndk-in-apex-libs = \
+ for lib in $(PRIVATE_LLNDK_LIBRARIES_MOVED_TO_APEX_LIST); do sed -i.bak s/$$lib.so// $(1); done && \
+ sed -i.bak -e 's/::\+/:/g ; s/^:\+// ; s/:\+$$//' $(1) && \
+ rm -f $(1).bak
+
$(LOCAL_BUILT_MODULE): PRIVATE_LLNDK_LIBRARIES_FILE := $(llndk_libraries_file)
$(LOCAL_BUILT_MODULE): PRIVATE_VNDK_SP_LIBRARIES_FILE := $(vndksp_libraries_file)
$(LOCAL_BUILT_MODULE): PRIVATE_VNDK_CORE_LIBRARIES_FILE := $(vndkcore_libraries_file)
@@ -100,6 +113,7 @@
$(LOCAL_BUILT_MODULE): PRIVATE_INTERMEDIATES_DIR := $(intermediates_dir)
$(LOCAL_BUILT_MODULE): PRIVATE_COMP_CHECK_SCRIPT := $(compatibility_check_script)
$(LOCAL_BUILT_MODULE): PRIVATE_VNDK_VERSION_TAG := \#VNDK$(vndk_version)\#
+$(LOCAL_BUILT_MODULE): PRIVATE_LLNDK_LIBRARIES_MOVED_TO_APEX_LIST := $(llndk_libraries_moved_to_apex_list)
deps := $(llndk_libraries_file) $(vndksp_libraries_file) $(vndkcore_libraries_file) \
$(vndkprivate_libraries_file)
ifeq ($(check_backward_compatibility),true)
@@ -118,6 +132,7 @@
endif
@mkdir -p $(dir $@)
$(call private-filter-out-private-libs,$(PRIVATE_LLNDK_LIBRARIES_FILE),$(PRIVATE_INTERMEDIATES_DIR)/llndk_filtered)
+ $(call private-filter-out-llndk-in-apex-libs,$(PRIVATE_INTERMEDIATES_DIR)/llndk_filtered)
$(hide) sed -e "s?%LLNDK_LIBRARIES%?$$(cat $(PRIVATE_INTERMEDIATES_DIR)/llndk_filtered)?g" $< >$@
$(call private-filter-out-private-libs,$(PRIVATE_VNDK_SP_LIBRARIES_FILE),$(PRIVATE_INTERMEDIATES_DIR)/vndksp_filtered)
$(hide) sed -i.bak -e "s?%VNDK_SAMEPROCESS_LIBRARIES%?$$(cat $(PRIVATE_INTERMEDIATES_DIR)/vndksp_filtered)?g" $@
@@ -162,6 +177,7 @@
intermediates_dir :=
library_lists_dir :=
llndk_libraries_file :=
+llndk_moved_to_apex_libraries_file :=
vndksp_libraries_file :=
vndkcore_libraries_file :=
vndkprivate_libraries_file :=