summaryrefslogtreecommitdiff
path: root/cmds
diff options
context:
space:
mode:
Diffstat (limited to 'cmds')
-rw-r--r--cmds/atrace/Android.bp17
-rw-r--r--cmds/atrace/Android.mk22
-rw-r--r--cmds/atrace/atrace.cpp67
-rw-r--r--cmds/bugreport/Android.bp6
-rw-r--r--cmds/bugreport/Android.mk12
-rw-r--r--cmds/dumpstate/Android.bp4
-rw-r--r--cmds/dumpstate/Android.mk6
-rw-r--r--cmds/dumpstate/dumpstate.cpp138
-rw-r--r--cmds/dumpstate/dumpstate.h2
-rw-r--r--cmds/dumpstate/utils.cpp6
-rw-r--r--cmds/dumpsys/Android.bp15
-rw-r--r--cmds/dumpsys/Android.mk21
-rw-r--r--cmds/dumpsys/dumpsys.cpp2
-rw-r--r--cmds/installd/Android.bp66
-rw-r--r--cmds/installd/Android.mk67
-rw-r--r--cmds/installd/commands.cpp253
-rw-r--r--cmds/installd/installd.cpp10
-rw-r--r--cmds/installd/installd_constants.h3
-rw-r--r--cmds/installd/otapreopt.cpp2
-rw-r--r--cmds/installd/tests/Android.bp16
-rw-r--r--cmds/installd/tests/Android.mk31
-rw-r--r--cmds/service/Android.bp13
-rw-r--r--cmds/service/Android.mk16
-rw-r--r--cmds/servicemanager/Android.bp36
-rw-r--r--cmds/servicemanager/Android.mk26
-rw-r--r--cmds/servicemanager/binder.h2
26 files changed, 425 insertions, 434 deletions
diff --git a/cmds/atrace/Android.bp b/cmds/atrace/Android.bp
new file mode 100644
index 0000000000..194a5650c9
--- /dev/null
+++ b/cmds/atrace/Android.bp
@@ -0,0 +1,17 @@
+// Copyright 2012 The Android Open Source Project
+
+cc_binary {
+ name: "atrace",
+ srcs: ["atrace.cpp"],
+
+ shared_libs: [
+ "libbinder",
+ "liblog",
+ "libcutils",
+ "libutils",
+ "libz",
+ "libbase",
+ ],
+
+ init_rc: ["atrace.rc"],
+}
diff --git a/cmds/atrace/Android.mk b/cmds/atrace/Android.mk
deleted file mode 100644
index a787e95942..0000000000
--- a/cmds/atrace/Android.mk
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright 2012 The Android Open Source Project
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= atrace.cpp
-
-LOCAL_C_INCLUDES += external/zlib
-
-LOCAL_MODULE:= atrace
-
-LOCAL_MODULE_TAGS:= optional
-
-LOCAL_SHARED_LIBRARIES := \
- libbinder \
- libcutils \
- libutils \
- libz \
-
-LOCAL_INIT_RC := atrace.rc
-
-include $(BUILD_EXECUTABLE)
diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp
index 5885738e9d..4c0e242bb4 100644
--- a/cmds/atrace/atrace.cpp
+++ b/cmds/atrace/atrace.cpp
@@ -31,6 +31,8 @@
#include <unistd.h>
#include <zlib.h>
+#include <memory>
+
#include <binder/IBinder.h>
#include <binder/IServiceManager.h>
#include <binder/Parcel.h>
@@ -41,6 +43,7 @@
#include <utils/Timers.h>
#include <utils/Tokenizer.h>
#include <utils/Trace.h>
+#include <android-base/file.h>
using namespace android;
@@ -533,11 +536,11 @@ static void clearAppProperties()
// Set the system property that indicates which apps should perform
// application-level tracing.
-static bool setAppCmdlineProperty(const char* cmdline)
+static bool setAppCmdlineProperty(char* cmdline)
{
char buf[PROPERTY_KEY_MAX];
int i = 0;
- const char* start = cmdline;
+ char* start = cmdline;
while (start != NULL) {
if (i == MAX_PACKAGES) {
fprintf(stderr, "error: only 16 packages could be traced at once\n");
@@ -587,24 +590,14 @@ static bool disableKernelTraceEvents() {
// kernel.
static bool verifyKernelTraceFuncs(const char* funcs)
{
- int fd = open(k_ftraceFilterPath, O_RDONLY);
- if (fd == -1) {
- fprintf(stderr, "error opening %s: %s (%d)\n", k_ftraceFilterPath,
- strerror(errno), errno);
- return false;
- }
-
- char buf[4097];
- ssize_t n = read(fd, buf, 4096);
- close(fd);
- if (n == -1) {
- fprintf(stderr, "error reading %s: %s (%d)\n", k_ftraceFilterPath,
+ std::string buf;
+ if (!android::base::ReadFileToString(k_ftraceFilterPath, &buf)) {
+ fprintf(stderr, "error opening %s: %s (%d)\n", k_ftraceFilterPath,
strerror(errno), errno);
- return false;
+ return false;
}
- buf[n] = '\0';
- String8 funcList = String8::format("\n%s", buf);
+ String8 funcList = String8::format("\n%s",buf.c_str());
// Make sure that every function listed in funcs is in the list we just
// read from the kernel, except for wildcard inputs.
@@ -624,7 +617,6 @@ static bool verifyKernelTraceFuncs(const char* funcs)
func = strtok(NULL, ",");
}
free(myFuncs);
-
return ok;
}
@@ -754,7 +746,7 @@ static bool setUpTrace()
}
packageList += value;
}
- ok &= setAppCmdlineProperty(packageList.data());
+ ok &= setAppCmdlineProperty(&packageList[0]);
ok &= pokeBinderServices();
// Disable all the sysfs enables. This is done as a separate loop from
@@ -853,30 +845,34 @@ static void dumpTrace(int outFd)
if (g_compress) {
z_stream zs;
- uint8_t *in, *out;
- int result, flush;
-
memset(&zs, 0, sizeof(zs));
- result = deflateInit(&zs, Z_DEFAULT_COMPRESSION);
+
+ int result = deflateInit(&zs, Z_DEFAULT_COMPRESSION);
if (result != Z_OK) {
fprintf(stderr, "error initializing zlib: %d\n", result);
close(traceFD);
return;
}
- const size_t bufSize = 64*1024;
- in = (uint8_t*)malloc(bufSize);
- out = (uint8_t*)malloc(bufSize);
- flush = Z_NO_FLUSH;
+ constexpr size_t bufSize = 64*1024;
+ std::unique_ptr<uint8_t> in(new uint8_t[bufSize]);
+ std::unique_ptr<uint8_t> out(new uint8_t[bufSize]);
+ if (!in || !out) {
+ fprintf(stderr, "couldn't allocate buffers\n");
+ close(traceFD);
+ return;
+ }
- zs.next_out = out;
+ int flush = Z_NO_FLUSH;
+
+ zs.next_out = reinterpret_cast<Bytef*>(out.get());
zs.avail_out = bufSize;
do {
if (zs.avail_in == 0) {
// More input is needed.
- result = read(traceFD, in, bufSize);
+ result = read(traceFD, in.get(), bufSize);
if (result < 0) {
fprintf(stderr, "error reading trace: %s (%d)\n",
strerror(errno), errno);
@@ -885,14 +881,14 @@ static void dumpTrace(int outFd)
} else if (result == 0) {
flush = Z_FINISH;
} else {
- zs.next_in = in;
+ zs.next_in = reinterpret_cast<Bytef*>(in.get());
zs.avail_in = result;
}
}
if (zs.avail_out == 0) {
// Need to write the output.
- result = write(outFd, out, bufSize);
+ result = write(outFd, out.get(), bufSize);
if ((size_t)result < bufSize) {
fprintf(stderr, "error writing deflated trace: %s (%d)\n",
strerror(errno), errno);
@@ -900,7 +896,7 @@ static void dumpTrace(int outFd)
zs.avail_out = bufSize; // skip the final write
break;
}
- zs.next_out = out;
+ zs.next_out = reinterpret_cast<Bytef*>(out.get());
zs.avail_out = bufSize;
}
@@ -912,7 +908,7 @@ static void dumpTrace(int outFd)
if (zs.avail_out < bufSize) {
size_t bytes = bufSize - zs.avail_out;
- result = write(outFd, out, bytes);
+ result = write(outFd, out.get(), bytes);
if ((size_t)result < bytes) {
fprintf(stderr, "error writing deflated trace: %s (%d)\n",
strerror(errno), errno);
@@ -923,9 +919,6 @@ static void dumpTrace(int outFd)
if (result != Z_OK) {
fprintf(stderr, "error cleaning up zlib: %d\n", result);
}
-
- free(in);
- free(out);
} else {
ssize_t sent = 0;
while ((sent = sendfile(outFd, traceFD, NULL, 64*1024*1024)) > 0);
@@ -981,7 +974,7 @@ static void showHelp(const char *cmd)
" -k fname,... trace the listed kernel functions\n"
" -n ignore signals\n"
" -s N sleep for N seconds before tracing [default 0]\n"
- " -t N trace for N seconds [defualt 5]\n"
+ " -t N trace for N seconds [default 5]\n"
" -z compress the trace dump\n"
" --async_start start circular trace and return immediatly\n"
" --async_dump dump the current contents of circular trace buffer\n"
diff --git a/cmds/bugreport/Android.bp b/cmds/bugreport/Android.bp
new file mode 100644
index 0000000000..139e4b2bf1
--- /dev/null
+++ b/cmds/bugreport/Android.bp
@@ -0,0 +1,6 @@
+cc_binary {
+ name: "bugreport",
+ srcs: ["bugreport.cpp"],
+ cflags: ["-Wall"],
+ shared_libs: ["libcutils"],
+}
diff --git a/cmds/bugreport/Android.mk b/cmds/bugreport/Android.mk
deleted file mode 100644
index ced5d30378..0000000000
--- a/cmds/bugreport/Android.mk
+++ /dev/null
@@ -1,12 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= bugreport.cpp
-
-LOCAL_MODULE:= bugreport
-
-LOCAL_CFLAGS := -Wall
-
-LOCAL_SHARED_LIBRARIES := libcutils
-
-include $(BUILD_EXECUTABLE)
diff --git a/cmds/dumpstate/Android.bp b/cmds/dumpstate/Android.bp
new file mode 100644
index 0000000000..3db41c20cf
--- /dev/null
+++ b/cmds/dumpstate/Android.bp
@@ -0,0 +1,4 @@
+cc_library_static {
+ name: "libdumpstate.default",
+ srcs: ["libdumpstate_default.cpp"],
+}
diff --git a/cmds/dumpstate/Android.mk b/cmds/dumpstate/Android.mk
index 791a7c4a61..0433f31eb2 100644
--- a/cmds/dumpstate/Android.mk
+++ b/cmds/dumpstate/Android.mk
@@ -1,8 +1,4 @@
LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := libdumpstate_default.cpp
-LOCAL_MODULE := libdumpstate.default
-include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
@@ -16,7 +12,7 @@ LOCAL_MODULE := dumpstate
LOCAL_SHARED_LIBRARIES := libcutils liblog libselinux libbase
# ZipArchive support, the order matters here to get all symbols.
-LOCAL_STATIC_LIBRARIES := libziparchive libz libmincrypt
+LOCAL_STATIC_LIBRARIES := libziparchive libz libcrypto_static
LOCAL_HAL_STATIC_LIBRARIES := libdumpstate
LOCAL_CFLAGS += -Wall -Werror -Wno-unused-parameter
LOCAL_INIT_RC := dumpstate.rc
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index d9b6a5c0a2..a868972bc3 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#define LOG_TAG "dumpstate"
#include <dirent.h>
#include <errno.h>
@@ -37,18 +38,16 @@
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include <android-base/unique_fd.h>
#include <cutils/properties.h>
-#include "private/android_filesystem_config.h"
-
-#define LOG_TAG "dumpstate"
-#include <cutils/log.h>
+#include <private/android_filesystem_config.h>
+#include <private/android_logger.h>
#include "dumpstate.h"
-#include "ScopedFd.h"
#include "ziparchive/zip_writer.h"
-#include "mincrypt/sha256.h"
+#include <openssl/sha.h>
using android::base::StringPrintf;
@@ -643,102 +642,14 @@ static int dump_stat_from_fd(const char *title __unused, const char *path, int f
return 0;
}
-/* Copied policy from system/core/logd/LogBuffer.cpp */
-
-#define LOG_BUFFER_SIZE (256 * 1024)
-#define LOG_BUFFER_MIN_SIZE (64 * 1024UL)
-#define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL)
-
-static bool valid_size(unsigned long value) {
- if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) {
- return false;
- }
-
- long pages = sysconf(_SC_PHYS_PAGES);
- if (pages < 1) {
- return true;
- }
-
- long pagesize = sysconf(_SC_PAGESIZE);
- if (pagesize <= 1) {
- pagesize = PAGE_SIZE;
- }
-
- // maximum memory impact a somewhat arbitrary ~3%
- pages = (pages + 31) / 32;
- unsigned long maximum = pages * pagesize;
-
- if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) {
- return true;
- }
-
- return value <= maximum;
-}
-
-static unsigned long property_get_size(const char *key) {
- unsigned long value;
- char *cp, property[PROPERTY_VALUE_MAX];
-
- property_get(key, property, "");
- value = strtoul(property, &cp, 10);
-
- switch(*cp) {
- case 'm':
- case 'M':
- value *= 1024;
- /* FALLTHRU */
- case 'k':
- case 'K':
- value *= 1024;
- /* FALLTHRU */
- case '\0':
- break;
-
- default:
- value = 0;
- }
-
- if (!valid_size(value)) {
- value = 0;
- }
-
- return value;
-}
-
/* timeout in ms */
static unsigned long logcat_timeout(const char *name) {
- static const char global_tuneable[] = "persist.logd.size"; // Settings App
- static const char global_default[] = "ro.logd.size"; // BoardConfig.mk
- char key[PROP_NAME_MAX];
- unsigned long property_size, default_size;
-
- default_size = property_get_size(global_tuneable);
- if (!default_size) {
- default_size = property_get_size(global_default);
- }
-
- snprintf(key, sizeof(key), "%s.%s", global_tuneable, name);
- property_size = property_get_size(key);
-
- if (!property_size) {
- snprintf(key, sizeof(key), "%s.%s", global_default, name);
- property_size = property_get_size(key);
- }
-
- if (!property_size) {
- property_size = default_size;
- }
-
- if (!property_size) {
- property_size = LOG_BUFFER_SIZE;
- }
-
+ log_id_t id = android_name_to_log_id(name);
+ unsigned long property_size = __android_logger_get_buffer_size(id);
/* Engineering margin is ten-fold our guess */
return 10 * (property_size + worst_write_perf) / worst_write_perf;
}
-/* End copy from system/core/logd/LogBuffer.cpp */
-
/* dumps the current system state to stdout */
static void print_header(std::string version) {
char build[PROPERTY_VALUE_MAX], fingerprint[PROPERTY_VALUE_MAX];
@@ -835,8 +746,9 @@ bool add_zip_entry_from_fd(const std::string& entry_name, int fd) {
}
bool add_zip_entry(const std::string& entry_name, const std::string& entry_path) {
- ScopedFd fd(TEMP_FAILURE_RETRY(open(entry_path.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC)));
- if (fd.get() == -1) {
+ android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(entry_path.c_str(), O_RDONLY | O_NONBLOCK
+ | O_CLOEXEC)));
+ if (fd == -1) {
MYLOGE("open(%s): %s\n", entry_path.c_str(), strerror(errno));
return false;
}
@@ -914,7 +826,8 @@ static void dumpstate(const std::string& screenshot_path, const std::string& ver
dump_files("UPTIME MMC PERF", mmcblk0, skip_not_stat, dump_stat_from_fd);
dump_emmc_ecsd("/d/mmc0/mmc0:0001/ext_csd");
dump_file("MEMORY INFO", "/proc/meminfo");
- run_command("CPU INFO", 10, "top", "-n", "1", "-d", "1", "-m", "30", "-H", NULL);
+ run_command("CPU INFO", 10, "top", "-b", "-n", "1", "-H", "-s", "6",
+ "-o", "pid,tid,user,pr,ni,%cpu,s,virt,res,pcy,cmd,name", NULL);
run_command("PROCRANK", 20, SU_PATH, "root", "procrank", NULL);
dump_file("VIRTUAL MEMORY STATS", "/proc/vmstat");
dump_file("VMALLOC INFO", "/proc/vmallocinfo");
@@ -928,11 +841,12 @@ static void dumpstate(const std::string& screenshot_path, const std::string& ver
dump_file("KERNEL CPUFREQ", "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state");
dump_file("KERNEL SYNC", "/d/sync");
- run_command("PROCESSES AND THREADS", 10, "ps", "-Z", "-t", "-p", "-P", NULL);
+ run_command("PROCESSES AND THREADS", 10, "ps", "-A", "-T", "-Z",
+ "-O", "pri,nice,rtprio,sched,pcy", NULL);
run_command("LIBRANK", 10, SU_PATH, "root", "librank", NULL);
run_command("PRINTENV", 10, "printenv", NULL);
- run_command("NETSTAT", 10, "netstat", "-n", NULL);
+ run_command("NETSTAT", 10, "netstat", "-nW", NULL);
run_command("LSMOD", 10, "lsmod", NULL);
do_dmesg();
@@ -942,6 +856,9 @@ static void dumpstate(const std::string& screenshot_path, const std::string& ver
for_each_tid(show_wchan, "BLOCKED PROCESS WAIT-CHANNELS");
for_each_pid(show_showtime, "PROCESS TIMES (pid cmd user system iowait+percentage)");
+ /* Dump Bluetooth HCI logs */
+ add_dir("/data/misc/bluetooth/logs", true);
+
if (!screenshot_path.empty()) {
MYLOGI("taking late screenshot\n");
take_screenshot(screenshot_path);
@@ -1268,15 +1185,15 @@ static bool finish_zip_file(const std::string& bugreport_name, const std::string
}
static std::string SHA256_file_hash(std::string filepath) {
- ScopedFd fd(TEMP_FAILURE_RETRY(open(filepath.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC
- | O_NOFOLLOW)));
- if (fd.get() == -1) {
+ android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(filepath.c_str(), O_RDONLY | O_NONBLOCK
+ | O_CLOEXEC | O_NOFOLLOW)));
+ if (fd == -1) {
MYLOGE("open(%s): %s\n", filepath.c_str(), strerror(errno));
return NULL;
}
SHA256_CTX ctx;
- SHA256_init(&ctx);
+ SHA256_Init(&ctx);
std::vector<uint8_t> buffer(65536);
while (1) {
@@ -1288,13 +1205,14 @@ static std::string SHA256_file_hash(std::string filepath) {
return NULL;
}
- SHA256_update(&ctx, buffer.data(), bytes_read);
+ SHA256_Update(&ctx, buffer.data(), bytes_read);
}
- uint8_t hash[SHA256_DIGEST_SIZE];
- memcpy(hash, SHA256_final(&ctx), SHA256_DIGEST_SIZE);
- char hash_buffer[SHA256_DIGEST_SIZE * 2 + 1];
- for(size_t i = 0; i < SHA256_DIGEST_SIZE; i++) {
+ uint8_t hash[SHA256_DIGEST_LENGTH];
+ SHA256_Final(hash, &ctx);
+
+ char hash_buffer[SHA256_DIGEST_LENGTH * 2 + 1];
+ for(size_t i = 0; i < SHA256_DIGEST_LENGTH; i++) {
sprintf(hash_buffer + (i * 2), "%02x", hash[i]);
}
hash_buffer[sizeof(hash_buffer) - 1] = 0;
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index 514af59c17..1b28c49640 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -221,7 +221,7 @@ bool is_user_build();
*/
class DurationReporter {
public:
- DurationReporter(const char *title);
+ explicit DurationReporter(const char *title);
DurationReporter(const char *title, FILE* out);
~DurationReporter();
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index fd6413d562..285c01ef8a 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -28,7 +28,6 @@
#include <sys/capability.h>
#include <sys/inotify.h>
#include <sys/stat.h>
-#include <sys/sysconf.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/klog.h>
@@ -181,7 +180,7 @@ static void for_each_pid_helper(int pid, const char *cmdline, void *arg) {
void for_each_pid(for_each_pid_func func, const char *header) {
ON_DRY_RUN_RETURN();
- __for_each_pid(for_each_pid_helper, header, (void *)func);
+ __for_each_pid(for_each_pid_helper, header, (void *) func);
}
static void for_each_tid_helper(int pid, const char *cmdline, void *arg) {
@@ -578,6 +577,7 @@ int dump_files(const char *title, const char *dir,
* stuck.
*/
int dump_file_from_fd(const char *title, const char *path, int fd) {
+ ON_DRY_RUN_RETURN(0);
int flags = fcntl(fd, F_GETFL);
if (flags == -1) {
printf("*** %s: failed to get flags on fd %d: %s\n", path, fd, strerror(errno));
@@ -828,7 +828,7 @@ bool drop_root_user() {
}
gid_t groups[] = { AID_LOG, AID_SDCARD_R, AID_SDCARD_RW,
- AID_MOUNT, AID_INET, AID_NET_BW_STATS, AID_READPROC };
+ AID_MOUNT, AID_INET, AID_NET_BW_STATS, AID_READPROC, AID_BLUETOOTH };
if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
MYLOGE("Unable to setgroups, aborting: %s\n", strerror(errno));
return false;
diff --git a/cmds/dumpsys/Android.bp b/cmds/dumpsys/Android.bp
new file mode 100644
index 0000000000..38442e755f
--- /dev/null
+++ b/cmds/dumpsys/Android.bp
@@ -0,0 +1,15 @@
+cc_binary {
+ name: "dumpsys",
+
+ srcs: ["dumpsys.cpp"],
+
+ shared_libs: [
+ "libbase",
+ "libutils",
+ "liblog",
+ "libbinder",
+ ],
+
+ cflags: ["-DXP_UNIX"],
+ //shared_libs: ["librt"],
+}
diff --git a/cmds/dumpsys/Android.mk b/cmds/dumpsys/Android.mk
deleted file mode 100644
index 8335c14df6..0000000000
--- a/cmds/dumpsys/Android.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- dumpsys.cpp
-
-LOCAL_SHARED_LIBRARIES := \
- libbase \
- libutils \
- liblog \
- libbinder
-
-
-ifeq ($(TARGET_OS),linux)
- LOCAL_CFLAGS += -DXP_UNIX
- #LOCAL_SHARED_LIBRARIES += librt
-endif
-
-LOCAL_MODULE:= dumpsys
-
-include $(BUILD_EXECUTABLE)
diff --git a/cmds/dumpsys/dumpsys.cpp b/cmds/dumpsys/dumpsys.cpp
index d19e98a10e..772d17f6ae 100644
--- a/cmds/dumpsys/dumpsys.cpp
+++ b/cmds/dumpsys/dumpsys.cpp
@@ -203,7 +203,7 @@ int main(int argc, char* const argv[])
// call returns, to terminate our reads if the other end closes their copy of the
// file descriptor, but then hangs for some reason. There doesn't seem to be a good
// way to do this, though.
- remote_end.clear();
+ remote_end.reset();
if (err != 0) {
aerr << "Error dumping service info: (" << strerror(err) << ") " << service_name
diff --git a/cmds/installd/Android.bp b/cmds/installd/Android.bp
new file mode 100644
index 0000000000..e3048c72a9
--- /dev/null
+++ b/cmds/installd/Android.bp
@@ -0,0 +1,66 @@
+cc_defaults {
+ name: "installd_defaults",
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+ srcs: [
+ "commands.cpp",
+ "globals.cpp",
+ "utils.cpp",
+ ],
+ shared_libs: [
+ "libbase",
+ "libcutils",
+ "liblog",
+ "liblogwrap",
+ "libselinux",
+ ],
+
+ clang: true,
+}
+
+//
+// Static library used in testing and executable
+//
+
+cc_library_static {
+ name: "libinstalld",
+ defaults: ["installd_defaults"],
+
+ export_include_dirs: ["."],
+}
+
+//
+// Executable
+//
+
+cc_binary {
+ name: "installd",
+ defaults: ["installd_defaults"],
+ srcs: ["installd.cpp"],
+
+ static_libs: ["libdiskusage"],
+
+ init_rc: ["installd.rc"],
+}
+
+// OTA chroot tool
+
+cc_binary {
+ name: "otapreopt_chroot",
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+ clang: true,
+
+ srcs: ["otapreopt_chroot.cpp"],
+ shared_libs: [
+ "libbase",
+ "liblog",
+ ],
+}
+
+subdirs = ["tests"]
diff --git a/cmds/installd/Android.mk b/cmds/installd/Android.mk
index 86df596c64..3ded400f67 100644
--- a/cmds/installd/Android.mk
+++ b/cmds/installd/Android.mk
@@ -1,48 +1,5 @@
LOCAL_PATH := $(call my-dir)
-common_src_files := commands.cpp globals.cpp utils.cpp
-common_cflags := -Wall -Werror
-
-#
-# Static library used in testing and executable
-#
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := libinstalld
-LOCAL_MODULE_TAGS := eng tests
-LOCAL_SRC_FILES := $(common_src_files)
-LOCAL_CFLAGS := $(common_cflags)
-LOCAL_SHARED_LIBRARIES := \
- libbase \
- liblogwrap \
- libselinux \
-
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-LOCAL_CLANG := true
-include $(BUILD_STATIC_LIBRARY)
-
-#
-# Executable
-#
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := installd
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := $(common_cflags)
-LOCAL_SRC_FILES := installd.cpp $(common_src_files)
-LOCAL_SHARED_LIBRARIES := \
- libbase \
- libcutils \
- liblog \
- liblogwrap \
- libselinux \
-
-LOCAL_STATIC_LIBRARIES := libdiskusage
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-LOCAL_INIT_RC := installd.rc
-LOCAL_CLANG := true
-include $(BUILD_EXECUTABLE)
-
#
# OTA Executable
#
@@ -50,7 +7,7 @@ include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_MODULE := otapreopt
LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := $(common_cflags)
+LOCAL_CFLAGS := -Wall -Werror
# Base & ASLR boundaries for boot image creation.
ifndef LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA
@@ -67,7 +24,7 @@ LOCAL_CFLAGS += -DART_BASE_ADDRESS=$(LIBART_IMG_HOST_BASE_ADDRESS)
LOCAL_CFLAGS += -DART_BASE_ADDRESS_MIN_DELTA=$(LOCAL_LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA)
LOCAL_CFLAGS += -DART_BASE_ADDRESS_MAX_DELTA=$(LOCAL_LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA)
-LOCAL_SRC_FILES := otapreopt.cpp $(common_src_files)
+LOCAL_SRC_FILES := otapreopt.cpp commands.cpp globals.cpp utils.cpp
LOCAL_SHARED_LIBRARIES := \
libbase \
libcutils \
@@ -80,22 +37,6 @@ LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
LOCAL_CLANG := true
include $(BUILD_EXECUTABLE)
-# OTA chroot tool
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := otapreopt_chroot
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := $(common_cflags)
-
-LOCAL_SRC_FILES := otapreopt_chroot.cpp
-LOCAL_SHARED_LIBRARIES := \
- libbase \
- liblog \
-
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-LOCAL_CLANG := true
-include $(BUILD_EXECUTABLE)
-
# OTA slot script
include $(CLEAR_VARS)
@@ -120,7 +61,3 @@ LOCAL_SRC_FILES := otapreopt_script.sh
LOCAL_REQUIRED_MODULES := otapreopt otapreopt_chroot otapreopt_slot
include $(BUILD_PREBUILT)
-
-# Tests.
-
-include $(LOCAL_PATH)/tests/Android.mk \ No newline at end of file
diff --git a/cmds/installd/commands.cpp b/cmds/installd/commands.cpp
index 271c75ba4e..2e64f4642a 100644
--- a/cmds/installd/commands.cpp
+++ b/cmds/installd/commands.cpp
@@ -746,8 +746,10 @@ static int split(char *buf, const char **argv)
return count;
}
-static void run_patchoat(int input_fd, int oat_fd, const char* input_file_name,
- const char* output_file_name, const char *pkgname ATTRIBUTE_UNUSED, const char *instruction_set)
+static void run_patchoat(int input_oat_fd, int input_vdex_fd, int out_oat_fd, int out_vdex_fd,
+ const char* input_oat_file_name, const char* input_vdex_file_name,
+ const char* output_oat_file_name, const char* output_vdex_file_name,
+ const char *pkgname ATTRIBUTE_UNUSED, const char *instruction_set)
{
static const int MAX_INT_LEN = 12; // '-'+10dig+'\0' -OR- 0x+8dig
static const unsigned int MAX_INSTRUCTION_SET_LEN = 7;
@@ -761,35 +763,44 @@ static void run_patchoat(int input_fd, int oat_fd, const char* input_file_name,
/* input_file_name/input_fd should be the .odex/.oat file that is precompiled. I think*/
char instruction_set_arg[strlen("--instruction-set=") + MAX_INSTRUCTION_SET_LEN];
- char output_oat_fd_arg[strlen("--output-oat-fd=") + MAX_INT_LEN];
char input_oat_fd_arg[strlen("--input-oat-fd=") + MAX_INT_LEN];
+ char input_vdex_fd_arg[strlen("--input-vdex-fd=") + MAX_INT_LEN];
+ char output_oat_fd_arg[strlen("--output-oat-fd=") + MAX_INT_LEN];
+ char output_vdex_fd_arg[strlen("--output-vdex-fd=") + MAX_INT_LEN];
const char* patched_image_location_arg = "--patched-image-location=/system/framework/boot.art";
// The caller has already gotten all the locks we need.
const char* no_lock_arg = "--no-lock-output";
sprintf(instruction_set_arg, "--instruction-set=%s", instruction_set);
- sprintf(output_oat_fd_arg, "--output-oat-fd=%d", oat_fd);
- sprintf(input_oat_fd_arg, "--input-oat-fd=%d", input_fd);
- ALOGV("Running %s isa=%s in-fd=%d (%s) out-fd=%d (%s)\n",
- PATCHOAT_BIN, instruction_set, input_fd, input_file_name, oat_fd, output_file_name);
+ sprintf(output_oat_fd_arg, "--output-oat-fd=%d", out_oat_fd);
+ sprintf(input_oat_fd_arg, "--input-oat-fd=%d", input_oat_fd);
+ ALOGV("Running %s isa=%s in-oat-fd=%d (%s) in-vdex-fd=%d (%s) "
+ "out-oat-fd=%d (%s) out-vdex-fd=%d (%s)\n",
+ PATCHOAT_BIN, instruction_set,
+ input_oat_fd, input_oat_file_name,
+ input_vdex_fd, input_vdex_file_name,
+ out_oat_fd, output_oat_file_name,
+ out_vdex_fd, output_vdex_file_name);
/* patchoat, patched-image-location, no-lock, isa, input-fd, output-fd */
- char* argv[7];
+ char* argv[9];
argv[0] = (char*) PATCHOAT_BIN;
argv[1] = (char*) patched_image_location_arg;
argv[2] = (char*) no_lock_arg;
argv[3] = instruction_set_arg;
- argv[4] = output_oat_fd_arg;
- argv[5] = input_oat_fd_arg;
- argv[6] = NULL;
+ argv[4] = input_oat_fd_arg;
+ argv[5] = input_vdex_fd_arg;
+ argv[6] = output_oat_fd_arg;
+ argv[7] = output_vdex_fd_arg;
+ argv[8] = NULL;
execv(PATCHOAT_BIN, (char* const *)argv);
ALOGE("execv(%s) failed: %s\n", PATCHOAT_BIN, strerror(errno));
}
-static void run_dex2oat(int zip_fd, int oat_fd, int image_fd, const char* input_file_name,
- const char* output_file_name, int swap_fd, const char *instruction_set,
- const char* compiler_filter, bool vm_safe_mode, bool debuggable, bool post_bootcomplete,
- int profile_fd, const char* shared_libraries) {
+static void run_dex2oat(int zip_fd, int oat_fd, int input_vdex_fd, int output_vdex_fd, int image_fd,
+ const char* input_file_name, const char* output_file_name, int swap_fd,
+ const char *instruction_set, const char* compiler_filter, bool vm_safe_mode,
+ bool debuggable, bool post_bootcomplete, int profile_fd, const char* shared_libraries) {
static const unsigned int MAX_INSTRUCTION_SET_LEN = 7;
if (strlen(instruction_set) >= MAX_INSTRUCTION_SET_LEN) {
@@ -870,6 +881,8 @@ static void run_dex2oat(int zip_fd, int oat_fd, int image_fd, const char* input_
char zip_fd_arg[strlen("--zip-fd=") + MAX_INT_LEN];
char zip_location_arg[strlen("--zip-location=") + PKG_PATH_MAX];
+ char input_vdex_fd_arg[strlen("--input-vdex-fd=") + MAX_INT_LEN];
+ char output_vdex_fd_arg[strlen("--output-vdex-fd=") + MAX_INT_LEN];
char oat_fd_arg[strlen("--oat-fd=") + MAX_INT_LEN];
char oat_location_arg[strlen("--oat-location=") + PKG_PATH_MAX];
char instruction_set_arg[strlen("--instruction-set=") + MAX_INSTRUCTION_SET_LEN];
@@ -885,6 +898,8 @@ static void run_dex2oat(int zip_fd, int oat_fd, int image_fd, const char* input_
sprintf(zip_fd_arg, "--zip-fd=%d", zip_fd);
sprintf(zip_location_arg, "--zip-location=%s", input_file_name);
+ sprintf(input_vdex_fd_arg, "--input-vdex-fd=%d", input_vdex_fd);
+ sprintf(output_vdex_fd_arg, "--output-vdex-fd=%d", output_vdex_fd);
sprintf(oat_fd_arg, "--oat-fd=%d", oat_fd);
sprintf(oat_location_arg, "--oat-location=%s", output_file_name);
sprintf(instruction_set_arg, "--instruction-set=%s", instruction_set);
@@ -947,7 +962,7 @@ static void run_dex2oat(int zip_fd, int oat_fd, int image_fd, const char* input_
ALOGV("Running %s in=%s out=%s\n", DEX2OAT_BIN, input_file_name, output_file_name);
- const char* argv[7 // program name, mandatory arguments and the final NULL
+ const char* argv[9 // program name, mandatory arguments and the final NULL
+ (have_dex2oat_isa_variant ? 1 : 0)
+ (have_dex2oat_isa_features ? 1 : 0)
+ (have_dex2oat_Xms_flag ? 2 : 0)
@@ -968,6 +983,8 @@ static void run_dex2oat(int zip_fd, int oat_fd, int image_fd, const char* input_
argv[i++] = DEX2OAT_BIN;
argv[i++] = zip_fd_arg;
argv[i++] = zip_location_arg;
+ argv[i++] = input_vdex_fd_arg;
+ argv[i++] = output_vdex_fd_arg;
argv[i++] = oat_fd_arg;
argv[i++] = oat_location_arg;
argv[i++] = instruction_set_arg;
@@ -1425,31 +1442,40 @@ bool dump_profile(uid_t uid, const char* pkgname, const char* code_path_string)
return true;
}
-// Translate the given oat path to an art (app image) path. An empty string
-// denotes an error.
-static std::string create_image_filename(const std::string& oat_path) {
- // A standard dalvik-cache entry. Replace ".dex" with ".art."
+static std::string replace_file_extension(const std::string& oat_path, const std::string& new_ext) {
+ // A standard dalvik-cache entry. Replace ".dex" with `new_ext`.
if (EndsWith(oat_path, ".dex")) {
- std::string art_path = oat_path;
- art_path.replace(art_path.length() - strlen("dex"), strlen("dex"), "art");
- CHECK(EndsWith(art_path, ".art"));
- return art_path;
+ std::string new_path = oat_path;
+ new_path.replace(new_path.length() - strlen(".dex"), strlen(".dex"), new_ext);
+ CHECK(EndsWith(new_path, new_ext.c_str()));
+ return new_path;
}
// An odex entry. Not that this may not be an extension, e.g., in the OTA
// case (where the base name will have an extension for the B artifact).
size_t odex_pos = oat_path.rfind(".odex");
if (odex_pos != std::string::npos) {
- std::string art_path = oat_path;
- art_path.replace(odex_pos, strlen(".odex"), ".art");
- CHECK_NE(art_path.find(".art"), std::string::npos);
- return art_path;
+ std::string new_path = oat_path;
+ new_path.replace(odex_pos, strlen(".odex"), new_ext);
+ CHECK_NE(new_path.find(new_ext), std::string::npos);
+ return new_path;
}
// Don't know how to handle this.
return "";
}
+// Translate the given oat path to an art (app image) path. An empty string
+// denotes an error.
+static std::string create_image_filename(const std::string& oat_path) {
+ return replace_file_extension(oat_path, ".art");
+}
+
+// Translate the given oat path to a vdex path. An empty string denotes an error.
+static std::string create_vdex_filename(const std::string& oat_path) {
+ return replace_file_extension(oat_path, ".vdex");
+}
+
static bool add_extension_to_file_name(char* file_name, const char* extension) {
if (strlen(file_name) + strlen(extension) + 1 > PKG_PATH_MAX) {
return false;
@@ -1484,8 +1510,16 @@ static bool set_permissions_and_ownership(int fd, bool is_public, int uid, const
return true;
}
+static bool IsOutputDalvikCache(const char* oat_dir) {
+ // InstallerConnection.java (which invokes installd) transforms Java null arguments
+ // into '!'. Play it safe by handling it both.
+ // TODO: ensure we never get null.
+ // TODO: pass a flag instead of inferring if the output is dalvik cache.
+ return oat_dir == nullptr || oat_dir[0] == '!';
+}
+
static bool create_oat_out_path(const char* apk_path, const char* instruction_set,
- const char* oat_dir, /*out*/ char* out_path) {
+ const char* oat_dir, /*out*/ char* out_oat_path) {
// Early best-effort check whether we can fit the the path into our buffers.
// Note: the cache path will require an additional 5 bytes for ".swap", but we'll try to run
// without a swap file, if necessary. Reference profiles file also add an extra ".prof"
@@ -1495,16 +1529,16 @@ static bool create_oat_out_path(const char* apk_path, const char* instruction_se
return false;
}
- if (oat_dir != NULL && oat_dir[0] != '!') {
+ if (!IsOutputDalvikCache(oat_dir)) {
if (validate_apk_path(oat_dir)) {
- ALOGE("invalid oat_dir '%s'\n", oat_dir);
+ ALOGE("cannot validate apk path with oat_dir '%s'\n", oat_dir);
return false;
}
- if (!calculate_oat_file_path(out_path, oat_dir, apk_path, instruction_set)) {
+ if (!calculate_oat_file_path(out_oat_path, oat_dir, apk_path, instruction_set)) {
return false;
}
} else {
- if (!create_cache_path(out_path, apk_path, instruction_set)) {
+ if (!create_cache_path(out_oat_path, apk_path, instruction_set)) {
return false;
}
}
@@ -1626,9 +1660,6 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins
bool boot_complete = (dexopt_flags & DEXOPT_BOOTCOMPLETE) != 0;
bool profile_guided = (dexopt_flags & DEXOPT_PROFILE_GUIDED) != 0;
- // Don't use profile for vm_safe_mode. b/30688277
- profile_guided = profile_guided && !vm_safe_mode;
-
CHECK(pkgname != nullptr);
CHECK(pkgname[0] != 0);
@@ -1649,8 +1680,8 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins
LOG_FATAL("dexopt flags contains unknown fields\n");
}
- char out_path[PKG_PATH_MAX];
- if (!create_oat_out_path(apk_path, instruction_set, oat_dir, out_path)) {
+ char out_oat_path[PKG_PATH_MAX];
+ if (!create_oat_out_path(apk_path, instruction_set, oat_dir, out_oat_path)) {
return false;
}
@@ -1669,7 +1700,7 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins
break;
case DEXOPT_SELF_PATCHOAT_NEEDED:
- input_file = out_path;
+ input_file = out_oat_path;
break;
default:
@@ -1681,21 +1712,82 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins
memset(&input_stat, 0, sizeof(input_stat));
stat(input_file, &input_stat);
+ // Open the input file. If running dex2oat, `input_file` is the APK. If running
+ // patchoat, it is the OAT file to be relocated.
base::unique_fd input_fd(open(input_file, O_RDONLY, 0));
if (input_fd.get() < 0) {
ALOGE("installd cannot open '%s' for input during dexopt\n", input_file);
return -1;
}
- const std::string out_path_str(out_path);
- Dex2oatFileWrapper<std::function<void ()>> out_fd(
- open_output_file(out_path, /*recreate*/true, /*permissions*/0644),
- [out_path_str]() { unlink(out_path_str.c_str()); });
- if (out_fd.get() < 0) {
- ALOGE("installd cannot open '%s' for output during dexopt\n", out_path);
+ // Create the output OAT file.
+ const std::string out_oat_path_str(out_oat_path);
+ Dex2oatFileWrapper<std::function<void ()>> out_oat_fd(
+ open_output_file(out_oat_path, /*recreate*/true, /*permissions*/0644),
+ [out_oat_path_str]() { unlink(out_oat_path_str.c_str()); });
+ if (out_oat_fd.get() < 0) {
+ ALOGE("installd cannot open '%s' for output during dexopt\n", out_oat_path);
return -1;
}
- if (!set_permissions_and_ownership(out_fd.get(), is_public, uid, out_path)) {
+ if (!set_permissions_and_ownership(out_oat_fd.get(), is_public, uid, out_oat_path)) {
+ return -1;
+ }
+
+ // Open the existing VDEX. We do this before creating the new output VDEX, which will
+ // unlink the old one.
+ base::unique_fd in_vdex_fd;
+ std::string in_vdex_path_str;
+ if (dexopt_needed == DEXOPT_PATCHOAT_NEEDED
+ || dexopt_needed == DEXOPT_SELF_PATCHOAT_NEEDED) {
+ // `input_file` is the OAT file to be relocated. The VDEX has to be there as well.
+ in_vdex_path_str = create_vdex_filename(input_file);
+ if (in_vdex_path_str.empty()) {
+ ALOGE("installd cannot compute input vdex location for '%s'\n", input_file);
+ return -1;
+ }
+ in_vdex_fd.reset(open(in_vdex_path_str.c_str(), O_RDONLY, 0));
+ if (in_vdex_fd.get() < 0) {
+ ALOGE("installd cannot open '%s' for input during dexopt: %s\n",
+ in_vdex_path_str.c_str(), strerror(errno));
+ return -1;
+ }
+ } else {
+ // Open the possibly existing vdex in the `out_oat_path`. If none exist, we pass -1
+ // to dex2oat for input-vdex-fd.
+ in_vdex_path_str = create_vdex_filename(out_oat_path);
+ if (in_vdex_path_str.empty()) {
+ ALOGE("installd cannot compute input vdex location for '%s'\n", out_oat_path);
+ return -1;
+ }
+ in_vdex_fd.reset(open(in_vdex_path_str.c_str(), O_RDONLY, 0));
+ // If there is no vdex file in out_oat_path, check if we have a vdex
+ // file next to the odex file. For other failures, we will just pass a -1 fd.
+ if (in_vdex_fd.get() < 0 && (errno == ENOENT) && IsOutputDalvikCache(oat_dir)) {
+ if (calculate_odex_file_path(in_odex_path, apk_path, instruction_set)) {
+ in_vdex_path_str = create_vdex_filename(std::string(in_odex_path));
+ if (in_vdex_path_str.empty()) {
+ ALOGE("installd cannot compute input vdex location for '%s'\n", in_odex_path);
+ return -1;
+ }
+ in_vdex_fd.reset(open(in_vdex_path_str.c_str(), O_RDONLY, 0));
+ }
+ }
+ }
+
+ // Infer the name of the output VDEX and create it.
+ const std::string out_vdex_path_str = create_vdex_filename(out_oat_path_str);
+ if (out_vdex_path_str.empty()) {
+ return -1;
+ }
+ Dex2oatFileWrapper<std::function<void ()>> out_vdex_fd(
+ open_output_file(out_vdex_path_str.c_str(), /*recreate*/true, /*permissions*/0644),
+ [out_vdex_path_str]() { unlink(out_vdex_path_str.c_str()); });
+ if (out_vdex_fd.get() < 0) {
+ ALOGE("installd cannot open '%s' for output during dexopt\n", out_vdex_path_str.c_str());
+ return -1;
+ }
+ if (!set_permissions_and_ownership(out_vdex_fd.get(), is_public,
+ uid, out_vdex_path_str.c_str())) {
return -1;
}
@@ -1704,7 +1796,7 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins
if (ShouldUseSwapFileForDexopt()) {
// Make sure there really is enough space.
char swap_file_name[PKG_PATH_MAX];
- strcpy(swap_file_name, out_path);
+ strcpy(swap_file_name, out_oat_path);
if (add_extension_to_file_name(swap_file_name, ".swap")) {
swap_fd.reset(open_output_file(swap_file_name, /*recreate*/true, /*permissions*/0600));
}
@@ -1722,8 +1814,8 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins
// Avoid generating an app image for extract only since it will not contain any classes.
Dex2oatFileWrapper<std::function<void ()>> image_fd;
- const std::string image_path = create_image_filename(out_path);
- if (!image_path.empty()) {
+ const std::string image_path = create_image_filename(out_oat_path);
+ if (dexopt_needed == DEXOPT_DEX2OAT_NEEDED && !image_path.empty()) {
char app_image_format[kPropertyValueMax];
bool have_app_image_format =
get_property("dalvik.vm.appimageformat", app_image_format, NULL) > 0;
@@ -1768,27 +1860,33 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins
drop_capabilities(uid);
SetDex2OatAndPatchOatScheduling(boot_complete);
- if (flock(out_fd.get(), LOCK_EX | LOCK_NB) != 0) {
- ALOGE("flock(%s) failed: %s\n", out_path, strerror(errno));
+ if (flock(out_oat_fd.get(), LOCK_EX | LOCK_NB) != 0) {
+ ALOGE("flock(%s) failed: %s\n", out_oat_path, strerror(errno));
_exit(67);
}
if (dexopt_needed == DEXOPT_PATCHOAT_NEEDED
|| dexopt_needed == DEXOPT_SELF_PATCHOAT_NEEDED) {
run_patchoat(input_fd.get(),
- out_fd.get(),
+ in_vdex_fd.get(),
+ out_oat_fd.get(),
+ out_vdex_fd.get(),
input_file,
- out_path,
+ in_vdex_path_str.c_str(),
+ out_oat_path,
+ out_vdex_path_str.c_str(),
pkgname,
instruction_set);
} else if (dexopt_needed == DEXOPT_DEX2OAT_NEEDED) {
// Pass dex2oat the relative path to the input file.
const char *input_file_name = get_location_from_path(input_file);
run_dex2oat(input_fd.get(),
- out_fd.get(),
+ out_oat_fd.get(),
+ in_vdex_fd.get(),
+ out_vdex_fd.get(),
image_fd.get(),
input_file_name,
- out_path,
+ out_oat_path,
swap_fd.get(),
instruction_set,
compiler_filter,
@@ -1815,10 +1913,11 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins
struct utimbuf ut;
ut.actime = input_stat.st_atime;
ut.modtime = input_stat.st_mtime;
- utime(out_path, &ut);
+ utime(out_oat_path, &ut);
// We've been successful, don't delete output.
- out_fd.SetCleanup(false);
+ out_oat_fd.SetCleanup(false);
+ out_vdex_fd.SetCleanup(false);
image_fd.SetCleanup(false);
reference_profile_fd.SetCleanup(false);
@@ -2154,7 +2253,6 @@ static bool unlink_and_rename(const char* from, const char* to) {
PLOG(ERROR) << "Could not rename " << from << " to " << to;
return false;
}
-
return true;
}
@@ -2224,36 +2322,41 @@ int move_ab(const char* apk_path, const char* instruction_set, const char* oat_d
if (!calculate_oat_file_path(a_path, oat_dir, apk_path, instruction_set)) {
return -1;
}
+ const std::string a_vdex_path = create_vdex_filename(a_path);
const std::string a_image_path = create_image_filename(a_path);
// B path = A path + slot suffix.
const std::string b_path = StringPrintf("%s.%s", a_path, slot_suffix.c_str());
+ const std::string b_vdex_path = StringPrintf("%s.%s", a_vdex_path.c_str(), slot_suffix.c_str());
const std::string b_image_path = StringPrintf("%s.%s",
a_image_path.c_str(),
slot_suffix.c_str());
- bool oat_success = move_ab_path(b_path, a_path);
- bool success;
-
- if (oat_success) {
- // Note: we can live without an app image. As such, ignore failure to move the image file.
- // If we decide to require the app image, or the app image being moved correctly,
- // then change accordingly.
- constexpr bool kIgnoreAppImageFailure = true;
-
- bool art_success = true;
- if (!a_image_path.empty()) {
- art_success = move_ab_path(b_image_path, a_image_path);
- if (!art_success) {
- unlink(a_image_path.c_str());
+ bool success = true;
+ if (move_ab_path(b_path, a_path)) {
+ if (move_ab_path(b_vdex_path, a_vdex_path)) {
+ // Note: we can live without an app image. As such, ignore failure to move the image file.
+ // If we decide to require the app image, or the app image being moved correctly,
+ // then change accordingly.
+ constexpr bool kIgnoreAppImageFailure = true;
+
+ if (!a_image_path.empty()) {
+ if (!move_ab_path(b_image_path, a_image_path)) {
+ unlink(a_image_path.c_str());
+ if (!kIgnoreAppImageFailure) {
+ success = false;
+ }
+ }
}
+ } else {
+ // Cleanup: delete B image, ignore errors.
+ unlink(b_image_path.c_str());
+ success = false;
}
-
- success = art_success || kIgnoreAppImageFailure;
} else {
// Cleanup: delete B image, ignore errors.
+ unlink(b_vdex_path.c_str());
unlink(b_image_path.c_str());
-
success = false;
}
diff --git a/cmds/installd/installd.cpp b/cmds/installd/installd.cpp
index 8f883db050..c81a33965c 100644
--- a/cmds/installd/installd.cpp
+++ b/cmds/installd/installd.cpp
@@ -65,8 +65,8 @@ bool calculate_oat_file_path(char path[PKG_PATH_MAX],
const char *oat_dir,
const char *apk_path,
const char *instruction_set) {
- char *file_name_start;
- char *file_name_end;
+ const char *file_name_start;
+ const char *file_name_end;
file_name_start = strrchr(apk_path, '/');
if (file_name_start == NULL) {
@@ -151,12 +151,11 @@ bool create_cache_path(char path[PKG_PATH_MAX],
return false;
}
- sprintf(path,"%s%s/%s/%s%s",
+ sprintf(path,"%s%s/%s/%s",
android_data_dir.path,
DALVIK_CACHE,
instruction_set,
- src + 1, /* skip the leading / */
- DALVIK_CACHE_POSTFIX);
+ src + 1 /* skip the leading / */);
char* tmp =
path +
@@ -171,6 +170,7 @@ bool create_cache_path(char path[PKG_PATH_MAX],
}
}
+ strcat(path, DALVIK_CACHE_POSTFIX);
return true;
}
diff --git a/cmds/installd/installd_constants.h b/cmds/installd/installd_constants.h
index 41732cce4f..b0bcce911a 100644
--- a/cmds/installd/installd_constants.h
+++ b/cmds/installd/installd_constants.h
@@ -28,8 +28,7 @@ constexpr const char* SECONDARY_USER_PREFIX = "user/";
// This is used as a string literal, can't be constants. TODO: std::string...
#define DALVIK_CACHE "dalvik-cache"
-constexpr const char* DALVIK_CACHE_POSTFIX = "/classes.dex";
-constexpr const char* DALVIK_CACHE_POSTFIX2 = "@classes.dex";
+constexpr const char* DALVIK_CACHE_POSTFIX = "@classes.dex";
constexpr size_t PKG_NAME_MAX = 128u; /* largest allowed package name */
constexpr size_t PKG_PATH_MAX = 256u; /* max size of any path we use */
diff --git a/cmds/installd/otapreopt.cpp b/cmds/installd/otapreopt.cpp
index 5fa972a4de..7e02b6bcfc 100644
--- a/cmds/installd/otapreopt.cpp
+++ b/cmds/installd/otapreopt.cpp
@@ -823,7 +823,7 @@ bool create_cache_path(char path[PKG_PATH_MAX],
DALVIK_CACHE,
instruction_set,
from_src.c_str(),
- DALVIK_CACHE_POSTFIX2);
+ DALVIK_CACHE_POSTFIX);
if (assembled_path.length() + 1 > PKG_PATH_MAX) {
return false;
diff --git a/cmds/installd/tests/Android.bp b/cmds/installd/tests/Android.bp
new file mode 100644
index 0000000000..447c8bdbcf
--- /dev/null
+++ b/cmds/installd/tests/Android.bp
@@ -0,0 +1,16 @@
+// Build the unit tests for installd
+cc_test {
+ name: "installd_utils_test",
+ clang: true,
+ srcs: ["installd_utils_test.cpp"],
+ shared_libs: [
+ "libbase",
+ "libutils",
+ "liblog",
+ "libcutils",
+ ],
+ static_libs: [
+ "libinstalld",
+ "libdiskusage",
+ ],
+}
diff --git a/cmds/installd/tests/Android.mk b/cmds/installd/tests/Android.mk
deleted file mode 100644
index 38a9f69964..0000000000
--- a/cmds/installd/tests/Android.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-# Build the unit tests for installd
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-# Build the unit tests.
-test_src_files := \
- installd_utils_test.cpp
-
-shared_libraries := \
- libbase \
- libutils \
- libcutils \
-
-static_libraries := \
- libinstalld \
- libdiskusage \
-
-c_includes := \
- frameworks/native/cmds/installd
-
-$(foreach file,$(test_src_files), \
- $(eval include $(CLEAR_VARS)) \
- $(eval LOCAL_SHARED_LIBRARIES := $(shared_libraries)) \
- $(eval LOCAL_STATIC_LIBRARIES := $(static_libraries)) \
- $(eval LOCAL_SRC_FILES := $(file)) \
- $(eval LOCAL_C_INCLUDES := $(c_includes)) \
- $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \
- $(eval LOCAL_CLANG := true) \
- $(eval include $(BUILD_NATIVE_TEST)) \
-)
diff --git a/cmds/service/Android.bp b/cmds/service/Android.bp
new file mode 100644
index 0000000000..8cffb3c701
--- /dev/null
+++ b/cmds/service/Android.bp
@@ -0,0 +1,13 @@
+cc_binary {
+ name: "service",
+
+ srcs: ["service.cpp"],
+
+ shared_libs: [
+ "libutils",
+ "libbinder",
+ ],
+
+ cflags: ["-DXP_UNIX"],
+ //shared_libs: ["librt"],
+}
diff --git a/cmds/service/Android.mk b/cmds/service/Android.mk
deleted file mode 100644
index 275bbb2e17..0000000000
--- a/cmds/service/Android.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- service.cpp
-
-LOCAL_SHARED_LIBRARIES := libutils libbinder
-
-ifeq ($(TARGET_OS),linux)
- LOCAL_CFLAGS += -DXP_UNIX
- #LOCAL_SHARED_LIBRARIES += librt
-endif
-
-LOCAL_MODULE:= service
-
-include $(BUILD_EXECUTABLE)
diff --git a/cmds/servicemanager/Android.bp b/cmds/servicemanager/Android.bp
new file mode 100644
index 0000000000..dc8e6759c6
--- /dev/null
+++ b/cmds/servicemanager/Android.bp
@@ -0,0 +1,36 @@
+cc_defaults {
+ name: "servicemanager_flags",
+
+ cflags: [
+ "-Wall",
+ "-Wextra",
+ "-Werror",
+ ],
+ product_variables: {
+ binder32bit: {
+ cflags: ["-DBINDER_IPC_32BIT=1"],
+ },
+ },
+
+ shared_libs: ["liblog"],
+}
+
+cc_binary {
+ name: "bctest",
+ defaults: ["servicemanager_flags"],
+ srcs: [
+ "bctest.c",
+ "binder.c",
+ ],
+}
+
+cc_binary {
+ name: "servicemanager",
+ defaults: ["servicemanager_flags"],
+ srcs: [
+ "service_manager.c",
+ "binder.c",
+ ],
+ shared_libs: ["libcutils", "libselinux"],
+ init_rc: ["servicemanager.rc"],
+}
diff --git a/cmds/servicemanager/Android.mk b/cmds/servicemanager/Android.mk
deleted file mode 100644
index b214f19efd..0000000000
--- a/cmds/servicemanager/Android.mk
+++ /dev/null
@@ -1,26 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-svc_c_flags = \
- -Wall -Wextra -Werror \
-
-ifneq ($(TARGET_USES_64_BIT_BINDER),true)
-ifneq ($(TARGET_IS_64_BIT),true)
-svc_c_flags += -DBINDER_IPC_32BIT=1
-endif
-endif
-
-include $(CLEAR_VARS)
-LOCAL_SHARED_LIBRARIES := liblog
-LOCAL_SRC_FILES := bctest.c binder.c
-LOCAL_CFLAGS += $(svc_c_flags)
-LOCAL_MODULE := bctest
-LOCAL_MODULE_TAGS := optional
-include $(BUILD_EXECUTABLE)
-
-include $(CLEAR_VARS)
-LOCAL_SHARED_LIBRARIES := liblog libcutils libselinux
-LOCAL_SRC_FILES := service_manager.c binder.c
-LOCAL_CFLAGS += $(svc_c_flags)
-LOCAL_MODULE := servicemanager
-LOCAL_INIT_RC := servicemanager.rc
-include $(BUILD_EXECUTABLE)
diff --git a/cmds/servicemanager/binder.h b/cmds/servicemanager/binder.h
index 7915fc2685..881ab07bfb 100644
--- a/cmds/servicemanager/binder.h
+++ b/cmds/servicemanager/binder.h
@@ -5,7 +5,7 @@
#define _BINDER_H_
#include <sys/ioctl.h>
-#include <linux/binder.h>
+#include <linux/android/binder.h>
struct binder_state;