Merge "Decrease size of LogBufferElements to 32 bytes." am: 44ad937411 am: e23b30a6da am: 90c25cbdd3
am: 784d6626fb
Change-Id: I39013185503abfc5872c4746f0d6e0461e5d8b7b
diff --git a/base/Android.bp b/base/Android.bp
index 1395756..82aee2a 100644
--- a/base/Android.bp
+++ b/base/Android.bp
@@ -40,6 +40,10 @@
name: "libbase",
vendor_available: true,
host_supported: true,
+ vndk: {
+ enabled: true,
+ support_system_process: true,
+ },
srcs: [
"file.cpp",
"logging.cpp",
diff --git a/fs_mgr/Android.mk b/fs_mgr/Android.mk
index 18ccc43..007189d 100644
--- a/fs_mgr/Android.mk
+++ b/fs_mgr/Android.mk
@@ -20,6 +20,7 @@
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_MODULE:= fs_mgr
LOCAL_MODULE_TAGS := optional
+LOCAL_REQUIRED_MODULES := mke2fs mke2fs.conf e2fsdroid
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/sbin
LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)
diff --git a/fs_mgr/fs_mgr_format.cpp b/fs_mgr/fs_mgr_format.cpp
index a03d92c..fc88217 100644
--- a/fs_mgr/fs_mgr_format.cpp
+++ b/fs_mgr/fs_mgr_format.cpp
@@ -24,21 +24,16 @@
#include <cutils/partition_utils.h>
#include <sys/mount.h>
-#include <ext4_utils/ext4_utils.h>
#include <ext4_utils/ext4.h>
-#include <ext4_utils/make_ext4fs.h>
-#include <selinux/selinux.h>
-#include <selinux/label.h>
+#include <ext4_utils/ext4_utils.h>
+#include <logwrap/logwrap.h>
#include <selinux/android.h>
+#include <selinux/label.h>
+#include <selinux/selinux.h>
#include "fs_mgr_priv.h"
#include "cryptfs.h"
-extern "C" {
-extern struct fs_info info; /* magic global from ext4_utils */
-extern void reset_ext4fs_info();
-}
-
static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer)
{
uint64_t dev_sz;
@@ -55,30 +50,36 @@
return -1;
}
- struct selabel_handle *sehandle = selinux_android_file_context_handle();
- if (!sehandle) {
- /* libselinux logs specific error */
- LERROR << "Cannot initialize android file_contexts";
- close(fd);
- return -1;
- }
-
- /* Format the partition using the calculated length */
- reset_ext4fs_info();
- info.len = (off64_t)dev_sz;
- if (crypt_footer) {
- info.len -= CRYPT_FOOTER_OFFSET;
- }
-
- /* Use make_ext4fs_internal to avoid wiping an already-wiped partition. */
- rc = make_ext4fs_internal(fd, NULL, NULL, fs_mnt_point, 0, 0, 0, 0, 0, 0, sehandle, 0, 0, NULL, NULL, NULL);
- if (rc) {
- LERROR << "make_ext4fs returned " << rc;
- }
close(fd);
- if (sehandle) {
- selabel_close(sehandle);
+ /* Format the partition using the calculated length */
+ if (crypt_footer) {
+ dev_sz -= CRYPT_FOOTER_OFFSET;
+ }
+
+ std::string size_str = std::to_string(dev_sz / 4096);
+ const char* const mke2fs_args[] = {
+ "/system/bin/mke2fs", "-t", "ext4", "-b", "4096", fs_blkdev, size_str.c_str(), nullptr};
+
+ rc = android_fork_execvp_ext(arraysize(mke2fs_args), const_cast<char**>(mke2fs_args), NULL,
+ true, LOG_KLOG, true, nullptr, nullptr, 0);
+ if (rc) {
+ LERROR << "mke2fs returned " << rc;
+ return rc;
+ }
+
+ const char* const e2fsdroid_args[] = {
+ "/system/bin/e2fsdroid",
+ "-e",
+ "-a",
+ fs_mnt_point,
+ fs_blkdev,
+ nullptr};
+
+ rc = android_fork_execvp_ext(arraysize(e2fsdroid_args), const_cast<char**>(e2fsdroid_args),
+ NULL, true, LOG_KLOG, true, nullptr, nullptr, 0);
+ if (rc) {
+ LERROR << "e2fsdroid returned " << rc;
}
return rc;
@@ -86,44 +87,10 @@
static int format_f2fs(char *fs_blkdev)
{
- char * args[5];
- int pid;
- int rc = 0;
+ const char* const args[] = {"/system/bin/make_f2fs", "-f", "-O encrypt", fs_blkdev, nullptr};
- args[0] = (char *)"/system/bin/make_f2fs";
- args[1] = (char *)"-f";
- args[2] = (char *)"-O encrypt";
- args[3] = fs_blkdev;
- args[4] = (char *)0;
-
- pid = fork();
- if (pid < 0) {
- return pid;
- }
- if (!pid) {
- /* This doesn't return */
- execv(args[0], args);
- exit(1);
- }
- for(;;) {
- pid_t p = waitpid(pid, &rc, 0);
- if (p != pid) {
- LERROR << "Error waiting for child process - " << p;
- rc = -1;
- break;
- }
- if (WIFEXITED(rc)) {
- rc = WEXITSTATUS(rc);
- LINFO << args[0] << " done, status " << rc;
- if (rc) {
- rc = -1;
- }
- break;
- }
- LERROR << "Still waiting for " << args[0] << "...";
- }
-
- return rc;
+ return android_fork_execvp_ext(arraysize(args), const_cast<char**>(args), NULL, true,
+ LOG_KLOG, true, nullptr, nullptr, 0);
}
int fs_mgr_do_format(struct fstab_rec *fstab, bool crypt_footer)
diff --git a/gatekeeperd/Android.mk b/gatekeeperd/Android.mk
index 0dfd9d8..28f0b07 100644
--- a/gatekeeperd/Android.mk
+++ b/gatekeeperd/Android.mk
@@ -21,8 +21,7 @@
LOCAL_SRC_FILES := \
SoftGateKeeperDevice.cpp \
IGateKeeperService.cpp \
- gatekeeperd.cpp \
- IUserManager.cpp
+ gatekeeperd.cpp
LOCAL_MODULE := gatekeeperd
LOCAL_SHARED_LIBRARIES := \
diff --git a/gatekeeperd/IUserManager.cpp b/gatekeeperd/IUserManager.cpp
deleted file mode 100644
index 8167d19..0000000
--- a/gatekeeperd/IUserManager.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#define LOG_TAG "IUserManager"
-#include <stdint.h>
-#include <sys/types.h>
-#include <utils/Log.h>
-#include <binder/Parcel.h>
-
-#include "IUserManager.h"
-
-namespace android {
-
-class BpUserManager : public BpInterface<IUserManager>
-{
-public:
- explicit BpUserManager(const sp<IBinder>& impl) :
- BpInterface<IUserManager>(impl) {
- }
- virtual int32_t getCredentialOwnerProfile(int32_t user_id) {
- Parcel data, reply;
- data.writeInterfaceToken(IUserManager::getInterfaceDescriptor());
- data.writeInt32(user_id);
- status_t rc = remote()->transact(GET_CREDENTIAL_OWNER_PROFILE, data, &reply, 0);
- if (rc != NO_ERROR) {
- ALOGE("%s: failed (%d)\n", __func__, rc);
- return -1;
- }
-
- int32_t exception = reply.readExceptionCode();
- if (exception != 0) {
- ALOGE("%s: got exception (%d)\n", __func__, exception);
- return -1;
- }
-
- return reply.readInt32();
- }
-
-};
-
-IMPLEMENT_META_INTERFACE(UserManager, "android.os.IUserManager");
-
-}; // namespace android
-
diff --git a/gatekeeperd/IUserManager.h b/gatekeeperd/IUserManager.h
deleted file mode 100644
index 640e9b5..0000000
--- a/gatekeeperd/IUserManager.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-#ifndef IUSERMANAGER_H_
-#define IUSERMANAGER_H_
-
-#include <inttypes.h>
-#include <utils/Errors.h>
-#include <binder/IInterface.h>
-#include <binder/Parcel.h>
-#include <utils/Vector.h>
-
-namespace android {
-
-/*
-* Communication channel to UserManager
-*/
-class IUserManager : public IInterface {
- public:
- // must be kept in sync with IUserManager.aidl
- enum {
- GET_CREDENTIAL_OWNER_PROFILE = IBinder::FIRST_CALL_TRANSACTION + 0,
- };
-
- virtual int32_t getCredentialOwnerProfile(int32_t user_id) = 0;
-
- DECLARE_META_INTERFACE(UserManager);
-};
-
-}; // namespace android
-
-#endif // IUSERMANAGER_H_
-
diff --git a/gatekeeperd/gatekeeperd.cpp b/gatekeeperd/gatekeeperd.cpp
index c6369f9..184c6d2 100644
--- a/gatekeeperd/gatekeeperd.cpp
+++ b/gatekeeperd/gatekeeperd.cpp
@@ -37,7 +37,6 @@
#include <utils/String16.h>
#include "SoftGateKeeperDevice.h"
-#include "IUserManager.h"
#include <hidl/HidlSupport.h>
#include <android/hardware/gatekeeper/1.0/IGatekeeper.h>
@@ -334,23 +333,7 @@
return ret;
}
- virtual uint64_t getSecureUserId(uint32_t uid) {
- uint64_t sid = read_sid(uid);
- if (sid == 0) {
- // might be a work profile, look up the parent
- sp<IServiceManager> sm = defaultServiceManager();
- sp<IBinder> binder = sm->getService(String16("user"));
- sp<IUserManager> um = interface_cast<IUserManager>(binder);
- int32_t parent = um->getCredentialOwnerProfile(uid);
- if (parent < 0) {
- return 0;
- } else if (parent != (int32_t) uid) {
- return read_sid(parent);
- }
- }
- return sid;
-
- }
+ virtual uint64_t getSecureUserId(uint32_t uid) { return read_sid(uid); }
virtual void clearSecureUserId(uint32_t uid) {
IPCThreadState* ipc = IPCThreadState::self();
diff --git a/healthd/Android.bp b/healthd/Android.bp
new file mode 100644
index 0000000..56f5148
--- /dev/null
+++ b/healthd/Android.bp
@@ -0,0 +1,7 @@
+cc_library_headers {
+ name: "libhealthd_headers",
+ vendor_available: true,
+ export_include_dirs: ["include"],
+ header_libs: ["libbatteryservice_headers"],
+ export_header_lib_headers: ["libbatteryservice_headers"],
+}
diff --git a/init/selinux.cpp b/init/selinux.cpp
index 32bb3dc..b29685b 100644
--- a/init/selinux.cpp
+++ b/init/selinux.cpp
@@ -381,7 +381,6 @@
selinux_android_restorecon("/dev/urandom", 0);
selinux_android_restorecon("/dev/__properties__", 0);
- selinux_android_restorecon("/file_contexts.bin", 0);
selinux_android_restorecon("/plat_file_contexts", 0);
selinux_android_restorecon("/nonplat_file_contexts", 0);
selinux_android_restorecon("/plat_property_contexts", 0);
diff --git a/libappfuse/FuseBridgeLoop.cc b/libappfuse/FuseBridgeLoop.cc
index 0792307..8b0c53e 100644
--- a/libappfuse/FuseBridgeLoop.cc
+++ b/libappfuse/FuseBridgeLoop.cc
@@ -179,7 +179,11 @@
}
const uint32_t opcode = buffer_.request.header.opcode;
- LOG(VERBOSE) << "Read a fuse packet, opcode=" << opcode;
+ const uint64_t unique = buffer_.request.header.unique;
+ LOG(VERBOSE) << "Read a fuse packet, opcode=" << opcode << " unique=" << unique;
+ if (unique == 0) {
+ return FuseBridgeState::kWaitToReadEither;
+ }
switch (opcode) {
case FUSE_FORGET:
// Do not reply to FUSE_FORGET.
diff --git a/libappfuse/tests/FuseBridgeLoopTest.cc b/libappfuse/tests/FuseBridgeLoopTest.cc
index 51d6051..0a28451 100644
--- a/libappfuse/tests/FuseBridgeLoopTest.cc
+++ b/libappfuse/tests/FuseBridgeLoopTest.cc
@@ -67,6 +67,7 @@
memset(&request_, 0, sizeof(FuseRequest));
request_.header.opcode = opcode;
request_.header.len = sizeof(fuse_in_header);
+ request_.header.unique = 1;
ASSERT_TRUE(request_.Write(dev_sockets_[0]));
memset(&response_, 0, sizeof(FuseResponse));
diff --git a/libbacktrace/Android.bp b/libbacktrace/Android.bp
index c58d777..02e0487 100644
--- a/libbacktrace/Android.bp
+++ b/libbacktrace/Android.bp
@@ -66,6 +66,10 @@
cc_library {
name: "libbacktrace",
vendor_available: true,
+ vndk: {
+ enabled: true,
+ support_system_process: true,
+ },
defaults: ["libbacktrace_common"],
host_supported: true,
diff --git a/libcrypto_utils/Android.bp b/libcrypto_utils/Android.bp
index 4a5f2a7..47de12a 100644
--- a/libcrypto_utils/Android.bp
+++ b/libcrypto_utils/Android.bp
@@ -17,6 +17,9 @@
cc_library {
name: "libcrypto_utils",
vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
host_supported: true,
srcs: [
"android_pubkey.c",
diff --git a/libcutils/Android.bp b/libcutils/Android.bp
index 8528a4b..cfe8d29 100644
--- a/libcutils/Android.bp
+++ b/libcutils/Android.bp
@@ -50,6 +50,10 @@
cc_library {
name: "libcutils",
vendor_available: true,
+ vndk: {
+ enabled: true,
+ support_system_process: true,
+ },
host_supported: true,
srcs: [
"config_utils.c",
diff --git a/libdiskconfig/Android.bp b/libdiskconfig/Android.bp
index 088981a..23a5c79 100644
--- a/libdiskconfig/Android.bp
+++ b/libdiskconfig/Android.bp
@@ -1,6 +1,9 @@
cc_library {
name: "libdiskconfig",
vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
srcs: [
"diskconfig.c",
"diskutils.c",
diff --git a/libion/Android.bp b/libion/Android.bp
index 6f267e4..6d9fae0 100644
--- a/libion/Android.bp
+++ b/libion/Android.bp
@@ -1,7 +1,11 @@
cc_library {
name: "libion",
- vendor_available: true,
+ vendor_available: true,
+ vndk: {
+ enabled: true,
+ support_system_process: true,
+ },
srcs: ["ion.c"],
shared_libs: ["liblog"],
local_include_dirs: [
diff --git a/liblog/Android.bp b/liblog/Android.bp
index e74aa82..b98d18f 100644
--- a/liblog/Android.bp
+++ b/liblog/Android.bp
@@ -42,6 +42,24 @@
"logd_writer.c",
]
+cc_library_headers {
+ name: "liblog_headers",
+ host_supported: true,
+ vendor_available: true,
+ export_include_dirs: ["include"],
+ target: {
+ windows: {
+ enabled: true,
+ },
+ linux_bionic: {
+ enabled: true,
+ },
+ vendor: {
+ export_include_dirs: ["include_vndk"],
+ },
+ },
+}
+
// Shared and static library for host and device
// ========================================================
cc_library {
@@ -81,7 +99,8 @@
},
},
- export_include_dirs: ["include"],
+ header_libs: ["liblog_headers"],
+ export_header_lib_headers: ["liblog_headers"],
cflags: [
"-Werror",
@@ -100,7 +119,7 @@
}
ndk_headers {
- name: "liblog_headers",
+ name: "liblog_ndk_headers",
from: "include/android",
to: "android",
srcs: ["include/android/log.h"],
diff --git a/liblog/include/log/log_main.h b/liblog/include/log/log_main.h
index 5a3f04c..339a06d 100644
--- a/liblog/include/log/log_main.h
+++ b/liblog/include/log/log_main.h
@@ -18,10 +18,9 @@
#define _LIBS_LOG_LOG_MAIN_H
#include <android/log.h>
+#include <sys/cdefs.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
+__BEGIN_DECLS
/*
* Normally we strip the effects of ALOGV (VERBOSE messages),
@@ -385,8 +384,6 @@
#pragma clang diagnostic pop
#endif
-#ifdef __cplusplus
-}
-#endif
+__END_DECLS
#endif /* _LIBS_LOG_LOG_MAIN_H */
diff --git a/liblog/tests/Android.mk b/liblog/tests/Android.mk
index ab96429..91044ab 100644
--- a/liblog/tests/Android.mk
+++ b/liblog/tests/Android.mk
@@ -89,7 +89,7 @@
LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
LOCAL_SHARED_LIBRARIES := liblog libcutils libbase
LOCAL_STATIC_LIBRARIES := libgtest libgtest_main
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts vts
LOCAL_CTS_TEST_PACKAGE := android.core.liblog
include $(BUILD_CTS_EXECUTABLE)
diff --git a/libmemtrack/Android.bp b/libmemtrack/Android.bp
index 68c580a..0955633 100644
--- a/libmemtrack/Android.bp
+++ b/libmemtrack/Android.bp
@@ -2,6 +2,10 @@
cc_library_shared {
name: "libmemtrack",
+ vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
srcs: ["memtrack.cpp"],
export_include_dirs: ["include"],
local_include_dirs: ["include"],
diff --git a/libnetutils/Android.bp b/libnetutils/Android.bp
index 9967ef8..1d43775 100644
--- a/libnetutils/Android.bp
+++ b/libnetutils/Android.bp
@@ -1,6 +1,9 @@
cc_library_shared {
name: "libnetutils",
vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
srcs: [
"dhcpclient.c",
diff --git a/libprocinfo/Android.bp b/libprocinfo/Android.bp
index aedaa38..b568ee5 100644
--- a/libprocinfo/Android.bp
+++ b/libprocinfo/Android.bp
@@ -23,6 +23,9 @@
cc_library {
name: "libprocinfo",
vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
host_supported: true,
srcs: [
"process.cpp",
diff --git a/libsuspend/Android.bp b/libsuspend/Android.bp
index 130800e..32f1e1f 100644
--- a/libsuspend/Android.bp
+++ b/libsuspend/Android.bp
@@ -3,6 +3,9 @@
cc_library {
name: "libsuspend",
vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
srcs: [
"autosuspend.c",
diff --git a/libsync/Android.bp b/libsync/Android.bp
index 1646348..3fae5e6 100644
--- a/libsync/Android.bp
+++ b/libsync/Android.bp
@@ -22,10 +22,15 @@
cc_library_shared {
name: "libsync",
- vendor_available: true,
defaults: ["libsync_defaults"],
}
+llndk_library {
+ name: "libsync",
+ symbol_file: "libsync.map.txt",
+ export_include_dirs: ["include"],
+}
+
// libsync_recovery is only intended for the recovery binary.
// Future versions of the kernel WILL require an updated libsync, and will break
// anything statically linked against the current libsync.
diff --git a/libsync/libsync.map.txt b/libsync/libsync.map.txt
index daa28ae..53bb07a 100644
--- a/libsync/libsync.map.txt
+++ b/libsync/libsync.map.txt
@@ -17,16 +17,12 @@
LIBSYNC {
global:
sync_merge; # introduced=26
- sync_get_fence_info; # introduced=26
- sync_free_fence_info; # introduced=26
+ sync_file_info; # introduced=26
+ sync_file_info_free; # introduced=26
+ sync_wait; # vndk
+ sync_fence_info; # vndk
+ sync_pt_info; # vndk
+ sync_fence_info_free; # vndk
local:
*;
};
-
-LIBSYNC_PLATFORM {
- global:
- sync_wait;
- sync_fence_info;
- sync_pt_info;
- sync_fence_info_free;
-} LIBSYNC_PLATFORM;
diff --git a/libsync/sync.c b/libsync/sync.c
index baeccda..0950082 100644
--- a/libsync/sync.c
+++ b/libsync/sync.c
@@ -217,6 +217,8 @@
local_info.num_fences * sizeof(struct sync_fence_info));
if (!info)
return NULL;
+
+ info->num_fences = local_info.num_fences;
info->sync_fence_info = (__u64)(uintptr_t)(info + 1);
err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
diff --git a/libsysutils/Android.bp b/libsysutils/Android.bp
index 550ef42..d076a1a 100644
--- a/libsysutils/Android.bp
+++ b/libsysutils/Android.bp
@@ -1,6 +1,9 @@
cc_library_shared {
name: "libsysutils",
vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
srcs: [
"src/SocketListener.cpp",
diff --git a/libusbhost/Android.bp b/libusbhost/Android.bp
index a0d6b9b..fc6f305 100644
--- a/libusbhost/Android.bp
+++ b/libusbhost/Android.bp
@@ -16,6 +16,10 @@
cc_library {
name: "libusbhost",
+ vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
host_supported: true,
srcs: ["usbhost.c"],
cflags: ["-Werror"],
diff --git a/libutils/Android.bp b/libutils/Android.bp
index 7d293ef..6e9bddf 100644
--- a/libutils/Android.bp
+++ b/libutils/Android.bp
@@ -18,10 +18,12 @@
host_supported: true,
header_libs: [
+ "liblog_headers",
"libsystem_headers",
"libcutils_headers"
],
export_header_lib_headers: [
+ "liblog_headers",
"libsystem_headers",
"libcutils_headers"
],
@@ -44,6 +46,10 @@
cc_library {
name: "libutils",
vendor_available: true,
+ vndk: {
+ enabled: true,
+ support_system_process: true,
+ },
host_supported: true,
srcs: [
@@ -78,6 +84,10 @@
"libutils_headers",
],
+ shared_libs: [
+ "liblog",
+ ],
+
arch: {
mips: {
cflags: ["-DALIGN_DOUBLE"],
@@ -98,7 +108,6 @@
"libbacktrace",
"libcutils",
"libdl",
- "liblog",
"libvndksupport",
],
diff --git a/libvndksupport/linker.c b/libvndksupport/linker.c
index 696e978..703b593 100644
--- a/libvndksupport/linker.c
+++ b/libvndksupport/linker.c
@@ -32,14 +32,13 @@
void* handle = android_dlopen_ext(name, flag, &dlextinfo);
if (!handle) {
ALOGE(
- "Could not load %s from sphal namespace: %s. ",
+ "Could not load %s from sphal namespace: %s.",
name, dlerror());
}
return handle;
} else {
- ALOGI(
- "sphal namespace is not configured for this process. "
- "Loading %s from the current namespace instead.",
+ ALOGD(
+ "Loading %s from current namespace instead of sphal namespace.",
name);
return dlopen(name, flag);
}
diff --git a/libziparchive/Android.bp b/libziparchive/Android.bp
index 333835c..f395c74 100644
--- a/libziparchive/Android.bp
+++ b/libziparchive/Android.bp
@@ -58,6 +58,9 @@
name: "libziparchive",
host_supported: true,
vendor_available: true,
+ vndk: {
+ enabled: true,
+ },
defaults: [
"libziparchive_defaults",
diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c
index 8a6168c..02a9601 100644
--- a/lmkd/lmkd.c
+++ b/lmkd/lmkd.c
@@ -31,6 +31,7 @@
#include <sys/types.h>
#include <unistd.h>
+#include <cutils/properties.h>
#include <cutils/sockets.h>
#include <log/log.h>
#include <processgroup/processgroup.h>
@@ -40,7 +41,8 @@
#endif
#define MEMCG_SYSFS_PATH "/dev/memcg/"
-#define MEMPRESSURE_WATCH_LEVEL "low"
+#define MEMPRESSURE_WATCH_MEDIUM_LEVEL "medium"
+#define MEMPRESSURE_WATCH_CRITICAL_LEVEL "critical"
#define ZONEINFO_PATH "/proc/zoneinfo"
#define LINE_MAX 128
@@ -48,6 +50,7 @@
#define INKERNEL_ADJ_PATH "/sys/module/lowmemorykiller/parameters/adj"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
+#define EIGHT_MEGA (1 << 23)
enum lmk_cmd {
LMK_TARGET,
@@ -66,15 +69,21 @@
static int use_inkernel_interface = 1;
/* memory pressure level medium event */
-static int mpevfd;
+static int mpevfd[2];
+#define CRITICAL_INDEX 1
+#define MEDIUM_INDEX 0
+
+static int medium_oomadj;
+static int critical_oomadj;
+static int debug_process_killing;
/* control socket listen and data */
static int ctrl_lfd;
static int ctrl_dfd = -1;
static int ctrl_dfd_reopened; /* did we reopen ctrl conn on this loop? */
-/* 1 memory pressure level, 1 ctrl listen socket, 1 ctrl data socket */
-#define MAX_EPOLL_EVENTS 3
+/* 2 memory pressure levels, 1 ctrl listen socket, 1 ctrl data socket */
+#define MAX_EPOLL_EVENTS 4
static int epollfd;
static int maxevents;
@@ -113,14 +122,6 @@
#define ADJTOSLOT(adj) ((adj) + -OOM_SCORE_ADJ_MIN)
static struct adjslot_list procadjslot_list[ADJTOSLOT(OOM_SCORE_ADJ_MAX) + 1];
-/*
- * Wait 1-2 seconds for the death report of a killed process prior to
- * considering killing more processes.
- */
-#define KILL_TIMEOUT 2
-/* Time of last process kill we initiated, stop me before I kill again */
-static time_t kill_lasttime;
-
/* PAGE_SIZE / 1024 */
static long page_k;
@@ -241,6 +242,7 @@
struct proc *procp;
char path[80];
char val[20];
+ int soft_limit_mult;
if (oomadj < OOM_SCORE_ADJ_MIN || oomadj > OOM_SCORE_ADJ_MAX) {
ALOGE("Invalid PROCPRIO oomadj argument %d", oomadj);
@@ -254,6 +256,38 @@
if (use_inkernel_interface)
return;
+ if (oomadj >= 900) {
+ soft_limit_mult = 0;
+ } else if (oomadj >= 800) {
+ soft_limit_mult = 0;
+ } else if (oomadj >= 700) {
+ soft_limit_mult = 0;
+ } else if (oomadj >= 600) {
+ // Launcher should be perceptible, don't kill it.
+ oomadj = 200;
+ soft_limit_mult = 1;
+ } else if (oomadj >= 500) {
+ soft_limit_mult = 0;
+ } else if (oomadj >= 400) {
+ soft_limit_mult = 0;
+ } else if (oomadj >= 300) {
+ soft_limit_mult = 1;
+ } else if (oomadj >= 200) {
+ soft_limit_mult = 2;
+ } else if (oomadj >= 100) {
+ soft_limit_mult = 10;
+ } else if (oomadj >= 0) {
+ soft_limit_mult = 20;
+ } else {
+ // Persistent processes will have a large
+ // soft limit 512MB.
+ soft_limit_mult = 64;
+ }
+
+ snprintf(path, sizeof(path), "/dev/memcg/apps/uid_%d/pid_%d/memory.soft_limit_in_bytes", uid, pid);
+ snprintf(val, sizeof(val), "%d", soft_limit_mult * EIGHT_MEGA);
+ writefilestring(path, val);
+
procp = pid_lookup(pid);
if (!procp) {
procp = malloc(sizeof(struct proc));
@@ -278,7 +312,6 @@
return;
pid_remove(pid);
- kill_lasttime = 0;
}
static void cmd_target(int ntargets, int *params) {
@@ -546,9 +579,7 @@
}
/* Kill one process specified by procp. Returns the size of the process killed */
-static int kill_one_process(struct proc *procp, int other_free, int other_file,
- int minfree, int min_score_adj, bool first)
-{
+static int kill_one_process(struct proc* procp, int min_score_adj, bool is_critical) {
int pid = procp->pid;
uid_t uid = procp->uid;
char *taskname;
@@ -567,14 +598,12 @@
return -1;
}
- ALOGI("Killing '%s' (%d), uid %d, adj %d\n"
- " to free %ldkB because cache %s%ldkB is below limit %ldkB for oom_adj %d\n"
- " Free memory is %s%ldkB %s reserved",
- taskname, pid, uid, procp->oomadj, tasksize * page_k,
- first ? "" : "~", other_file * page_k, minfree * page_k, min_score_adj,
- first ? "" : "~", other_free * page_k, other_free >= 0 ? "above" : "below");
+ ALOGI(
+ "Killing '%s' (%d), uid %d, adj %d\n"
+ " to free %ldkB because system is under %s memory pressure oom_adj %d\n",
+ taskname, pid, uid, procp->oomadj, tasksize * page_k, is_critical ? "critical" : "medium",
+ min_score_adj);
r = kill(pid, SIGKILL);
- killProcessGroup(uid, pid, SIGKILL);
pid_remove(pid);
if (r) {
@@ -589,24 +618,10 @@
* Find a process to kill based on the current (possibly estimated) free memory
* and cached memory sizes. Returns the size of the killed processes.
*/
-static int find_and_kill_process(int other_free, int other_file, bool first)
-{
+static int find_and_kill_process(int min_score_adj, bool is_critical) {
int i;
- int min_score_adj = OOM_SCORE_ADJ_MAX + 1;
- int minfree = 0;
int killed_size = 0;
- for (i = 0; i < lowmem_targets_size; i++) {
- minfree = lowmem_minfree[i];
- if (other_free < minfree && other_file < minfree) {
- min_score_adj = lowmem_adj[i];
- break;
- }
- }
-
- if (min_score_adj == OOM_SCORE_ADJ_MAX + 1)
- return 0;
-
for (i = OOM_SCORE_ADJ_MAX; i >= min_score_adj; i--) {
struct proc *procp;
@@ -614,7 +629,7 @@
procp = proc_adj_lru(i);
if (procp) {
- killed_size = kill_one_process(procp, other_free, other_file, minfree, min_score_adj, first);
+ killed_size = kill_one_process(procp, min_score_adj, is_critical);
if (killed_size < 0) {
goto retry;
} else {
@@ -626,42 +641,33 @@
return 0;
}
-static void mp_event(uint32_t events __unused) {
+static void mp_event_common(bool is_critical) {
int ret;
unsigned long long evcount;
- struct sysmeminfo mi;
- int other_free;
- int other_file;
- int killed_size;
- bool first = true;
+ int min_adj_score = is_critical ? critical_oomadj : medium_oomadj;
+ int index = is_critical ? CRITICAL_INDEX : MEDIUM_INDEX;
- ret = read(mpevfd, &evcount, sizeof(evcount));
+ ret = read(mpevfd[index], &evcount, sizeof(evcount));
if (ret < 0)
ALOGE("Error reading memory pressure event fd; errno=%d",
errno);
- if (time(NULL) - kill_lasttime < KILL_TIMEOUT)
- return;
-
- while (zoneinfo_parse(&mi) < 0) {
- // Failed to read /proc/zoneinfo, assume ENOMEM and kill something
- find_and_kill_process(0, 0, true);
- }
-
- other_free = mi.nr_free_pages - mi.totalreserve_pages;
- other_file = mi.nr_file_pages - mi.nr_shmem;
-
- do {
- killed_size = find_and_kill_process(other_free, other_file, first);
- if (killed_size > 0) {
- first = false;
- other_free += killed_size;
- other_file += killed_size;
+ if (find_and_kill_process(min_adj_score, is_critical) == 0) {
+ if (debug_process_killing) {
+ ALOGI("Nothing to kill");
}
- } while (killed_size > 0);
+ }
}
-static int init_mp(char *levelstr, void *event_handler)
+static void mp_event(uint32_t events __unused) {
+ mp_event_common(false);
+}
+
+static void mp_event_critical(uint32_t events __unused) {
+ mp_event_common(true);
+}
+
+static int init_mp_common(char *levelstr, void *event_handler, bool is_critical)
{
int mpfd;
int evfd;
@@ -669,6 +675,7 @@
char buf[256];
struct epoll_event epev;
int ret;
+ int mpevfd_index = is_critical ? CRITICAL_INDEX : MEDIUM_INDEX;
mpfd = open(MEMCG_SYSFS_PATH "memory.pressure_level", O_RDONLY | O_CLOEXEC);
if (mpfd < 0) {
@@ -709,7 +716,7 @@
goto err;
}
maxevents++;
- mpevfd = evfd;
+ mpevfd[mpevfd_index] = evfd;
return 0;
err:
@@ -722,6 +729,16 @@
return -1;
}
+static int init_mp_medium()
+{
+ return init_mp_common(MEMPRESSURE_WATCH_MEDIUM_LEVEL, (void *)&mp_event, false);
+}
+
+static int init_mp_critical()
+{
+ return init_mp_common(MEMPRESSURE_WATCH_CRITICAL_LEVEL, (void *)&mp_event_critical, true);
+}
+
static int init(void) {
struct epoll_event epev;
int i;
@@ -763,7 +780,8 @@
if (use_inkernel_interface) {
ALOGI("Using in-kernel low memory killer interface");
} else {
- ret = init_mp(MEMPRESSURE_WATCH_LEVEL, (void *)&mp_event);
+ ret = init_mp_medium();
+ ret |= init_mp_critical();
if (ret)
ALOGE("Kernel does not support memory pressure events or in-kernel low memory killer");
}
@@ -806,6 +824,10 @@
.sched_priority = 1,
};
+ medium_oomadj = property_get_int32("ro.lmk.medium", 800);
+ critical_oomadj = property_get_int32("ro.lmk.critical", 0);
+ debug_process_killing = property_get_bool("ro.lmk.debug", false);
+
mlockall(MCL_FUTURE);
sched_setscheduler(0, SCHED_FIFO, ¶m);
if (!init())
diff --git a/logd/tests/Android.mk b/logd/tests/Android.mk
index 1915677..a0875ea 100644
--- a/logd/tests/Android.mk
+++ b/logd/tests/Android.mk
@@ -63,7 +63,7 @@
LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
LOCAL_SHARED_LIBRARIES := libbase libcutils liblog libselinux
LOCAL_STATIC_LIBRARIES := libgtest libgtest_main
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts vts
LOCAL_CTS_TEST_PACKAGE := android.core.logd
include $(BUILD_CTS_EXECUTABLE)
diff --git a/rootdir/Android.mk b/rootdir/Android.mk
index 2e5575f..046557e 100644
--- a/rootdir/Android.mk
+++ b/rootdir/Android.mk
@@ -194,7 +194,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := ld.config.txt
-ifeq ($(PRODUCT_FULL_TREBLE),true)
+ifeq ($(PRODUCT_FULL_TREBLE)|$(SANITIZE_TARGET),true|)
LOCAL_SRC_FILES := etc/ld.config.txt
else
LOCAL_SRC_FILES := etc/ld.config.legacy.txt
diff --git a/rootdir/etc/ld.config.txt b/rootdir/etc/ld.config.txt
index 56066bc..16db770 100644
--- a/rootdir/etc/ld.config.txt
+++ b/rootdir/etc/ld.config.txt
@@ -54,7 +54,7 @@
namespace.sphal.isolated = true
namespace.sphal.visible = true
namespace.sphal.search.paths = /vendor/${LIB}/egl:/vendor/${LIB}/hw:/vendor/${LIB}
-namespace.sphal.permitted.paths = /vendor/${LIB}
+namespace.sphal.permitted.paths = /vendor/${LIB}:/system/${LIB}/vndk-sp/hw
namespace.sphal.asan.search.paths = /data/asan/vendor/${LIB}/egl:/vendor/${LIB}/egl:/data/asan/vendor/${LIB}/hw:/vendor/${LIB}/hw:/data/asan/vendor/${LIB}:/vendor/${LIB}
namespace.sphal.asan.permitted.paths = /data/asan/vendor/${LIB}:/vendor/${LIB}
@@ -64,10 +64,10 @@
namespace.sphal.links = default,vndk,rs
# WARNING: only NDK libs can be listed here.
-namespace.sphal.link.default.shared_libs = libc.so:libz.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libGLESv1_CM.so:libGLESv2.so:libvndksupport.so
+namespace.sphal.link.default.shared_libs = libc.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libGLESv1_CM.so:libGLESv2.so:libvndksupport.so
# WARNING: only VNDK-SP libs can be listed here. DO NOT EDIT this line.
-namespace.sphal.link.vndk.shared_libs = android.hardware.renderscript@1.0.so:android.hardware.graphics.allocator@2.0.so:android.hardware.graphics.mapper@2.0.so:android.hardware.graphics.common@1.0.so:android.hidl.memory@1.0.so:libhwbinder.so:libbase.so:libcutils.so:libhardware.so:libhidlbase.so:libhidlmemory.so:libhidltransport.so:libion.so:libutils.so:libc++.so
+namespace.sphal.link.vndk.shared_libs = android.hardware.renderscript@1.0.so:android.hardware.graphics.allocator@2.0.so:android.hardware.graphics.mapper@2.0.so:android.hardware.graphics.common@1.0.so:android.hidl.memory@1.0.so:libhwbinder.so:libbase.so:libcutils.so:libhardware.so:libhidlbase.so:libhidlmemory.so:libhidltransport.so:libion.so:libutils.so:libc++.so:libz.so
# Renderscript gets separate namespace
namespace.sphal.link.rs.shared_libs = libRS_internal.so
@@ -88,8 +88,8 @@
namespace.rs.asan.permitted.paths = /data/asan/vendor/${LIB}:/vendor/${LIB}:/data
namespace.rs.links = default,vndk
-namespace.rs.link.default.shared_libs = libc.so:libz.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libGLESv1_CM.so:libGLESv2.so:libmediandk.so:libvndksupport.so
-namespace.rs.link.vndk.shared_libs = android.hardware.renderscript@1.0.so:android.hardware.graphics.allocator@2.0.so:android.hardware.graphics.mapper@2.0.so:android.hardware.graphics.common@1.0.so:android.hidl.memory@1.0.so:libhwbinder.so:libbase.so:libcutils.so:libhardware.so:libhidlbase.so:libhidlmemory.so:libhidltransport.so:libion.so:libutils.so:libc++.so
+namespace.rs.link.default.shared_libs = libc.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libGLESv1_CM.so:libGLESv2.so:libmediandk.so:libvndksupport.so:libft2.so
+namespace.rs.link.vndk.shared_libs = android.hardware.renderscript@1.0.so:android.hardware.graphics.allocator@2.0.so:android.hardware.graphics.mapper@2.0.so:android.hardware.graphics.common@1.0.so:android.hidl.memory@1.0.so:libhwbinder.so:libbase.so:libcutils.so:libhardware.so:libhidlbase.so:libhidlmemory.so:libhidltransport.so:libion.so:libutils.so:libc++.so:libz.so
###############################################################################
# "vndk" namespace
@@ -97,17 +97,17 @@
# This namespace is exclusively for vndk-sp libs.
###############################################################################
namespace.vndk.isolated = true
-namespace.vndk.search.paths = /vendor/${LIB}/vndk-sp:/system/${LIB}/vndk-sp:/vendor/${LIB}
+namespace.vndk.search.paths = /vendor/${LIB}/vndk-sp:/system/${LIB}/vndk-sp
namespace.vndk.permitted.paths = /vendor/${LIB}/hw:/vendor/${LIB}/egl
-namespace.vndk.asan.search.paths = /data/asan/vendor/${LIB}/vndk-sp:/vendor/${LIB}/vndk-sp:/data/asan/system/${LIB}/vndk-sp:/system/${LIB}/vndk-sp:/data/asan/vendor/${LIB}:/vendor/${LIB}
+namespace.vndk.asan.search.paths = /data/asan/vendor/${LIB}/vndk-sp:/vendor/${LIB}/vndk-sp:/data/asan/system/${LIB}/vndk-sp:/system/${LIB}/vndk-sp
namespace.vndk.asan.permitted.paths = /data/asan/vendor/${LIB}/hw:/vendor/${LIB}/hw:/data/asan/vendor/${LIB}/egl:/vendor/${LIB}/egl
# 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.link.default.shared_libs = android.hidl.memory@1.0-impl.so:libc.so:libz.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libvndksupport.so
+namespace.vndk.link.default.shared_libs = android.hidl.memory@1.0-impl.so:libc.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libvndksupport.so
###############################################################################
# Namespace config for vendor processes. In O, no restriction is enforced for
@@ -117,9 +117,9 @@
###############################################################################
[vendor]
namespace.default.isolated = false
-namespace.default.search.paths = /vendor/${LIB}:/vendor/${LIB}/vndk-sp:/system/${LIB}/vndk-sp:/system/${LIB}
+namespace.default.search.paths = /vendor/${LIB}/hw:/vendor/${LIB}/egl:/vendor/${LIB}:/system/${LIB}/vndk:/vendor/${LIB}/vndk-sp:/system/${LIB}/vndk-sp:/system/${LIB}
-namespace.default.asan.search.paths = /data/asan/vendor/${LIB}:/vendor/${LIB}:/data/asan/vendor/${LIB}/vndk-sp:/vendor/${LIB}/vndk-sp:/data/asan/system/${LIB}/vndk-sp:/system/${LIB}/vndk-sp:/data/asan/system/${LIB}:/system/${LIB}
+namespace.default.asan.search.paths = /data/asan/vendor/${LIB}/hw:/vendor/${LIB}/hw:/data/asan/vendor/${LIB}/egl:/vendor/${LIB}/egl:/data/asan/vendor/${LIB}:/vendor/${LIB}:/data/asan/system/${LIB}/vndk:/system/${LIB}/vndk:/data/asan/vendor/${LIB}/vndk-sp:/vendor/${LIB}/vndk-sp:/data/asan/system/${LIB}/vndk-sp:/system/${LIB}/vndk-sp:/data/asan/system/${LIB}:/system/${LIB}
###############################################################################
# Namespace config for tests. No VNDK restriction is enforced for these tests.
diff --git a/rootdir/etc/public.libraries.android.txt b/rootdir/etc/public.libraries.android.txt
index c5e149c..e20b95d 100644
--- a/rootdir/etc/public.libraries.android.txt
+++ b/rootdir/etc/public.libraries.android.txt
@@ -15,6 +15,7 @@
libmediandk.so
libm.so
libnativewindow.so
+libneuralnetworks.so
libOpenMAXAL.so
libOpenSLES.so
libRS.so
diff --git a/rootdir/etc/public.libraries.wear.txt b/rootdir/etc/public.libraries.wear.txt
index a4ca683..3c46094 100644
--- a/rootdir/etc/public.libraries.wear.txt
+++ b/rootdir/etc/public.libraries.wear.txt
@@ -15,6 +15,7 @@
libmediandk.so
libm.so
libnativewindow.so
+libneuralnetworks.so
libOpenMAXAL.so
libOpenSLES.so
libRS.so
diff --git a/storaged/Android.mk b/storaged/Android.mk
index 5e6a3c0..a1abe0f 100644
--- a/storaged/Android.mk
+++ b/storaged/Android.mk
@@ -9,7 +9,6 @@
libcutils \
liblog \
libsysutils \
- libpackagelistparser \
libbatteryservice \
include $(CLEAR_VARS)
diff --git a/storaged/include/storaged.h b/storaged/include/storaged.h
index 514798b..fa68406 100644
--- a/storaged/include/storaged.h
+++ b/storaged/include/storaged.h
@@ -256,6 +256,7 @@
uid_monitor mUidm;
time_t mStarttime;
sp<IBatteryPropertiesRegistrar> battery_properties;
+ std::unique_ptr<storage_info_t> storage_info;
public:
storaged_t(void);
~storaged_t() {}
@@ -285,6 +286,8 @@
void init_battery_service();
virtual void batteryPropertiesChanged(struct BatteryProperties props);
void binderDied(const wp<IBinder>& who);
+
+ void report_storage_info();
};
// Eventlog tag
diff --git a/storaged/include/storaged_info.h b/storaged/include/storaged_info.h
index 913c814..7d04c7a 100644
--- a/storaged/include/storaged_info.h
+++ b/storaged/include/storaged_info.h
@@ -27,39 +27,46 @@
class storage_info_t {
protected:
FRIEND_TEST(storaged_test, storage_info_t);
+ // emmc lifetime
uint16_t eol; // pre-eol (end of life) information
uint16_t lifetime_a; // device life time estimation (type A)
uint16_t lifetime_b; // device life time estimation (type B)
string version; // version string
+ // free space
+ const string userdata_path = "/data";
+ uint64_t userdata_total_kb;
+ uint64_t userdata_free_kb;
+
+ storage_info_t() : eol(0), lifetime_a(0), lifetime_b(0),
+ userdata_total_kb(0), userdata_free_kb(0) {}
void publish();
+ storage_info_t* s_info;
public:
- storage_info_t() : eol(0), lifetime_a(0), lifetime_b(0) {}
+ static storage_info_t* get_storage_info();
virtual ~storage_info_t() {}
- virtual bool report() = 0;
+ virtual void report() {};
+ void refresh();
};
class emmc_info_t : public storage_info_t {
private:
- const string emmc_sysfs = "/sys/bus/mmc/devices/mmc0:0001/";
- const string emmc_debugfs = "/d/mmc0/mmc0:0001/ext_csd";
- const char* emmc_ver_str[9] = {
- "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0", "5.1"
- };
-public:
- virtual ~emmc_info_t() {}
- bool report();
bool report_sysfs();
bool report_debugfs();
+public:
+ static const string emmc_sysfs;
+ static const string emmc_debugfs;
+ static const char* emmc_ver_str[];
+
+ virtual ~emmc_info_t() {}
+ virtual void report();
};
class ufs_info_t : public storage_info_t {
-private:
- const string health_file = "/sys/devices/soc/624000.ufshc/health";
public:
- virtual ~ufs_info_t() {}
- bool report();
-};
+ static const string health_file;
-void report_storage_health();
+ virtual ~ufs_info_t() {}
+ virtual void report();
+};
#endif /* _STORAGED_INFO_H_ */
diff --git a/storaged/main.cpp b/storaged/main.cpp
index 4d1e430..6b82904 100644
--- a/storaged/main.cpp
+++ b/storaged/main.cpp
@@ -49,6 +49,7 @@
storaged = new storaged_t();
storaged->init_battery_service();
+ storaged->report_storage_info();
LOG_TO(SYSTEM, INFO) << "storaged: Start";
@@ -113,7 +114,6 @@
}
if (flag_main_service) { // start main thread
- report_storage_health();
// Start the main thread of storaged
pthread_t storaged_main_thread;
errno = pthread_create(&storaged_main_thread, NULL, storaged_main, NULL);
diff --git a/storaged/storaged.cpp b/storaged/storaged.cpp
index 54d429c..06afea6 100644
--- a/storaged/storaged.cpp
+++ b/storaged/storaged.cpp
@@ -200,6 +200,10 @@
}
}
+void storaged_t::report_storage_info() {
+ storage_info->report();
+}
+
/* storaged_t */
storaged_t::storaged_t(void) {
if (access(MMC_DISK_STATS_PATH, R_OK) < 0 && access(SDA_DISK_STATS_PATH, R_OK) < 0) {
@@ -222,6 +226,8 @@
mConfig.periodic_chores_interval_uid_io =
property_get_int32("ro.storaged.uid_io.interval", DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO);
+ storage_info.reset(storage_info_t::get_storage_info());
+
mStarttime = time(NULL);
}
@@ -229,6 +235,7 @@
if (mConfig.diskstats_available) {
mDiskStats.update();
mDsm.update();
+ storage_info->refresh();
if (mTimer && (mTimer % mConfig.periodic_chores_interval_disk_stats_publish) == 0) {
mDiskStats.publish();
}
diff --git a/storaged/storaged_info.cpp b/storaged/storaged_info.cpp
index 434bd74..b5fb13e 100644
--- a/storaged/storaged_info.cpp
+++ b/storaged/storaged_info.cpp
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <string.h>
+#include <sys/statvfs.h>
#include <android-base/file.h>
#include <android-base/parseint.h>
@@ -30,13 +31,42 @@
using namespace std;
using namespace android::base;
-void report_storage_health()
-{
- emmc_info_t mmc;
- ufs_info_t ufs;
+const string emmc_info_t::emmc_sysfs = "/sys/bus/mmc/devices/mmc0:0001/";
+const string emmc_info_t::emmc_debugfs = "/d/mmc0/mmc0:0001/ext_csd";
+const char* emmc_info_t::emmc_ver_str[9] = {
+ "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0", "5.1"
+};
- mmc.report();
- ufs.report();
+const string ufs_info_t::health_file = "/sys/devices/soc/624000.ufshc/health";
+
+static bool FileExists(const std::string& filename)
+{
+ struct stat buffer;
+ return stat(filename.c_str(), &buffer) == 0;
+}
+
+storage_info_t* storage_info_t::get_storage_info()
+{
+ if (FileExists(emmc_info_t::emmc_sysfs) ||
+ FileExists(emmc_info_t::emmc_debugfs)) {
+ return new emmc_info_t;
+ }
+ if (FileExists(ufs_info_t::health_file)) {
+ return new ufs_info_t;
+ }
+ return new storage_info_t;
+}
+
+void storage_info_t::refresh()
+{
+ struct statvfs buf;
+ if (statvfs(userdata_path.c_str(), &buf) != 0) {
+ PLOG_TO(SYSTEM, WARNING) << "Failed to get userdata info";
+ return;
+ }
+
+ userdata_total_kb = buf.f_bsize * buf.f_blocks >> 10;
+ userdata_free_kb = buf.f_bfree * buf.f_blocks >> 10;
}
void storage_info_t::publish()
@@ -46,13 +76,12 @@
<< LOG_ID_EVENTS;
}
-bool emmc_info_t::report()
+void emmc_info_t::report()
{
if (!report_sysfs() && !report_debugfs())
- return false;
+ return;
publish();
- return true;
}
bool emmc_info_t::report_sysfs()
@@ -136,21 +165,21 @@
return true;
}
-bool ufs_info_t::report()
+void ufs_info_t::report()
{
string buffer;
if (!ReadFileToString(health_file, &buffer)) {
- return false;
+ return;
}
vector<string> lines = Split(buffer, "\n");
if (lines.empty()) {
- return false;
+ return;
}
char rev[8];
if (sscanf(lines[0].c_str(), "ufs version: 0x%7s\n", rev) < 1) {
- return false;
+ return;
}
version = "ufs " + string(rev);
@@ -175,10 +204,9 @@
}
if (eol == 0 || (lifetime_a == 0 && lifetime_b == 0)) {
- return false;
+ return;
}
publish();
- return true;
}
diff --git a/storaged/storaged_uid_monitor.cpp b/storaged/storaged_uid_monitor.cpp
index 5bb98e1..dd8bdd6 100644
--- a/storaged/storaged_uid_monitor.cpp
+++ b/storaged/storaged_uid_monitor.cpp
@@ -22,33 +22,24 @@
#include <string>
#include <unordered_map>
+#include <android/content/pm/IPackageManagerNative.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/macros.h>
#include <android-base/parseint.h>
#include <android-base/strings.h>
#include <android-base/stringprintf.h>
+#include <binder/IServiceManager.h>
#include <log/log_event_list.h>
-#include <packagelistparser/packagelistparser.h>
#include "storaged.h"
#include "storaged_uid_monitor.h"
using namespace android;
using namespace android::base;
+using namespace android::content::pm;
-static bool packagelist_parse_cb(pkg_info* info, void* userdata)
-{
- std::unordered_map<uint32_t, struct uid_info>* uids =
- reinterpret_cast<std::unordered_map<uint32_t, struct uid_info>*>(userdata);
-
- if (uids->find(info->uid) != uids->end()) {
- (*uids)[info->uid].name = info->name;
- }
-
- packagelist_free(info);
- return true;
-}
+static bool refresh_uid_names;
std::unordered_map<uint32_t, struct uid_info> uid_monitor::get_uid_io_stats()
{
@@ -56,6 +47,38 @@
return get_uid_io_stats_locked();
};
+static void get_uid_names(const vector<int>& uids, const vector<std::string*>& uid_names)
+{
+ sp<IServiceManager> sm = defaultServiceManager();
+ if (sm == NULL) {
+ LOG_TO(SYSTEM, ERROR) << "defaultServiceManager failed";
+ return;
+ }
+
+ sp<IBinder> binder = sm->getService(String16("package_native"));
+ if (binder == NULL) {
+ LOG_TO(SYSTEM, ERROR) << "getService package_native failed";
+ return;
+ }
+
+ sp<IPackageManagerNative> package_mgr = interface_cast<IPackageManagerNative>(binder);
+ std::vector<std::string> names;
+ binder::Status status = package_mgr->getNamesForUids(uids, &names);
+ if (!status.isOk()) {
+ LOG_TO(SYSTEM, ERROR) << "package_native::getNamesForUids failed: "
+ << status.exceptionMessage();
+ return;
+ }
+
+ for (uint32_t i = 0; i < uid_names.size(); i++) {
+ if (!names[i].empty()) {
+ *uid_names[i] = names[i];
+ }
+ }
+
+ refresh_uid_names = false;
+}
+
std::unordered_map<uint32_t, struct uid_info> uid_monitor::get_uid_io_stats_locked()
{
std::unordered_map<uint32_t, struct uid_info> uid_io_stats;
@@ -67,7 +90,8 @@
std::vector<std::string> io_stats = Split(buffer, "\n");
struct uid_info u;
- bool refresh_uid = false;
+ vector<int> uids;
+ vector<std::string*> uid_names;
for (uint32_t i = 0; i < io_stats.size(); i++) {
if (io_stats[i].empty()) {
@@ -91,17 +115,19 @@
continue;
}
- if (last_uid_io_stats.find(u.uid) == last_uid_io_stats.end()) {
- refresh_uid = true;
- u.name = std::to_string(u.uid);
- } else {
- u.name = last_uid_io_stats[u.uid].name;
- }
uid_io_stats[u.uid] = u;
+ uid_io_stats[u.uid].name = std::to_string(u.uid);
+ uids.push_back(u.uid);
+ uid_names.push_back(&uid_io_stats[u.uid].name);
+ if (last_uid_io_stats.find(u.uid) == last_uid_io_stats.end()) {
+ refresh_uid_names = true;
+ } else {
+ uid_io_stats[u.uid].name = last_uid_io_stats[u.uid].name;
+ }
}
- if (refresh_uid) {
- packagelist_parse(packagelist_parse_cb, &uid_io_stats);
+ if (!uids.empty() && refresh_uid_names) {
+ get_uid_names(uids, uid_names);
}
return uid_io_stats;
@@ -228,13 +254,13 @@
last_uid_io_stats[uid.uid].io[BACKGROUND].write_bytes;
usage.bytes[READ][FOREGROUND][charger_stat] +=
- (fg_rd_delta < 0) ? uid.io[FOREGROUND].read_bytes : fg_rd_delta;
+ (fg_rd_delta < 0) ? 0 : fg_rd_delta;
usage.bytes[READ][BACKGROUND][charger_stat] +=
- (bg_rd_delta < 0) ? uid.io[BACKGROUND].read_bytes : bg_rd_delta;
+ (bg_rd_delta < 0) ? 0 : bg_rd_delta;
usage.bytes[WRITE][FOREGROUND][charger_stat] +=
- (fg_wr_delta < 0) ? uid.io[FOREGROUND].write_bytes : fg_wr_delta;
+ (fg_wr_delta < 0) ? 0 : fg_wr_delta;
usage.bytes[WRITE][BACKGROUND][charger_stat] +=
- (bg_wr_delta < 0) ? uid.io[BACKGROUND].write_bytes : bg_wr_delta;
+ (bg_wr_delta < 0) ? 0 : bg_wr_delta;
}
last_uid_io_stats = uid_io_stats;