diff options
224 files changed, 3472 insertions, 1440 deletions
diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000000..086a2c68c9 --- /dev/null +++ b/Android.bp @@ -0,0 +1,14 @@ +ndk_headers { + name: "libandroid_headers", + from: "include/android", + to: "android", + srcs: ["include/android/**/*.h"], +} + +subdirs = [ + "cmds/*", + "libs/*", + "opengl", + "services/*", + "vulkan", +] 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 7a9f9adcb3..e478651de0 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 libhardware_legacy # 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 45db71c1f9..e67b67f19c 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -36,6 +36,7 @@ #include <unistd.h> #include <android-base/stringprintf.h> +#include <android-base/unique_fd.h> #include <android-base/file.h> #include <cutils/properties.h> #include <hardware_legacy/power.h> @@ -46,10 +47,9 @@ #include <cutils/log.h> #include "dumpstate.h" -#include "ScopedFd.h" #include "ziparchive/zip_writer.h" -#include "mincrypt/sha256.h" +#include <openssl/sha.h> using android::base::StringPrintf; @@ -763,8 +763,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; } @@ -821,12 +822,12 @@ static bool add_text_zip_entry(const std::string& entry_name, const std::string& static void dump_iptables() { run_command("IPTABLES", 10, "iptables", "-L", "-nvx", NULL); run_command("IP6TABLES", 10, "ip6tables", "-L", "-nvx", NULL); - run_command("IPTABLE NAT", 10, "iptables", "-t", "nat", "-L", "-nvx", NULL); + run_command("IPTABLES NAT", 10, "iptables", "-t", "nat", "-L", "-nvx", NULL); /* no ip6 nat */ - run_command("IPTABLE MANGLE", 10, "iptables", "-t", "mangle", "-L", "-nvx", NULL); - run_command("IP6TABLE MANGLE", 10, "ip6tables", "-t", "mangle", "-L", "-nvx", NULL); - run_command("IPTABLE RAW", 10, "iptables", "-t", "raw", "-L", "-nvx", NULL); - run_command("IP6TABLE RAW", 10, "ip6tables", "-t", "raw", "-L", "-nvx", NULL); + run_command("IPTABLES MANGLE", 10, "iptables", "-t", "mangle", "-L", "-nvx", NULL); + run_command("IP6TABLES MANGLE", 10, "ip6tables", "-t", "mangle", "-L", "-nvx", NULL); + run_command("IPTABLES RAW", 10, "iptables", "-t", "raw", "-L", "-nvx", NULL); + run_command("IP6TABLES RAW", 10, "ip6tables", "-t", "raw", "-L", "-nvx", NULL); } static void dumpstate(const std::string& screenshot_path, const std::string& version) { @@ -838,7 +839,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"); @@ -852,7 +854,8 @@ 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); @@ -866,6 +869,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); @@ -1208,15 +1214,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) { @@ -1228,13 +1234,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; @@ -1533,6 +1540,9 @@ int main(int argc, char *argv[]) { add_mountinfo(); dump_iptables(); + // Capture any IPSec policies in play. No keys are exposed here. + run_command("IP XFRM POLICY", 10, "ip", "xfrm", "policy", nullptr); + // Run ss as root so we can see socket marks. run_command("DETAILED SOCKET STATE", 10, "ss", "-eionptu", NULL); diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h index 5e083cc002..905fc2276a 100644 --- a/cmds/dumpstate/dumpstate.h +++ b/cmds/dumpstate/dumpstate.h @@ -218,7 +218,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 1035cde9d4..0d9cce28bb 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,8 @@ 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_WAKELOCK }; + AID_MOUNT, AID_INET, AID_NET_BW_STATS, AID_READPROC, AID_WAKELOCK, + 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 4ed8997fcb..1d291ca7ce 100644 --- a/cmds/installd/commands.cpp +++ b/cmds/installd/commands.cpp @@ -739,8 +739,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; @@ -754,35 +756,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 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) { @@ -863,6 +874,7 @@ 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 vdex_fd_arg[strlen("--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]; @@ -878,6 +890,7 @@ 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(vdex_fd_arg, "--vdex-fd=%d", 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); @@ -940,7 +953,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[8 // 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) @@ -961,6 +974,7 @@ 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++] = vdex_fd_arg; argv[i++] = oat_fd_arg; argv[i++] = oat_location_arg; argv[i++] = instruction_set_arg; @@ -1418,31 +1432,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; @@ -1478,7 +1501,7 @@ static bool set_permissions_and_ownership(int fd, bool is_public, int uid, const } 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" @@ -1493,11 +1516,11 @@ static bool create_oat_out_path(const char* apk_path, const char* instruction_se ALOGE("invalid 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; } } @@ -1619,9 +1642,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); @@ -1642,8 +1662,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; } @@ -1662,7 +1682,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: @@ -1674,21 +1694,57 @@ 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); + // If invoking patchoat, open the VDEX associated with the OAT too. + std::string in_vdex_path_str; + base::unique_fd input_vdex_fd; + if (dexopt_needed == DEXOPT_PATCHOAT_NEEDED + || dexopt_needed == DEXOPT_SELF_PATCHOAT_NEEDED) { + in_vdex_path_str = create_vdex_filename(input_file); + if (in_vdex_path_str.empty()) { + return -1; + } + input_vdex_fd.reset(open(in_vdex_path_str.c_str(), O_RDONLY, 0)); + if (input_vdex_fd.get() < 0) { + ALOGE("installd cannot open '%s' for input during dexopt\n", in_vdex_path_str.c_str()); + return -1; + } + } + + // 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_oat_fd.get(), is_public, uid, out_oat_path)) { + return -1; + } + + // 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_fd.get(), is_public, uid, out_path)) { + if (!set_permissions_and_ownership(out_vdex_fd.get(), is_public, + uid, out_vdex_path_str.c_str())) { return -1; } @@ -1697,7 +1753,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)); } @@ -1715,8 +1771,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; @@ -1761,27 +1817,32 @@ 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(), + input_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(), + out_vdex_fd.get(), image_fd.get(), input_file_name, - out_path, + out_oat_path, swap_fd.get(), instruction_set, compiler_filter, @@ -1808,10 +1869,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); @@ -2147,7 +2209,6 @@ static bool unlink_and_rename(const char* from, const char* to) { PLOG(ERROR) << "Could not rename " << from << " to " << to; return false; } - return true; } @@ -2217,36 +2278,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; diff --git a/include/android/asset_manager.h b/include/android/asset_manager.h index d65483968e..7ef3ecb595 100644 --- a/include/android/asset_manager.h +++ b/include/android/asset_manager.h @@ -26,6 +26,9 @@ #ifndef ANDROID_ASSET_MANAGER_H #define ANDROID_ASSET_MANAGER_H +#include <sys/cdefs.h> +#include <sys/types.h> + #ifdef __cplusplus extern "C" { #endif @@ -131,6 +134,7 @@ int AAsset_read(AAsset* asset, void* buf, size_t count); */ off_t AAsset_seek(AAsset* asset, off_t offset, int whence); +#if __ANDROID_API__ >= 13 /** * Seek to the specified offset within the asset data. 'whence' uses the * same constants as lseek()/fseek(). @@ -141,6 +145,7 @@ off_t AAsset_seek(AAsset* asset, off_t offset, int whence); * Returns the new position on success, or (off64_t) -1 on error. */ off64_t AAsset_seek64(AAsset* asset, off64_t offset, int whence); +#endif /** * Close the asset, freeing all associated resources. @@ -159,23 +164,27 @@ const void* AAsset_getBuffer(AAsset* asset); */ off_t AAsset_getLength(AAsset* asset); +#if __ANDROID_API__ >= 13 /** * Report the total size of the asset data. Reports the size using a 64-bit * number insted of 32-bit as AAsset_getLength. */ off64_t AAsset_getLength64(AAsset* asset); +#endif /** * Report the total amount of asset data that can be read from the current position. */ off_t AAsset_getRemainingLength(AAsset* asset); +#if __ANDROID_API__ >= 13 /** * Report the total amount of asset data that can be read from the current position. * * Uses a 64-bit number instead of a 32-bit number as AAsset_getRemainingLength does. */ off64_t AAsset_getRemainingLength64(AAsset* asset); +#endif /** * Open a new file descriptor that can be used to read the asset data. If the @@ -187,6 +196,7 @@ off64_t AAsset_getRemainingLength64(AAsset* asset); */ int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength); +#if __ANDROID_API__ >= 13 /** * Open a new file descriptor that can be used to read the asset data. * @@ -197,6 +207,7 @@ int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength); * compressed). */ int AAsset_openFileDescriptor64(AAsset* asset, off64_t* outStart, off64_t* outLength); +#endif /** * Returns whether this asset's internal buffer is allocated in ordinary RAM (i.e. not diff --git a/include/android/choreographer.h b/include/android/choreographer.h index 02c83dc07c..43346fe83f 100644 --- a/include/android/choreographer.h +++ b/include/android/choreographer.h @@ -30,6 +30,8 @@ __BEGIN_DECLS +#if __ANDROID_API__ >= 24 + struct AChoreographer; typedef struct AChoreographer AChoreographer; @@ -62,6 +64,9 @@ void AChoreographer_postFrameCallback(AChoreographer* choreographer, */ void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer, AChoreographer_frameCallback callback, void* data, long delayMillis); + +#endif /* __ANDROID_API__ >= 24 */ + __END_DECLS #endif // ANDROID_CHOREOGRAPHER_H diff --git a/include/android/configuration.h b/include/android/configuration.h index 81f71a92cb..8e10f67662 100644 --- a/include/android/configuration.h +++ b/include/android/configuration.h @@ -26,6 +26,8 @@ #ifndef ANDROID_CONFIGURATION_H #define ANDROID_CONFIGURATION_H +#include <sys/cdefs.h> + #include <android/asset_manager.h> #ifdef __cplusplus @@ -628,6 +630,7 @@ int32_t AConfiguration_getUiModeNight(AConfiguration* config); */ void AConfiguration_setUiModeNight(AConfiguration* config, int32_t uiModeNight); +#if __ANDROID_API__ >= 13 /** * Return the current configuration screen width in dp units, or * ACONFIGURATION_SCREEN_WIDTH_DP_ANY if not set. @@ -660,7 +663,9 @@ int32_t AConfiguration_getSmallestScreenWidthDp(AConfiguration* config); * Set the configuration's smallest screen width in dp units. */ void AConfiguration_setSmallestScreenWidthDp(AConfiguration* config, int32_t value); +#endif /* __ANDROID_API__ >= 13 */ +#if __ANDROID_API__ >= 17 /** * Return the configuration's layout direction, or * ACONFIGURATION_LAYOUTDIR_ANY if not set. @@ -671,6 +676,7 @@ int32_t AConfiguration_getLayoutDirection(AConfiguration* config); * Set the configuration's layout direction. */ void AConfiguration_setLayoutDirection(AConfiguration* config, int32_t value); +#endif /* __ANDROID_API__ >= 17 */ /** * Perform a diff between two configurations. Returns a bit mask of diff --git a/include/android/input.h b/include/android/input.h index fd9fa98e70..f928c6e4f0 100644 --- a/include/android/input.h +++ b/include/android/input.h @@ -26,6 +26,8 @@ #ifndef _ANDROID_INPUT_H #define _ANDROID_INPUT_H +#include <sys/cdefs.h> + /****************************************************************** * * IMPORTANT NOTICE: @@ -978,8 +980,10 @@ int32_t AMotionEvent_getFlags(const AInputEvent* motion_event); */ int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event); +#if __ANDROID_API__ >= 14 /** Get the button state of all buttons that are pressed. */ int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event); +#endif /** * Get a bitfield indicating which edges, if any, were touched by this motion event. @@ -1044,12 +1048,14 @@ size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event); */ int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index); +#if __ANDROID_API__ >= 14 /** * Get the tool type of a pointer for the given pointer index. * The tool type indicates the type of tool used to make contact such as a * finger or stylus, if known. */ int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index); +#endif /** * Get the original raw X coordinate of this event. @@ -1139,9 +1145,11 @@ float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_ */ float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index); +#if __ANDROID_API__ >= 13 /** Get the value of the request axis for the given pointer index. */ float AMotionEvent_getAxisValue(const AInputEvent* motion_event, int32_t axis, size_t pointer_index); +#endif /** * Get the number of historical points in this event. These are movements that @@ -1272,12 +1280,14 @@ float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_ float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index, size_t history_index); +#if __ANDROID_API__ >= 13 /** * Get the historical value of the request axis for the given pointer index * that occurred between this event and the previous motion event. */ float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event, int32_t axis, size_t pointer_index, size_t history_index); +#endif struct AInputQueue; diff --git a/include/android/multinetwork.h b/include/android/multinetwork.h index 6c718c9037..be0151881a 100644 --- a/include/android/multinetwork.h +++ b/include/android/multinetwork.h @@ -51,6 +51,7 @@ typedef uint64_t net_handle_t; * on failure with an appropriate errno value set. */ +#if __ANDROID_API__ >= 24 /** * Set the network to be used by the given socket file descriptor. @@ -104,6 +105,8 @@ int android_getaddrinfofornetwork(net_handle_t network, const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res); +#endif /* __ANDROID_API__ >= 24 */ + __END_DECLS #endif // ANDROID_MULTINETWORK_H diff --git a/include/android/native_window.h b/include/android/native_window.h index cf07f1afad..b60b9f1d9c 100644 --- a/include/android/native_window.h +++ b/include/android/native_window.h @@ -26,6 +26,8 @@ #ifndef ANDROID_NATIVE_WINDOW_H #define ANDROID_NATIVE_WINDOW_H +#include <sys/cdefs.h> + #include <android/rect.h> #ifdef __cplusplus diff --git a/include/android/native_window_jni.h b/include/android/native_window_jni.h index 60a36c3f27..1ec2a67c3d 100644 --- a/include/android/native_window_jni.h +++ b/include/android/native_window_jni.h @@ -26,6 +26,8 @@ #ifndef ANDROID_NATIVE_WINDOW_JNI_H #define ANDROID_NATIVE_WINDOW_JNI_H +#include <sys/cdefs.h> + #include <android/native_window.h> #include <jni.h> @@ -42,6 +44,16 @@ extern "C" { */ ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface); +#if __ANDROID_API__ >= 13 +/** + * Return the ANativeWindow associated with a Java SurfaceTexture object, + * for interacting with it through native code. This acquires a reference + * on the ANativeWindow that is returned; be sure to use ANativeWindow_release() + * when done with it so that it doesn't leak. + */ +ANativeWindow* ANativeWindow_fromSurfaceTexture(JNIEnv* env, jobject surfaceTexture); +#endif + #ifdef __cplusplus }; #endif diff --git a/include/android/sensor.h b/include/android/sensor.h index 5a61213f53..b6a42ae34b 100644 --- a/include/android/sensor.h +++ b/include/android/sensor.h @@ -367,12 +367,14 @@ int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list); */ ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type); +#if __ANDROID_API__ >= 21 /** * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor * of this type and wakeUp properties exists. */ ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp); +#endif /** * Creates a new sensor event queue and associate it with a looper. @@ -471,6 +473,7 @@ float ASensor_getResolution(ASensor const* sensor); */ int ASensor_getMinDelay(ASensor const* sensor); +#if __ANDROID_API__ >= 21 /** * Returns the maximum size of batches for this sensor. Batches will often be * smaller, as the hardware fifo might be used for other sensors. @@ -496,6 +499,7 @@ int ASensor_getReportingMode(ASensor const* sensor); * Returns true if this is a wake up sensor, false otherwise. */ bool ASensor_isWakeUpSensor(ASensor const* sensor); +#endif /* __ANDROID_API__ >= 21 */ #ifdef __cplusplus }; diff --git a/include/android/trace.h b/include/android/trace.h index e42e334102..6cdcfebb78 100644 --- a/include/android/trace.h +++ b/include/android/trace.h @@ -19,11 +19,14 @@ #define ANDROID_NATIVE_TRACE_H #include <stdbool.h> +#include <sys/cdefs.h> #ifdef __cplusplus extern "C" { #endif +#if __ANDROID_API__ >= 23 + /** * Returns true if tracing is enabled. Use this signal to avoid expensive computation only necessary * when tracing is enabled. @@ -48,6 +51,8 @@ void ATrace_beginSection(const char* sectionName); */ void ATrace_endSection(); +#endif /* __ANDROID_API__ >= 23 */ + #ifdef __cplusplus }; #endif diff --git a/include/batteryservice/IBatteryPropertiesListener.h b/include/batteryservice/IBatteryPropertiesListener.h index b02d8e9073..9154076eb3 100644 --- a/include/batteryservice/IBatteryPropertiesListener.h +++ b/include/batteryservice/IBatteryPropertiesListener.h @@ -33,7 +33,7 @@ enum { class IBatteryPropertiesListener : public IInterface { public: - DECLARE_META_INTERFACE(BatteryPropertiesListener); + DECLARE_META_INTERFACE(BatteryPropertiesListener) virtual void batteryPropertiesChanged(struct BatteryProperties props) = 0; }; diff --git a/include/batteryservice/IBatteryPropertiesRegistrar.h b/include/batteryservice/IBatteryPropertiesRegistrar.h index eca075d7ef..b5c3a4d9ab 100644 --- a/include/batteryservice/IBatteryPropertiesRegistrar.h +++ b/include/batteryservice/IBatteryPropertiesRegistrar.h @@ -31,7 +31,7 @@ enum { class IBatteryPropertiesRegistrar : public IInterface { public: - DECLARE_META_INTERFACE(BatteryPropertiesRegistrar); + DECLARE_META_INTERFACE(BatteryPropertiesRegistrar) virtual void registerListener(const sp<IBatteryPropertiesListener>& listener) = 0; virtual void unregisterListener(const sp<IBatteryPropertiesListener>& listener) = 0; diff --git a/include/binder/Binder.h b/include/binder/Binder.h index f849fd4327..34048816cd 100644 --- a/include/binder/Binder.h +++ b/include/binder/Binder.h @@ -80,7 +80,7 @@ private: class BpRefBase : public virtual RefBase { protected: - BpRefBase(const sp<IBinder>& o); + explicit BpRefBase(const sp<IBinder>& o); virtual ~BpRefBase(); virtual void onFirstRef(); virtual void onLastStrongRef(const void* id); diff --git a/include/binder/IAppOpsCallback.h b/include/binder/IAppOpsCallback.h index 7f8eb0168b..b62e9e264d 100644 --- a/include/binder/IAppOpsCallback.h +++ b/include/binder/IAppOpsCallback.h @@ -27,7 +27,7 @@ namespace android { class IAppOpsCallback : public IInterface { public: - DECLARE_META_INTERFACE(AppOpsCallback); + DECLARE_META_INTERFACE(AppOpsCallback) virtual void opChanged(int32_t op, const String16& packageName) = 0; diff --git a/include/binder/IAppOpsService.h b/include/binder/IAppOpsService.h index cd81efa363..dc18045975 100644 --- a/include/binder/IAppOpsService.h +++ b/include/binder/IAppOpsService.h @@ -28,7 +28,7 @@ namespace android { class IAppOpsService : public IInterface { public: - DECLARE_META_INTERFACE(AppOpsService); + DECLARE_META_INTERFACE(AppOpsService) virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) = 0; virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName) = 0; diff --git a/include/binder/IBatteryStats.h b/include/binder/IBatteryStats.h index 5f3818652b..e15d6f07e9 100644 --- a/include/binder/IBatteryStats.h +++ b/include/binder/IBatteryStats.h @@ -26,7 +26,7 @@ namespace android { class IBatteryStats : public IInterface { public: - DECLARE_META_INTERFACE(BatteryStats); + DECLARE_META_INTERFACE(BatteryStats) virtual void noteStartSensor(int uid, int sensor) = 0; virtual void noteStopSensor(int uid, int sensor) = 0; diff --git a/include/binder/IBinder.h b/include/binder/IBinder.h index 5f1e87cd5e..9097cb3bb9 100644 --- a/include/binder/IBinder.h +++ b/include/binder/IBinder.h @@ -90,12 +90,24 @@ public: Parcel* reply, uint32_t flags = 0) = 0; + // DeathRecipient is pure abstract, there is no virtual method + // implementation to put in a translation unit in order to silence the + // weak vtables warning. + #if defined(__clang__) + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wweak-vtables" + #endif + class DeathRecipient : public virtual RefBase { public: virtual void binderDied(const wp<IBinder>& who) = 0; }; + #if defined(__clang__) + #pragma clang diagnostic pop + #endif + /** * Register the @a recipient for a notification if this binder * goes away. If this binder object unexpectedly goes away diff --git a/include/binder/IInterface.h b/include/binder/IInterface.h index 4ce361380d..be72d44759 100644 --- a/include/binder/IInterface.h +++ b/include/binder/IInterface.h @@ -63,7 +63,7 @@ template<typename INTERFACE> class BpInterface : public INTERFACE, public BpRefBase { public: - BpInterface(const sp<IBinder>& remote); + explicit BpInterface(const sp<IBinder>& remote); protected: virtual IBinder* onAsBinder(); @@ -105,7 +105,7 @@ protected: #define CHECK_INTERFACE(interface, data, reply) \ - if (!data.checkInterface(this)) { return PERMISSION_DENIED; } \ + if (!(data).checkInterface(this)) { return PERMISSION_DENIED; } \ // ---------------------------------------------------------------------- diff --git a/include/binder/IMediaResourceMonitor.h b/include/binder/IMediaResourceMonitor.h index c671f7a529..b21047fc49 100644 --- a/include/binder/IMediaResourceMonitor.h +++ b/include/binder/IMediaResourceMonitor.h @@ -25,7 +25,7 @@ namespace android { class IMediaResourceMonitor : public IInterface { public: - DECLARE_META_INTERFACE(MediaResourceMonitor); + DECLARE_META_INTERFACE(MediaResourceMonitor) // Values should be in sync with Intent.EXTRA_MEDIA_RESOURCE_TYPE_XXX. enum { diff --git a/include/binder/IMemory.h b/include/binder/IMemory.h index 2d0db001c6..15a104fe6a 100644 --- a/include/binder/IMemory.h +++ b/include/binder/IMemory.h @@ -32,7 +32,7 @@ namespace android { class IMemoryHeap : public IInterface { public: - DECLARE_META_INTERFACE(MemoryHeap); + DECLARE_META_INTERFACE(MemoryHeap) // flags returned by getFlags() enum { @@ -70,7 +70,7 @@ protected: class IMemory : public IInterface { public: - DECLARE_META_INTERFACE(Memory); + DECLARE_META_INTERFACE(Memory) virtual sp<IMemoryHeap> getMemory(ssize_t* offset=0, size_t* size=0) const = 0; diff --git a/include/binder/IPermissionController.h b/include/binder/IPermissionController.h index 4e5fb34838..25f34313f0 100644 --- a/include/binder/IPermissionController.h +++ b/include/binder/IPermissionController.h @@ -28,7 +28,7 @@ namespace android { class IPermissionController : public IInterface { public: - DECLARE_META_INTERFACE(PermissionController); + DECLARE_META_INTERFACE(PermissionController) virtual bool checkPermission(const String16& permission, int32_t pid, int32_t uid) = 0; diff --git a/include/binder/IProcessInfoService.h b/include/binder/IProcessInfoService.h index 69dc9a79f1..2669f9193d 100644 --- a/include/binder/IProcessInfoService.h +++ b/include/binder/IProcessInfoService.h @@ -25,7 +25,7 @@ namespace android { class IProcessInfoService : public IInterface { public: - DECLARE_META_INTERFACE(ProcessInfoService); + DECLARE_META_INTERFACE(ProcessInfoService) virtual status_t getProcessStatesFromPids( size_t length, /*in*/ int32_t* pids, diff --git a/include/binder/IResultReceiver.h b/include/binder/IResultReceiver.h index 02dc6a63b6..e494fba0b8 100644 --- a/include/binder/IResultReceiver.h +++ b/include/binder/IResultReceiver.h @@ -27,7 +27,7 @@ namespace android { class IResultReceiver : public IInterface { public: - DECLARE_META_INTERFACE(ResultReceiver); + DECLARE_META_INTERFACE(ResultReceiver) virtual void send(int32_t resultCode) = 0; diff --git a/include/binder/IServiceManager.h b/include/binder/IServiceManager.h index 7ccd9fefd3..3b23f81e43 100644 --- a/include/binder/IServiceManager.h +++ b/include/binder/IServiceManager.h @@ -30,7 +30,7 @@ namespace android { class IServiceManager : public IInterface { public: - DECLARE_META_INTERFACE(ServiceManager); + DECLARE_META_INTERFACE(ServiceManager) /** * Retrieve an existing service, blocking for a few seconds diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index 1c355c4689..74e75d74fc 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h @@ -20,14 +20,14 @@ #include <string> #include <vector> +#include <android-base/unique_fd.h> #include <cutils/native_handle.h> -#include <nativehelper/ScopedFd.h> #include <utils/Errors.h> #include <utils/RefBase.h> #include <utils/String16.h> #include <utils/Vector.h> #include <utils/Flattenable.h> -#include <linux/binder.h> +#include <linux/android/binder.h> #include <binder/IInterface.h> #include <binder/Parcelable.h> @@ -166,6 +166,10 @@ public: template<typename T> status_t write(const LightFlattenable<T>& val); + template<typename T> + status_t writeVectorSize(const std::vector<T>& val); + template<typename T> + status_t writeVectorSize(const std::unique_ptr<std::vector<T>>& val); // Place a native_handle into the parcel (the native_handle's file- // descriptors are dup'ed, so it is safe to delete the native_handle @@ -186,14 +190,14 @@ public: // semantics of the smart file descriptor. A new descriptor will be // created, and will be closed when the parcel is destroyed. status_t writeUniqueFileDescriptor( - const ScopedFd& fd); + const base::unique_fd& fd); // Place a vector of file desciptors into the parcel. Each descriptor is // dup'd as in writeDupFileDescriptor status_t writeUniqueFileDescriptorVector( - const std::unique_ptr<std::vector<ScopedFd>>& val); + const std::unique_ptr<std::vector<base::unique_fd>>& val); status_t writeUniqueFileDescriptorVector( - const std::vector<ScopedFd>& val); + const std::vector<base::unique_fd>& val); // Writes a blob to the parcel. // If the blob is small, then it is stored in-place, otherwise it is @@ -246,12 +250,14 @@ public: const char* readCString() const; String8 readString8() const; + status_t readString8(String8* pArg) const; String16 readString16() const; status_t readString16(String16* pArg) const; status_t readString16(std::unique_ptr<String16>* pArg) const; const char16_t* readString16Inplace(size_t* outLen) const; sp<IBinder> readStrongBinder() const; status_t readStrongBinder(sp<IBinder>* val) const; + status_t readNullableStrongBinder(sp<IBinder>* val) const; wp<IBinder> readWeakBinder() const; template<typename T> @@ -268,6 +274,9 @@ public: template<typename T> status_t readStrongBinder(sp<T>* val) const; + template<typename T> + status_t readNullableStrongBinder(sp<T>* val) const; + status_t readStrongBinderVector(std::unique_ptr<std::vector<sp<IBinder>>>* val) const; status_t readStrongBinderVector(std::vector<sp<IBinder>>* val) const; @@ -300,6 +309,11 @@ public: template<typename T> status_t read(LightFlattenable<T>& val) const; + template<typename T> + status_t resizeOutVector(std::vector<T>* val) const; + template<typename T> + status_t resizeOutVector(std::unique_ptr<std::vector<T>>* val) const; + // Like Parcel.java's readExceptionCode(). Reads the first int32 // off of a Parcel's header, returning 0 or the negative error // code on exceptions, but also deals with skipping over rich @@ -320,14 +334,14 @@ public: // Retrieve a smart file descriptor from the parcel. status_t readUniqueFileDescriptor( - ScopedFd* val) const; + base::unique_fd* val) const; // Retrieve a vector of smart file descriptors from the parcel. status_t readUniqueFileDescriptorVector( - std::unique_ptr<std::vector<ScopedFd>>* val) const; + std::unique_ptr<std::vector<base::unique_fd>>* val) const; status_t readUniqueFileDescriptorVector( - std::vector<ScopedFd>* val) const; + std::vector<base::unique_fd>* val) const; // Reads a blob from the parcel. // The caller should call release() on the blob after reading its contents. @@ -437,7 +451,7 @@ private: void clear(); void release(); inline size_t size() const { return mSize; } - inline int fd() const { return mFd; }; + inline int fd() const { return mFd; } inline bool isMutable() const { return mMutable; } protected: @@ -449,6 +463,11 @@ private: bool mMutable; }; + #if defined(__clang__) + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wweak-vtables" + #endif + class FlattenableHelperInterface { protected: ~FlattenableHelperInterface() { } @@ -459,12 +478,18 @@ private: virtual status_t unflatten(void const* buffer, size_t size, int const* fds, size_t count) = 0; }; + #if defined(__clang__) + #pragma clang diagnostic pop + #endif + template<typename T> class FlattenableHelper : public FlattenableHelperInterface { friend class Parcel; const Flattenable<T>& val; - explicit FlattenableHelper(const Flattenable<T>& val) : val(val) { } + explicit FlattenableHelper(const Flattenable<T>& _val) : val(_val) { } + protected: + ~FlattenableHelper() = default; public: virtual size_t getFlattenedSize() const { return val.getFlattenedSize(); @@ -517,7 +542,10 @@ template<typename T> status_t Parcel::write(const LightFlattenable<T>& val) { size_t size(val.getFlattenedSize()); if (!val.isFixedSize()) { - status_t err = writeInt32(size); + if (size > INT32_MAX) { + return BAD_VALUE; + } + status_t err = writeInt32(static_cast<int32_t>(size)); if (err != NO_ERROR) { return err; } @@ -548,7 +576,7 @@ status_t Parcel::read(LightFlattenable<T>& val) const { if (err != NO_ERROR) { return err; } - size = s; + size = static_cast<size_t>(s); } if (size) { void const* buffer = readInplace(size); @@ -559,6 +587,54 @@ status_t Parcel::read(LightFlattenable<T>& val) const { } template<typename T> +status_t Parcel::writeVectorSize(const std::vector<T>& val) { + if (val.size() > INT32_MAX) { + return BAD_VALUE; + } + return writeInt32(static_cast<int32_t>(val.size())); +} + +template<typename T> +status_t Parcel::writeVectorSize(const std::unique_ptr<std::vector<T>>& val) { + if (!val) { + return writeInt32(-1); + } + + return writeVectorSize(*val); +} + +template<typename T> +status_t Parcel::resizeOutVector(std::vector<T>* val) const { + int32_t size; + status_t err = readInt32(&size); + if (err != NO_ERROR) { + return err; + } + + if (size < 0) { + return UNEXPECTED_NULL; + } + val->resize(size_t(size)); + return OK; +} + +template<typename T> +status_t Parcel::resizeOutVector(std::unique_ptr<std::vector<T>>* val) const { + int32_t size; + status_t err = readInt32(&size); + if (err != NO_ERROR) { + return err; + } + + val->reset(); + if (size >= 0) { + val->reset(new std::vector<T>(size_t(size))); + } + + return OK; +} + +template<typename T> status_t Parcel::readStrongBinder(sp<T>* val) const { sp<IBinder> tmp; status_t ret = readStrongBinder(&tmp); @@ -574,6 +650,22 @@ status_t Parcel::readStrongBinder(sp<T>* val) const { return ret; } +template<typename T> +status_t Parcel::readNullableStrongBinder(sp<T>* val) const { + sp<IBinder> tmp; + status_t ret = readNullableStrongBinder(&tmp); + + if (ret == OK) { + *val = interface_cast<T>(tmp); + + if (val->get() == nullptr && tmp.get() != nullptr) { + ret = UNKNOWN_ERROR; + } + } + + return ret; +} + template<typename T, typename U> status_t Parcel::unsafeReadTypedVector( std::vector<T>* val, @@ -589,7 +681,7 @@ status_t Parcel::unsafeReadTypedVector( return UNEXPECTED_NULL; } - val->resize(size); + val->resize(static_cast<size_t>(size)); for (auto& v: *val) { status = (this->*read_func)(&v); @@ -611,7 +703,7 @@ status_t Parcel::readTypedVector(std::vector<T>* val, template<typename T> status_t Parcel::readNullableTypedVector(std::unique_ptr<std::vector<T>>* val, status_t(Parcel::*read_func)(T*) const) const { - const int32_t start = dataPosition(); + const size_t start = dataPosition(); int32_t size; status_t status = readInt32(&size); val->reset(); @@ -639,7 +731,7 @@ status_t Parcel::unsafeWriteTypedVector(const std::vector<T>& val, return BAD_VALUE; } - status_t status = this->writeInt32(val.size()); + status_t status = this->writeInt32(static_cast<int32_t>(val.size())); if (status != OK) { return status; @@ -695,7 +787,7 @@ status_t Parcel::readParcelableVector(std::vector<T>* val) const { template<typename T> status_t Parcel::readParcelableVector(std::unique_ptr<std::vector<std::unique_ptr<T>>>* val) const { - const int32_t start = dataPosition(); + const size_t start = dataPosition(); int32_t size; status_t status = readInt32(&size); val->reset(); @@ -718,7 +810,7 @@ status_t Parcel::readParcelableVector(std::unique_ptr<std::vector<std::unique_pt template<typename T> status_t Parcel::readParcelable(std::unique_ptr<T>* parcelable) const { - const int32_t start = dataPosition(); + const size_t start = dataPosition(); int32_t present; status_t status = readInt32(&present); parcelable->reset(); diff --git a/include/binder/Parcelable.h b/include/binder/Parcelable.h index faf0d34e9f..d5b57ac587 100644 --- a/include/binder/Parcelable.h +++ b/include/binder/Parcelable.h @@ -26,6 +26,11 @@ namespace android { class Parcel; +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#endif + // Abstract interface of all parcelables. class Parcelable { public: @@ -46,6 +51,10 @@ public: virtual status_t readFromParcel(const Parcel* parcel) = 0; }; // class Parcelable +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + } // namespace android #endif // ANDROID_PARCELABLE_H diff --git a/include/binder/PersistableBundle.h b/include/binder/PersistableBundle.h index fe5619fc52..322fef9e4f 100644 --- a/include/binder/PersistableBundle.h +++ b/include/binder/PersistableBundle.h @@ -18,6 +18,7 @@ #define ANDROID_PERSISTABLE_BUNDLE_H #include <map> +#include <set> #include <vector> #include <binder/Parcelable.h> @@ -79,6 +80,19 @@ public: bool getStringVector(const String16& key, std::vector<String16>* out) const; bool getPersistableBundle(const String16& key, PersistableBundle* out) const; + /* Getters for all keys for each value type */ + std::set<String16> getBooleanKeys() const; + std::set<String16> getIntKeys() const; + std::set<String16> getLongKeys() const; + std::set<String16> getDoubleKeys() const; + std::set<String16> getStringKeys() const; + std::set<String16> getBooleanVectorKeys() const; + std::set<String16> getIntVectorKeys() const; + std::set<String16> getLongVectorKeys() const; + std::set<String16> getDoubleVectorKeys() const; + std::set<String16> getStringVectorKeys() const; + std::set<String16> getPersistableBundleKeys() const; + friend bool operator==(const PersistableBundle& lhs, const PersistableBundle& rhs) { return (lhs.mBoolMap == rhs.mBoolMap && lhs.mIntMap == rhs.mIntMap && lhs.mLongMap == rhs.mLongMap && lhs.mDoubleMap == rhs.mDoubleMap && diff --git a/include/binder/Status.h b/include/binder/Status.h index ce947fa3de..dd61616f24 100644 --- a/include/binder/Status.h +++ b/include/binder/Status.h @@ -18,6 +18,7 @@ #define ANDROID_BINDER_STATUS_H #include <cstdint> +#include <sstream> #include <binder/Parcel.h> #include <utils/String8.h> @@ -71,6 +72,7 @@ public: // A more readable alias for the default constructor. static Status ok(); + // Authors should explicitly pick whether their integer is: // - an exception code (EX_* above) // - service specific error code @@ -83,9 +85,15 @@ public: static Status fromExceptionCode(int32_t exceptionCode); static Status fromExceptionCode(int32_t exceptionCode, const String8& message); + static Status fromExceptionCode(int32_t exceptionCode, + const char* message); + static Status fromServiceSpecificError(int32_t serviceSpecificErrorCode); static Status fromServiceSpecificError(int32_t serviceSpecificErrorCode, const String8& message); + static Status fromServiceSpecificError(int32_t serviceSpecificErrorCode, + const char* message); + static Status fromStatusT(status_t status); Status() = default; @@ -142,11 +150,7 @@ private: }; // class Status // For gtest output logging -template<typename T> -T& operator<< (T& stream, const Status& s) { - stream << s.toString8().string(); - return stream; -} +std::stringstream& operator<< (std::stringstream& stream, const Status& s); } // namespace binder } // namespace android diff --git a/include/gui/BufferItem.h b/include/gui/BufferItem.h index f45d85207a..5232d0f69e 100644 --- a/include/gui/BufferItem.h +++ b/include/gui/BufferItem.h @@ -46,6 +46,8 @@ class BufferItem : public Flattenable<BufferItem> { enum { INVALID_BUFFER_SLOT = -1 }; BufferItem(); ~BufferItem(); + BufferItem(const BufferItem&) = default; + BufferItem& operator=(const BufferItem&) = default; static const char* scalingModeName(uint32_t scalingMode); @@ -72,13 +74,7 @@ class BufferItem : public Flattenable<BufferItem> { // to set by queueBuffer each time this slot is queued. This value // is guaranteed to be monotonically increasing for each newly // acquired buffer. - union { - int64_t mTimestamp; - struct { - uint32_t mTimestampLo; - uint32_t mTimestampHi; - }; - }; + int64_t mTimestamp; // mIsAutoTimestamp indicates whether mTimestamp was generated // automatically when the buffer was queued. @@ -90,13 +86,7 @@ class BufferItem : public Flattenable<BufferItem> { android_dataspace mDataSpace; // mFrameNumber is the number of the queued frame for this slot. - union { - uint64_t mFrameNumber; - struct { - uint32_t mFrameNumberLo; - uint32_t mFrameNumberHi; - }; - }; + uint64_t mFrameNumber; // mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT). int mSlot; diff --git a/include/gui/BufferQueue.h b/include/gui/BufferQueue.h index fe4b1fa830..266f0aa501 100644 --- a/include/gui/BufferQueue.h +++ b/include/gui/BufferQueue.h @@ -60,7 +60,7 @@ public: // weak references. class ProxyConsumerListener : public BnConsumerListener { public: - ProxyConsumerListener(const wp<ConsumerListener>& consumerListener); + explicit ProxyConsumerListener(const wp<ConsumerListener>& consumerListener); virtual ~ProxyConsumerListener(); virtual void onFrameAvailable(const BufferItem& item) override; virtual void onFrameReplaced(const BufferItem& item) override; diff --git a/include/gui/BufferQueueConsumer.h b/include/gui/BufferQueueConsumer.h index 8ec0546c7e..e2bafec4a9 100644 --- a/include/gui/BufferQueueConsumer.h +++ b/include/gui/BufferQueueConsumer.h @@ -144,7 +144,7 @@ public: virtual status_t discardFreeBuffers() override; // dump our state in a String - virtual void dump(String8& result, const char* prefix) const; + virtual void dumpState(String8& result, const char* prefix) const; // Functions required for backwards compatibility. // These will be modified/renamed in IGraphicBufferConsumer and will be diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h index 1226feb59a..b1c730a587 100644 --- a/include/gui/BufferQueueCore.h +++ b/include/gui/BufferQueueCore.h @@ -86,7 +86,7 @@ public: private: // Dump our state in a string - void dump(String8& result, const char* prefix) const; + void dumpState(String8& result, const char* prefix) const; // getMinUndequeuedBufferCountLocked returns the minimum number of buffers // that must remain in a state other than DEQUEUED. The async parameter @@ -317,13 +317,13 @@ private: // Cached data about the shared buffer in shared buffer mode struct SharedBufferCache { - SharedBufferCache(Rect _crop, uint32_t _transform, int _scalingMode, - android_dataspace _dataspace) + SharedBufferCache(Rect _crop, uint32_t _transform, + uint32_t _scalingMode, android_dataspace _dataspace) : crop(_crop), transform(_transform), scalingMode(_scalingMode), dataspace(_dataspace) { - }; + } Rect crop; uint32_t transform; diff --git a/include/gui/BufferQueueProducer.h b/include/gui/BufferQueueProducer.h index 8f613ee17d..79e7af2117 100644 --- a/include/gui/BufferQueueProducer.h +++ b/include/gui/BufferQueueProducer.h @@ -22,7 +22,7 @@ namespace android { -class BufferSlot; +struct BufferSlot; class BufferQueueProducer : public BnGraphicBufferProducer, private IBinder::DeathRecipient { diff --git a/include/gui/ConsumerBase.h b/include/gui/ConsumerBase.h index 0490c3cc5b..9f8b638a3a 100644 --- a/include/gui/ConsumerBase.h +++ b/include/gui/ConsumerBase.h @@ -63,11 +63,11 @@ public: // log messages. void setName(const String8& name); - // dump writes the current state to a string. Child classes should add + // dumpState writes the current state to a string. Child classes should add // their state to the dump by overriding the dumpLocked method, which is // called by these methods after locking the mutex. - void dump(String8& result) const; - void dump(String8& result, const char* prefix) const; + void dumpState(String8& result) const; + void dumpState(String8& result, const char* prefix) const; // setFrameAvailableListener sets the listener object that will be notified // when a new frame becomes available. @@ -101,7 +101,7 @@ protected: // buffers from the given IGraphicBufferConsumer. // The controlledByApp flag indicates that this consumer is under the application's // control. - ConsumerBase(const sp<IGraphicBufferConsumer>& consumer, bool controlledByApp = false); + explicit ConsumerBase(const sp<IGraphicBufferConsumer>& consumer, bool controlledByApp = false); // onLastStrongRef gets called by RefBase just before the dtor of the most // derived class. It is used to clean up the buffers so that ConsumerBase diff --git a/include/gui/DisplayEventReceiver.h b/include/gui/DisplayEventReceiver.h index a4718b91c6..cb9b373392 100644 --- a/include/gui/DisplayEventReceiver.h +++ b/include/gui/DisplayEventReceiver.h @@ -35,13 +35,19 @@ namespace android { class BitTube; class IDisplayEventConnection; -// ---------------------------------------------------------------------------- +static inline constexpr uint32_t fourcc(char c1, char c2, char c3, char c4) { + return static_cast<uint32_t>(c1) << 24 | + static_cast<uint32_t>(c2) << 16 | + static_cast<uint32_t>(c3) << 8 | + static_cast<uint32_t>(c4); +} +// ---------------------------------------------------------------------------- class DisplayEventReceiver { public: enum { - DISPLAY_EVENT_VSYNC = 'vsyn', - DISPLAY_EVENT_HOTPLUG = 'plug' + DISPLAY_EVENT_VSYNC = fourcc('v', 's', 'y', 'n'), + DISPLAY_EVENT_HOTPLUG = fourcc('p', 'l', 'u', 'g'), }; struct Event { diff --git a/include/gui/IConsumerListener.h b/include/gui/IConsumerListener.h index 1efcf3cfb5..460a03d91a 100644 --- a/include/gui/IConsumerListener.h +++ b/include/gui/IConsumerListener.h @@ -41,7 +41,7 @@ class BufferItem; class ConsumerListener : public virtual RefBase { public: ConsumerListener() { } - virtual ~ConsumerListener() { } + virtual ~ConsumerListener(); // onFrameAvailable is called from queueBuffer each time an additional // frame becomes available for consumption. This means that frames that @@ -91,7 +91,7 @@ public: class IConsumerListener : public ConsumerListener, public IInterface { public: - DECLARE_META_INTERFACE(ConsumerListener); + DECLARE_META_INTERFACE(ConsumerListener) }; // ---------------------------------------------------------------------------- diff --git a/include/gui/IDisplayEventConnection.h b/include/gui/IDisplayEventConnection.h index 86247de62b..848368c7b6 100644 --- a/include/gui/IDisplayEventConnection.h +++ b/include/gui/IDisplayEventConnection.h @@ -34,7 +34,7 @@ class IDisplayEventConnection : public IInterface { public: - DECLARE_META_INTERFACE(DisplayEventConnection); + DECLARE_META_INTERFACE(DisplayEventConnection) /* * getDataChannel() returns a BitTube where to receive the events from diff --git a/include/gui/IGraphicBufferAlloc.h b/include/gui/IGraphicBufferAlloc.h index 600cf27c4c..acc2f30bf4 100644 --- a/include/gui/IGraphicBufferAlloc.h +++ b/include/gui/IGraphicBufferAlloc.h @@ -33,7 +33,7 @@ namespace android { class IGraphicBufferAlloc : public IInterface { public: - DECLARE_META_INTERFACE(GraphicBufferAlloc); + DECLARE_META_INTERFACE(GraphicBufferAlloc) /* Create a new GraphicBuffer for the client to use. */ diff --git a/include/gui/IGraphicBufferConsumer.h b/include/gui/IGraphicBufferConsumer.h index 3b10d78b58..dcddca46e8 100644 --- a/include/gui/IGraphicBufferConsumer.h +++ b/include/gui/IGraphicBufferConsumer.h @@ -278,10 +278,10 @@ public: virtual status_t discardFreeBuffers() = 0; // dump state into a string - virtual void dump(String8& result, const char* prefix) const = 0; + virtual void dumpState(String8& result, const char* prefix) const = 0; public: - DECLARE_META_INTERFACE(GraphicBufferConsumer); + DECLARE_META_INTERFACE(GraphicBufferConsumer) }; // ---------------------------------------------------------------------------- diff --git a/include/gui/IGraphicBufferProducer.h b/include/gui/IGraphicBufferProducer.h index bf427fe4b9..c2dba50361 100644 --- a/include/gui/IGraphicBufferProducer.h +++ b/include/gui/IGraphicBufferProducer.h @@ -56,7 +56,7 @@ class Surface; class IGraphicBufferProducer : public IInterface { public: - DECLARE_META_INTERFACE(GraphicBufferProducer); + DECLARE_META_INTERFACE(GraphicBufferProducer) enum { // A flag returned by dequeueBuffer when the client needs to call @@ -294,7 +294,7 @@ public: struct QueueBufferInput : public Flattenable<QueueBufferInput> { friend class Flattenable<QueueBufferInput>; - inline QueueBufferInput(const Parcel& parcel); + explicit inline QueueBufferInput(const Parcel& parcel); // timestamp - a monotonically increasing value in nanoseconds // isAutoTimestamp - if the timestamp was synthesized at queue time // dataSpace - description of the contents, interpretation depends on format @@ -305,12 +305,13 @@ public: // set this to Fence::NO_FENCE if the buffer is ready immediately // sticky - the sticky transform set in Surface (only used by the LEGACY // camera mode). - inline QueueBufferInput(int64_t timestamp, bool isAutoTimestamp, - android_dataspace dataSpace, const Rect& crop, int scalingMode, - uint32_t transform, const sp<Fence>& fence, uint32_t sticky = 0) - : timestamp(timestamp), isAutoTimestamp(isAutoTimestamp), - dataSpace(dataSpace), crop(crop), scalingMode(scalingMode), - transform(transform), stickyTransform(sticky), fence(fence), + inline QueueBufferInput(int64_t _timestamp, bool _isAutoTimestamp, + android_dataspace _dataSpace, const Rect& _crop, + int _scalingMode, uint32_t _transform, const sp<Fence>& _fence, + uint32_t _sticky = 0) + : timestamp(_timestamp), isAutoTimestamp(_isAutoTimestamp), + dataSpace(_dataSpace), crop(_crop), scalingMode(_scalingMode), + transform(_transform), stickyTransform(_sticky), fence(_fence), surfaceDamage() { } inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp, android_dataspace* outDataSpace, @@ -351,7 +352,7 @@ public: }; // QueueBufferOutput must be a POD structure - struct __attribute__ ((__packed__)) QueueBufferOutput { + struct QueueBufferOutput { inline QueueBufferOutput() { } // outWidth - filled with default width applied to the buffer // outHeight - filled with default height applied to the buffer diff --git a/include/gui/IProducerListener.h b/include/gui/IProducerListener.h index b7826c677f..e808bd3bc3 100644 --- a/include/gui/IProducerListener.h +++ b/include/gui/IProducerListener.h @@ -33,7 +33,7 @@ class ProducerListener : public virtual RefBase { public: ProducerListener() {} - virtual ~ProducerListener() {} + virtual ~ProducerListener(); // onBufferReleased is called from IGraphicBufferConsumer::releaseBuffer to // notify the producer that a new buffer is free and ready to be dequeued. @@ -61,6 +61,7 @@ public: class DummyProducerListener : public BnProducerListener { public: + virtual ~DummyProducerListener(); virtual void onBufferReleased() {} virtual bool needsReleaseNotify() { return false; } }; diff --git a/include/gui/ISensorEventConnection.h b/include/gui/ISensorEventConnection.h index f64c6b8604..857444b60b 100644 --- a/include/gui/ISensorEventConnection.h +++ b/include/gui/ISensorEventConnection.h @@ -33,7 +33,7 @@ class BitTube; class ISensorEventConnection : public IInterface { public: - DECLARE_META_INTERFACE(SensorEventConnection); + DECLARE_META_INTERFACE(SensorEventConnection) virtual sp<BitTube> getSensorChannel() const = 0; virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs, diff --git a/include/gui/ISensorServer.h b/include/gui/ISensorServer.h index 571acb5d39..737c430af4 100644 --- a/include/gui/ISensorServer.h +++ b/include/gui/ISensorServer.h @@ -35,7 +35,7 @@ class String8; class ISensorServer : public IInterface { public: - DECLARE_META_INTERFACE(SensorServer); + DECLARE_META_INTERFACE(SensorServer) virtual Vector<Sensor> getSensorList(const String16& opPackageName) = 0; virtual Vector<Sensor> getDynamicSensorList(const String16& opPackageName) = 0; diff --git a/include/gui/ISurfaceComposer.h b/include/gui/ISurfaceComposer.h index 74a4123bb6..555a0cc6ab 100644 --- a/include/gui/ISurfaceComposer.h +++ b/include/gui/ISurfaceComposer.h @@ -35,8 +35,8 @@ namespace android { // ---------------------------------------------------------------------------- -class ComposerState; -class DisplayState; +struct ComposerState; +struct DisplayState; struct DisplayInfo; struct DisplayStatInfo; class HdrCapabilities; @@ -50,7 +50,7 @@ class Rect; */ class ISurfaceComposer: public IInterface { public: - DECLARE_META_INTERFACE(SurfaceComposer); + DECLARE_META_INTERFACE(SurfaceComposer) // flags for setTransactionState() enum { diff --git a/include/gui/ISurfaceComposerClient.h b/include/gui/ISurfaceComposerClient.h index c27a741632..4a4efb631a 100644 --- a/include/gui/ISurfaceComposerClient.h +++ b/include/gui/ISurfaceComposerClient.h @@ -36,7 +36,7 @@ class IGraphicBufferProducer; class ISurfaceComposerClient : public IInterface { public: - DECLARE_META_INTERFACE(SurfaceComposerClient); + DECLARE_META_INTERFACE(SurfaceComposerClient) // flags for createSurface() enum { // (keep in sync with Surface.java) diff --git a/include/gui/OccupancyTracker.h b/include/gui/OccupancyTracker.h index 1d15e7f029..d4de8f2b14 100644 --- a/include/gui/OccupancyTracker.h +++ b/include/gui/OccupancyTracker.h @@ -45,12 +45,12 @@ public: occupancyAverage(0.0f), usedThirdBuffer(false) {} - Segment(nsecs_t totalTime, size_t numFrames, float occupancyAverage, - bool usedThirdBuffer) - : totalTime(totalTime), - numFrames(numFrames), - occupancyAverage(occupancyAverage), - usedThirdBuffer(usedThirdBuffer) {} + Segment(nsecs_t _totalTime, size_t _numFrames, float _occupancyAverage, + bool _usedThirdBuffer) + : totalTime(_totalTime), + numFrames(_numFrames), + occupancyAverage(_occupancyAverage), + usedThirdBuffer(_usedThirdBuffer) {} // Parcelable interface virtual status_t writeToParcel(Parcel* parcel) const override; diff --git a/include/gui/Sensor.h b/include/gui/Sensor.h index 094fd163bc..750683559d 100644 --- a/include/gui/Sensor.h +++ b/include/gui/Sensor.h @@ -61,6 +61,9 @@ public: uuid_t() : b{0} {} }; + Sensor(const Sensor&) = default; + Sensor& operator=(const Sensor&) = default; + Sensor(const char * name = ""); Sensor(struct sensor_t const* hwSensor, int halVersion = 0); Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersion = 0); diff --git a/include/gui/Surface.h b/include/gui/Surface.h index f4a22cb733..489d5ea7bf 100644 --- a/include/gui/Surface.h +++ b/include/gui/Surface.h @@ -66,7 +66,7 @@ public: * the controlledByApp flag indicates that this Surface (producer) is * controlled by the application. This flag is used at connect time. */ - Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false); + explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false); /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this * Surface was created with. Usually it's an error to use the diff --git a/include/gui/SurfaceComposerClient.h b/include/gui/SurfaceComposerClient.h index c4f88b60cc..f2932f2c08 100644 --- a/include/gui/SurfaceComposerClient.h +++ b/include/gui/SurfaceComposerClient.h @@ -38,7 +38,7 @@ namespace android { // --------------------------------------------------------------------------- -class DisplayInfo; +struct DisplayInfo; class Composer; class HdrCapabilities; class ISurfaceComposerClient; diff --git a/include/input/IInputFlinger.h b/include/input/IInputFlinger.h index 629310ff2f..11bb7215d6 100644 --- a/include/input/IInputFlinger.h +++ b/include/input/IInputFlinger.h @@ -30,7 +30,7 @@ namespace android { */ class IInputFlinger : public IInterface { public: - DECLARE_META_INTERFACE(InputFlinger); + DECLARE_META_INTERFACE(InputFlinger) }; diff --git a/include/input/Input.h b/include/input/Input.h index 55787e7c75..cfcafabebf 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -398,7 +398,7 @@ public: inline int32_t getButtonState() const { return mButtonState; } - inline int32_t setButtonState(int32_t buttonState) { mButtonState = buttonState; } + inline void setButtonState(int32_t buttonState) { mButtonState = buttonState; } inline int32_t getActionButton() const { return mActionButton; } diff --git a/include/input/InputEventLabels.h b/include/input/InputEventLabels.h index 0bd14ea3a1..20154eb10e 100644 --- a/include/input/InputEventLabels.h +++ b/include/input/InputEventLabels.h @@ -425,30 +425,30 @@ static const char* lookupLabelByValue(int value, const InputEventLabel* list) { return NULL; } -static int32_t getKeyCodeByLabel(const char* label) { +static inline int32_t getKeyCodeByLabel(const char* label) { return int32_t(lookupValueByLabel(label, KEYCODES)); } -static const char* getLabelByKeyCode(int32_t keyCode) { - if (keyCode >= 0 && keyCode < size(KEYCODES)) { +static inline const char* getLabelByKeyCode(int32_t keyCode) { + if (keyCode >= 0 && keyCode < static_cast<int32_t>(size(KEYCODES))) { return KEYCODES[keyCode].literal; } return NULL; } -static uint32_t getKeyFlagByLabel(const char* label) { +static inline uint32_t getKeyFlagByLabel(const char* label) { return uint32_t(lookupValueByLabel(label, FLAGS)); } -static int32_t getAxisByLabel(const char* label) { +static inline int32_t getAxisByLabel(const char* label) { return int32_t(lookupValueByLabel(label, AXES)); } -static const char* getAxisLabel(int32_t axisId) { +static inline const char* getAxisLabel(int32_t axisId) { return lookupLabelByValue(axisId, AXES); } -static int32_t getLedByLabel(const char* label) { +static inline int32_t getLedByLabel(const char* label) { return int32_t(lookupValueByLabel(label, LEDS)); } diff --git a/include/media/hardware/HardwareAPI.h b/include/media/hardware/HardwareAPI.h index 2c50ad6f15..cecf7152f4 100644 --- a/include/media/hardware/HardwareAPI.h +++ b/include/media/hardware/HardwareAPI.h @@ -270,7 +270,7 @@ struct DescribeColorFormatParams { // output: fill out the MediaImage fields MediaImage sMediaImage; - DescribeColorFormatParams(const DescribeColorFormat2Params&); // for internal use only + explicit DescribeColorFormatParams(const DescribeColorFormat2Params&); // for internal use only }; // A pointer to this struct is passed to OMX_GetParameter when the extension diff --git a/include/media/openmax/OMX_Core.h b/include/media/openmax/OMX_Core.h index 88dd585d74..bb974b3f88 100644 --- a/include/media/openmax/OMX_Core.h +++ b/include/media/openmax/OMX_Core.h @@ -738,7 +738,7 @@ typedef struct OMX_TUNNELSETUPTYPE pComponentVersion, \ pSpecVersion, \ pComponentUUID) \ - ((OMX_COMPONENTTYPE*)hComponent)->GetComponentVersion( \ + ((OMX_COMPONENTTYPE*)(hComponent))->GetComponentVersion(\ hComponent, \ pComponentName, \ pComponentVersion, \ @@ -804,7 +804,7 @@ typedef struct OMX_TUNNELSETUPTYPE Cmd, \ nParam, \ pCmdData) \ - ((OMX_COMPONENTTYPE*)hComponent)->SendCommand( \ + ((OMX_COMPONENTTYPE*)(hComponent))->SendCommand( \ hComponent, \ Cmd, \ nParam, \ @@ -843,8 +843,8 @@ typedef struct OMX_TUNNELSETUPTYPE #define OMX_GetParameter( \ hComponent, \ nParamIndex, \ - pComponentParameterStructure) \ - ((OMX_COMPONENTTYPE*)hComponent)->GetParameter( \ + pComponentParameterStructure) \ + ((OMX_COMPONENTTYPE*)(hComponent))->GetParameter( \ hComponent, \ nParamIndex, \ pComponentParameterStructure) /* Macro End */ @@ -882,8 +882,8 @@ typedef struct OMX_TUNNELSETUPTYPE #define OMX_SetParameter( \ hComponent, \ nParamIndex, \ - pComponentParameterStructure) \ - ((OMX_COMPONENTTYPE*)hComponent)->SetParameter( \ + pComponentParameterStructure) \ + ((OMX_COMPONENTTYPE*)(hComponent))->SetParameter( \ hComponent, \ nParamIndex, \ pComponentParameterStructure) /* Macro End */ @@ -918,8 +918,8 @@ typedef struct OMX_TUNNELSETUPTYPE #define OMX_GetConfig( \ hComponent, \ nConfigIndex, \ - pComponentConfigStructure) \ - ((OMX_COMPONENTTYPE*)hComponent)->GetConfig( \ + pComponentConfigStructure) \ + ((OMX_COMPONENTTYPE*)(hComponent))->GetConfig( \ hComponent, \ nConfigIndex, \ pComponentConfigStructure) /* Macro End */ @@ -954,8 +954,8 @@ typedef struct OMX_TUNNELSETUPTYPE #define OMX_SetConfig( \ hComponent, \ nConfigIndex, \ - pComponentConfigStructure) \ - ((OMX_COMPONENTTYPE*)hComponent)->SetConfig( \ + pComponentConfigStructure) \ + ((OMX_COMPONENTTYPE*)(hComponent))->SetConfig( \ hComponent, \ nConfigIndex, \ pComponentConfigStructure) /* Macro End */ @@ -989,7 +989,7 @@ typedef struct OMX_TUNNELSETUPTYPE hComponent, \ cParameterName, \ pIndexType) \ - ((OMX_COMPONENTTYPE*)hComponent)->GetExtensionIndex( \ + ((OMX_COMPONENTTYPE*)(hComponent))->GetExtensionIndex( \ hComponent, \ cParameterName, \ pIndexType) /* Macro End */ @@ -1015,7 +1015,7 @@ typedef struct OMX_TUNNELSETUPTYPE #define OMX_GetState( \ hComponent, \ pState) \ - ((OMX_COMPONENTTYPE*)hComponent)->GetState( \ + ((OMX_COMPONENTTYPE*)(hComponent))->GetState( \ hComponent, \ pState) /* Macro End */ @@ -1046,7 +1046,7 @@ typedef struct OMX_TUNNELSETUPTYPE pAppPrivate, \ nSizeBytes, \ pBuffer) \ - ((OMX_COMPONENTTYPE*)hComponent)->UseBuffer( \ + ((OMX_COMPONENTTYPE*)(hComponent))->UseBuffer( \ hComponent, \ ppBufferHdr, \ nPortIndex, \ @@ -1088,7 +1088,7 @@ typedef struct OMX_TUNNELSETUPTYPE nPortIndex, \ pAppPrivate, \ nSizeBytes) \ - ((OMX_COMPONENTTYPE*)hComponent)->AllocateBuffer( \ + ((OMX_COMPONENTTYPE*)(hComponent))->AllocateBuffer( \ hComponent, \ ppBuffer, \ nPortIndex, \ @@ -1122,7 +1122,7 @@ typedef struct OMX_TUNNELSETUPTYPE hComponent, \ nPortIndex, \ pBuffer) \ - ((OMX_COMPONENTTYPE*)hComponent)->FreeBuffer( \ + ((OMX_COMPONENTTYPE*)(hComponent))->FreeBuffer( \ hComponent, \ nPortIndex, \ pBuffer) /* Macro End */ @@ -1153,7 +1153,7 @@ typedef struct OMX_TUNNELSETUPTYPE #define OMX_EmptyThisBuffer( \ hComponent, \ pBuffer) \ - ((OMX_COMPONENTTYPE*)hComponent)->EmptyThisBuffer( \ + ((OMX_COMPONENTTYPE*)(hComponent))->EmptyThisBuffer( \ hComponent, \ pBuffer) /* Macro End */ @@ -1183,7 +1183,7 @@ typedef struct OMX_TUNNELSETUPTYPE #define OMX_FillThisBuffer( \ hComponent, \ pBuffer) \ - ((OMX_COMPONENTTYPE*)hComponent)->FillThisBuffer( \ + ((OMX_COMPONENTTYPE*)(hComponent))->FillThisBuffer( \ hComponent, \ pBuffer) /* Macro End */ @@ -1225,7 +1225,7 @@ typedef struct OMX_TUNNELSETUPTYPE nPortIndex, \ pAppPrivate, \ eglImage) \ - ((OMX_COMPONENTTYPE*)hComponent)->UseEGLImage( \ + ((OMX_COMPONENTTYPE*)(hComponent))->UseEGLImage( \ hComponent, \ ppBufferHdr, \ nPortIndex, \ diff --git a/include/powermanager/IPowerManager.h b/include/powermanager/IPowerManager.h index 461fad7515..32301897bc 100644 --- a/include/powermanager/IPowerManager.h +++ b/include/powermanager/IPowerManager.h @@ -50,7 +50,7 @@ public: CRASH = IBinder::FIRST_CALL_TRANSACTION + 16, }; - DECLARE_META_INTERFACE(PowerManager); + DECLARE_META_INTERFACE(PowerManager) // The parcels created by these methods must be kept in sync with the // corresponding methods from IPowerManager.aidl. diff --git a/include/private/binder/binder_module.h b/include/private/binder/binder_module.h index a8dd64f235..2f11622e70 100644 --- a/include/private/binder/binder_module.h +++ b/include/private/binder/binder_module.h @@ -24,7 +24,7 @@ namespace android { /* obtain structures and constants from the kernel header */ #include <sys/ioctl.h> -#include <linux/binder.h> +#include <linux/android/binder.h> #ifdef __cplusplus } // namespace android diff --git a/include/private/ui/RegionHelper.h b/include/private/ui/RegionHelper.h index 84eb10079b..c7c31607dc 100644 --- a/include/private/ui/RegionHelper.h +++ b/include/private/ui/RegionHelper.h @@ -53,20 +53,20 @@ public: TYPE dy; inline region(const region& rhs) : rects(rhs.rects), count(rhs.count), dx(rhs.dx), dy(rhs.dy) { } - inline region(RECT const* r, size_t c) - : rects(r), count(c), dx(), dy() { } - inline region(RECT const* r, size_t c, TYPE dx, TYPE dy) - : rects(r), count(c), dx(dx), dy(dy) { } + inline region(RECT const* _r, size_t _c) + : rects(_r), count(_c), dx(), dy() { } + inline region(RECT const* _r, size_t _c, TYPE _dx, TYPE _dy) + : rects(_r), count(_c), dx(_dx), dy(_dy) { } }; class region_rasterizer { friend class region_operator; virtual void operator()(const RECT& rect) = 0; public: - virtual ~region_rasterizer() { }; + virtual ~region_rasterizer() { } }; - inline region_operator(int op, const region& lhs, const region& rhs) + inline region_operator(uint32_t op, const region& lhs, const region& rhs) : op_mask(op), spanner(lhs, rhs) { } @@ -79,8 +79,8 @@ public: spannerInner.prepare(inside); do { TYPE left, right; - int inside = spannerInner.next(current.left, current.right); - if ((op_mask >> inside) & 1) { + int inner_inside = spannerInner.next(current.left, current.right); + if ((op_mask >> inner_inside) & 1) { if (current.left < current.right && current.top < current.bottom) { rasterizer(current); @@ -162,8 +162,8 @@ private: region rhs; public: - inline Spanner(const region& lhs, const region& rhs) - : lhs(lhs), rhs(rhs) + inline Spanner(const region& _lhs, const region& _rhs) + : lhs(_lhs), rhs(_rhs) { if (lhs.count) { SpannerBase::lhs_head = lhs.rects->top + lhs.dy; @@ -223,8 +223,8 @@ private: region rhs; public: - inline SpannerInner(const region& lhs, const region& rhs) - : lhs(lhs), rhs(rhs) + inline SpannerInner(const region& _lhs, const region& _rhs) + : lhs(_lhs), rhs(_rhs) { } diff --git a/include/ui/Fence.h b/include/ui/Fence.h index b431bd52aa..a4c1df72bc 100644 --- a/include/ui/Fence.h +++ b/include/ui/Fence.h @@ -53,7 +53,7 @@ public: // Construct a new Fence object to manage a given fence file descriptor. // When the new Fence object is destructed the file descriptor will be // closed. - Fence(int fenceFd); + explicit Fence(int fenceFd); // Check whether the Fence has an open fence file descriptor. Most Fence // methods treat an invalid file descriptor just like a valid fence that diff --git a/include/ui/FrameStats.h b/include/ui/FrameStats.h index 6bfe635c72..bc9d3ec1f1 100644 --- a/include/ui/FrameStats.h +++ b/include/ui/FrameStats.h @@ -25,7 +25,7 @@ namespace android { class FrameStats : public LightFlattenable<FrameStats> { public: - FrameStats() : refreshPeriodNano(0) {}; + FrameStats() : refreshPeriodNano(0) {} /* * Approximate refresh time, in nanoseconds. diff --git a/include/ui/Gralloc1On0Adapter.h b/include/ui/Gralloc1On0Adapter.h index 97c9a89d32..d523c4f7e7 100644 --- a/include/ui/Gralloc1On0Adapter.h +++ b/include/ui/Gralloc1On0Adapter.h @@ -81,7 +81,7 @@ private: uint32_t* outCount, int32_t* /*gralloc1_capability_t*/ outCapabilities) { getAdapter(device)->doGetCapabilities(outCount, outCapabilities); - }; + } // getFunction @@ -104,7 +104,7 @@ private: // Buffer descriptor lifecycle functions - class Descriptor; + struct Descriptor; gralloc1_error_t createDescriptor( gralloc1_buffer_descriptor_t* outDescriptor); @@ -124,10 +124,10 @@ private: // Buffer descriptor modification functions struct Descriptor : public std::enable_shared_from_this<Descriptor> { - Descriptor(Gralloc1On0Adapter* adapter, - gralloc1_buffer_descriptor_t id) - : adapter(adapter), - id(id), + Descriptor(Gralloc1On0Adapter* _adapter, + gralloc1_buffer_descriptor_t _id) + : adapter(_adapter), + id(_id), width(0), height(0), format(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED), @@ -416,10 +416,10 @@ private: if (!outData) { const auto producerCpuUsage = GRALLOC1_PRODUCER_USAGE_CPU_READ | GRALLOC1_PRODUCER_USAGE_CPU_WRITE; - if (producerUsage & producerCpuUsage != 0) { + if ((producerUsage & producerCpuUsage) != 0) { return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); } - if (consumerUsage & GRALLOC1_CONSUMER_USAGE_CPU_READ != 0) { + if ((consumerUsage & GRALLOC1_CONSUMER_USAGE_CPU_READ) != 0) { return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); } } diff --git a/include/ui/Point.h b/include/ui/Point.h index 1d7f64d307..d050ede02d 100644 --- a/include/ui/Point.h +++ b/include/ui/Point.h @@ -34,7 +34,7 @@ public: // Default constructor doesn't initialize the Point inline Point() { } - inline Point(int x, int y) : x(x), y(y) { + inline Point(int _x, int _y) : x(_x), y(_y) { } inline bool operator == (const Point& rhs) const { diff --git a/include/ui/Region.h b/include/ui/Region.h index 810f09860d..778845295f 100644 --- a/include/ui/Region.h +++ b/include/ui/Region.h @@ -147,21 +147,21 @@ private: class rasterizer; friend class rasterizer; - Region& operationSelf(const Rect& r, int op); - Region& operationSelf(const Region& r, int op); - Region& operationSelf(const Region& r, int dx, int dy, int op); - const Region operation(const Rect& rhs, int op) const; - const Region operation(const Region& rhs, int op) const; - const Region operation(const Region& rhs, int dx, int dy, int op) const; - - static void boolean_operation(int op, Region& dst, + Region& operationSelf(const Rect& r, uint32_t op); + Region& operationSelf(const Region& r, uint32_t op); + Region& operationSelf(const Region& r, int dx, int dy, uint32_t op); + const Region operation(const Rect& rhs, uint32_t op) const; + const Region operation(const Region& rhs, uint32_t op) const; + const Region operation(const Region& rhs, int dx, int dy, uint32_t op) const; + + static void boolean_operation(uint32_t op, Region& dst, const Region& lhs, const Region& rhs, int dx, int dy); - static void boolean_operation(int op, Region& dst, + static void boolean_operation(uint32_t op, Region& dst, const Region& lhs, const Rect& rhs, int dx, int dy); - static void boolean_operation(int op, Region& dst, + static void boolean_operation(uint32_t op, Region& dst, const Region& lhs, const Region& rhs); - static void boolean_operation(int op, Region& dst, + static void boolean_operation(uint32_t op, Region& dst, const Region& lhs, const Rect& rhs); static void translate(Region& reg, int dx, int dy); diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp new file mode 100644 index 0000000000..4780757f59 --- /dev/null +++ b/libs/binder/Android.bp @@ -0,0 +1,76 @@ +// Copyright (C) 2009 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. + +cc_library { + name: "libbinder", + + srcs: [ + "AppOpsManager.cpp", + "Binder.cpp", + "BpBinder.cpp", + "BufferedTextOutput.cpp", + "Debug.cpp", + "IAppOpsCallback.cpp", + "IAppOpsService.cpp", + "IBatteryStats.cpp", + "IInterface.cpp", + "IMediaResourceMonitor.cpp", + "IMemory.cpp", + "IPCThreadState.cpp", + "IPermissionController.cpp", + "IProcessInfoService.cpp", + "IResultReceiver.cpp", + "IServiceManager.cpp", + "MemoryBase.cpp", + "MemoryDealer.cpp", + "MemoryHeapBase.cpp", + "Parcel.cpp", + "PermissionCache.cpp", + "PersistableBundle.cpp", + "ProcessInfoService.cpp", + "ProcessState.cpp", + "Static.cpp", + "Status.cpp", + "TextOutput.cpp", + ], + + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + ], + product_variables: { + binder32bit: { + cflags: ["-DBINDER_IPC_32BIT=1"], + }, + }, + + shared_libs: [ + "libbase", + "liblog", + "libcutils", + "libutils", + ], + export_shared_lib_headers: [ + "libbase", + "libutils", + ], + + clang: true, + sanitize: { + misc_undefined: ["integer"], + }, +} + +subdirs = ["tests"] diff --git a/libs/binder/Android.mk b/libs/binder/Android.mk deleted file mode 100644 index 14be920d2e..0000000000 --- a/libs/binder/Android.mk +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (C) 2009 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. - -# we have the common sources, plus some device-specific stuff -sources := \ - AppOpsManager.cpp \ - Binder.cpp \ - BpBinder.cpp \ - BufferedTextOutput.cpp \ - Debug.cpp \ - IAppOpsCallback.cpp \ - IAppOpsService.cpp \ - IBatteryStats.cpp \ - IInterface.cpp \ - IMediaResourceMonitor.cpp \ - IMemory.cpp \ - IPCThreadState.cpp \ - IPermissionController.cpp \ - IProcessInfoService.cpp \ - IResultReceiver.cpp \ - IServiceManager.cpp \ - MemoryBase.cpp \ - MemoryDealer.cpp \ - MemoryHeapBase.cpp \ - Parcel.cpp \ - PermissionCache.cpp \ - PersistableBundle.cpp \ - ProcessInfoService.cpp \ - ProcessState.cpp \ - Static.cpp \ - Status.cpp \ - TextOutput.cpp \ - -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) -LOCAL_MODULE := libbinder -LOCAL_SHARED_LIBRARIES := liblog libcutils libutils - -LOCAL_CLANG := true -LOCAL_SANITIZE := integer -LOCAL_SRC_FILES := $(sources) -ifneq ($(TARGET_USES_64_BIT_BINDER),true) -ifneq ($(TARGET_IS_64_BIT),true) -LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1 -endif -endif -LOCAL_CFLAGS += -Werror -include $(BUILD_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := libbinder -LOCAL_STATIC_LIBRARIES += libutils -LOCAL_SRC_FILES := $(sources) -ifneq ($(TARGET_USES_64_BIT_BINDER),true) -ifneq ($(TARGET_IS_64_BIT),true) -LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1 -endif -endif -LOCAL_CFLAGS += -Werror -include $(BUILD_STATIC_LIBRARY) diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index 9a061a0ceb..f3b86ae311 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include <mutex> #include <binder/AppOpsManager.h> #include <binder/Binder.h> #include <binder/IServiceManager.h> @@ -22,6 +23,19 @@ namespace android { +namespace { + +#if defined(__BRILLO__) +// Because Brillo has no application model, security policy is managed +// statically (at build time) with SELinux controls. +// As a consequence, it also never runs the AppOpsManager service. +const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_ALLOWED; +#else +const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_IGNORED; +#endif // defined(__BRILLO__) + +} // namespace + static String16 _appops("appops"); static pthread_mutex_t gTokenMutex = PTHREAD_MUTEX_INITIALIZER; static sp<IBinder> gToken; @@ -39,10 +53,15 @@ AppOpsManager::AppOpsManager() { } +#if defined(__BRILLO__) +// There is no AppOpsService on Brillo +sp<IAppOpsService> AppOpsManager::getService() { return NULL; } +#else sp<IAppOpsService> AppOpsManager::getService() { + + std::lock_guard<Mutex> scoped_lock(mLock); int64_t startTime = 0; - mLock.lock(); sp<IAppOpsService> service = mService; while (service == NULL || !IInterface::asBinder(service)->isBinderAlive()) { sp<IBinder> binder = defaultServiceManager()->checkService(_appops); @@ -53,7 +72,8 @@ sp<IAppOpsService> AppOpsManager::getService() ALOGI("Waiting for app ops service"); } else if ((uptimeMillis()-startTime) > 10000) { ALOGW("Waiting too long for app ops service, giving up"); - return NULL; + service = NULL; + break; } sleep(1); } else { @@ -61,25 +81,30 @@ sp<IAppOpsService> AppOpsManager::getService() mService = service; } } - mLock.unlock(); return service; } +#endif // defined(__BRILLO__) int32_t AppOpsManager::checkOp(int32_t op, int32_t uid, const String16& callingPackage) { sp<IAppOpsService> service = getService(); - return service != NULL ? service->checkOperation(op, uid, callingPackage) : MODE_IGNORED; + return service != NULL + ? service->checkOperation(op, uid, callingPackage) + : APP_OPS_MANAGER_UNAVAILABLE_MODE; } int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) { sp<IAppOpsService> service = getService(); - return service != NULL ? service->noteOperation(op, uid, callingPackage) : MODE_IGNORED; + return service != NULL + ? service->noteOperation(op, uid, callingPackage) + : APP_OPS_MANAGER_UNAVAILABLE_MODE; } int32_t AppOpsManager::startOp(int32_t op, int32_t uid, const String16& callingPackage) { sp<IAppOpsService> service = getService(); - return service != NULL ? service->startOperation(getToken(service), op, uid, callingPackage) - : MODE_IGNORED; + return service != NULL + ? service->startOperation(getToken(service), op, uid, callingPackage) + : APP_OPS_MANAGER_UNAVAILABLE_MODE; } void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage) { diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp index c4d47caede..7ce2a318a9 100644 --- a/libs/binder/Binder.cpp +++ b/libs/binder/Binder.cpp @@ -237,6 +237,10 @@ status_t BBinder::onTransact( // XXX can't add virtuals until binaries are updated. //return shellCommand(in, out, err, args, resultReceiver); + (void)in; + (void)out; + (void)err; + if (resultReceiver != NULL) { resultReceiver->send(INVALID_OPERATION); } diff --git a/libs/binder/BufferedTextOutput.cpp b/libs/binder/BufferedTextOutput.cpp index 1339a67e62..a2443c081f 100644 --- a/libs/binder/BufferedTextOutput.cpp +++ b/libs/binder/BufferedTextOutput.cpp @@ -34,7 +34,7 @@ namespace android { struct BufferedTextOutput::BufferState : public RefBase { - BufferState(int32_t _seq) + explicit BufferState(int32_t _seq) : seq(_seq) , buffer(NULL) , bufferPos(0) diff --git a/libs/binder/IAppOpsCallback.cpp b/libs/binder/IAppOpsCallback.cpp index 2aaf56679e..f9ec593f77 100644 --- a/libs/binder/IAppOpsCallback.cpp +++ b/libs/binder/IAppOpsCallback.cpp @@ -31,7 +31,7 @@ namespace android { class BpAppOpsCallback : public BpInterface<IAppOpsCallback> { public: - BpAppOpsCallback(const sp<IBinder>& impl) + explicit BpAppOpsCallback(const sp<IBinder>& impl) : BpInterface<IAppOpsCallback>(impl) { } diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp index 9558376dbf..638ae5c8ac 100644 --- a/libs/binder/IAppOpsService.cpp +++ b/libs/binder/IAppOpsService.cpp @@ -31,7 +31,7 @@ namespace android { class BpAppOpsService : public BpInterface<IAppOpsService> { public: - BpAppOpsService(const sp<IBinder>& impl) + explicit BpAppOpsService(const sp<IBinder>& impl) : BpInterface<IAppOpsService>(impl) { } diff --git a/libs/binder/IBatteryStats.cpp b/libs/binder/IBatteryStats.cpp index e32c628679..ad1e69faeb 100644 --- a/libs/binder/IBatteryStats.cpp +++ b/libs/binder/IBatteryStats.cpp @@ -29,7 +29,7 @@ namespace android { class BpBatteryStats : public BpInterface<IBatteryStats> { public: - BpBatteryStats(const sp<IBinder>& impl) + explicit BpBatteryStats(const sp<IBinder>& impl) : BpInterface<IBatteryStats>(impl) { } diff --git a/libs/binder/IMemory.cpp b/libs/binder/IMemory.cpp index 5f345cf7b7..790fa8c931 100644 --- a/libs/binder/IMemory.cpp +++ b/libs/binder/IMemory.cpp @@ -16,6 +16,7 @@ #define LOG_TAG "IMemory" +#include <atomic> #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -29,7 +30,6 @@ #include <cutils/log.h> #include <utils/KeyedVector.h> #include <utils/threads.h> -#include <utils/Atomic.h> #include <binder/Parcel.h> #include <utils/CallStack.h> @@ -56,12 +56,15 @@ private: struct heap_info_t { sp<IMemoryHeap> heap; int32_t count; + // Note that this cannot be meaningfully copied. }; void free_heap(const wp<IBinder>& binder); - Mutex mHeapCacheLock; + Mutex mHeapCacheLock; // Protects entire vector below. KeyedVector< wp<IBinder>, heap_info_t > mHeapCache; + // We do not use the copy-on-write capabilities of KeyedVector. + // TODO: Reimplemement based on standard C++ container? }; static sp<HeapCache> gHeapCache = new HeapCache(); @@ -75,7 +78,7 @@ enum { class BpMemoryHeap : public BpInterface<IMemoryHeap> { public: - BpMemoryHeap(const sp<IBinder>& impl); + explicit BpMemoryHeap(const sp<IBinder>& impl); virtual ~BpMemoryHeap(); virtual int getHeapID() const; @@ -105,7 +108,7 @@ private: void assertMapped() const; void assertReallyMapped() const; - mutable volatile int32_t mHeapId; + mutable std::atomic<int32_t> mHeapId; mutable void* mBase; mutable size_t mSize; mutable uint32_t mFlags; @@ -123,7 +126,7 @@ enum { class BpMemory : public BpInterface<IMemory> { public: - BpMemory(const sp<IBinder>& impl); + explicit BpMemory(const sp<IBinder>& impl); virtual ~BpMemory(); virtual sp<IMemoryHeap> getMemory(ssize_t* offset=0, size_t* size=0) const; @@ -248,8 +251,9 @@ BpMemoryHeap::BpMemoryHeap(const sp<IBinder>& impl) } BpMemoryHeap::~BpMemoryHeap() { - if (mHeapId != -1) { - close(mHeapId); + int32_t heapId = mHeapId.load(memory_order_relaxed); + if (heapId != -1) { + close(heapId); if (mRealHeap) { // by construction we're the last one if (mBase != MAP_FAILED) { @@ -257,7 +261,7 @@ BpMemoryHeap::~BpMemoryHeap() { if (VERBOSE) { ALOGD("UNMAPPING binder=%p, heap=%p, size=%zu, fd=%d", - binder.get(), this, mSize, mHeapId); + binder.get(), this, mSize, heapId); CallStack stack(LOG_TAG); } @@ -273,17 +277,21 @@ BpMemoryHeap::~BpMemoryHeap() { void BpMemoryHeap::assertMapped() const { - if (mHeapId == -1) { + int32_t heapId = mHeapId.load(memory_order_acquire); + if (heapId == -1) { sp<IBinder> binder(IInterface::asBinder(const_cast<BpMemoryHeap*>(this))); sp<BpMemoryHeap> heap(static_cast<BpMemoryHeap*>(find_heap(binder).get())); heap->assertReallyMapped(); if (heap->mBase != MAP_FAILED) { Mutex::Autolock _l(mLock); - if (mHeapId == -1) { + if (mHeapId.load(memory_order_relaxed) == -1) { mBase = heap->mBase; mSize = heap->mSize; mOffset = heap->mOffset; - android_atomic_write( dup( heap->mHeapId ), &mHeapId ); + int fd = dup(heap->mHeapId.load(memory_order_relaxed)); + ALOGE_IF(fd==-1, "cannot dup fd=%d", + heap->mHeapId.load(memory_order_relaxed)); + mHeapId.store(fd, memory_order_release); } } else { // something went wrong @@ -294,7 +302,8 @@ void BpMemoryHeap::assertMapped() const void BpMemoryHeap::assertReallyMapped() const { - if (mHeapId == -1) { + int32_t heapId = mHeapId.load(memory_order_acquire); + if (heapId == -1) { // remote call without mLock held, worse case scenario, we end up // calling transact() from multiple threads, but that's not a problem, @@ -313,7 +322,7 @@ void BpMemoryHeap::assertReallyMapped() const parcel_fd, size, err, strerror(-err)); Mutex::Autolock _l(mLock); - if (mHeapId == -1) { + if (mHeapId.load(memory_order_relaxed) == -1) { int fd = dup( parcel_fd ); ALOGE_IF(fd==-1, "cannot dup fd=%d, size=%zd, err=%d (%s)", parcel_fd, size, err, strerror(errno)); @@ -322,7 +331,6 @@ void BpMemoryHeap::assertReallyMapped() const if (!(flags & READ_ONLY)) { access |= PROT_WRITE; } - mRealHeap = true; mBase = mmap(0, size, access, MAP_SHARED, fd, offset); if (mBase == MAP_FAILED) { @@ -333,7 +341,7 @@ void BpMemoryHeap::assertReallyMapped() const mSize = size; mFlags = flags; mOffset = offset; - android_atomic_write(fd, &mHeapId); + mHeapId.store(fd, memory_order_release); } } } @@ -341,7 +349,8 @@ void BpMemoryHeap::assertReallyMapped() const int BpMemoryHeap::getHeapID() const { assertMapped(); - return mHeapId; + // We either stored mHeapId ourselves, or loaded it with acquire semantics. + return mHeapId.load(memory_order_relaxed); } void* BpMemoryHeap::getBase() const { @@ -418,9 +427,10 @@ sp<IMemoryHeap> HeapCache::find_heap(const sp<IBinder>& binder) "found binder=%p, heap=%p, size=%zu, fd=%d, count=%d", binder.get(), info.heap.get(), static_cast<BpMemoryHeap*>(info.heap.get())->mSize, - static_cast<BpMemoryHeap*>(info.heap.get())->mHeapId, + static_cast<BpMemoryHeap*>(info.heap.get()) + ->mHeapId.load(memory_order_relaxed), info.count); - android_atomic_inc(&info.count); + ++info.count; return info.heap; } else { heap_info_t info; @@ -445,13 +455,13 @@ void HeapCache::free_heap(const wp<IBinder>& binder) ssize_t i = mHeapCache.indexOfKey(binder); if (i>=0) { heap_info_t& info(mHeapCache.editValueAt(i)); - int32_t c = android_atomic_dec(&info.count); - if (c == 1) { + if (--info.count == 0) { ALOGD_IF(VERBOSE, "removing binder=%p, heap=%p, size=%zu, fd=%d, count=%d", binder.unsafe_get(), info.heap.get(), static_cast<BpMemoryHeap*>(info.heap.get())->mSize, - static_cast<BpMemoryHeap*>(info.heap.get())->mHeapId, + static_cast<BpMemoryHeap*>(info.heap.get()) + ->mHeapId.load(memory_order_relaxed), info.count); rel = mHeapCache.valueAt(i).heap; mHeapCache.removeItemsAt(i); @@ -482,7 +492,7 @@ void HeapCache::dump_heaps() ALOGD("hey=%p, heap=%p, count=%d, (fd=%d, base=%p, size=%zu)", mHeapCache.keyAt(i).unsafe_get(), info.heap.get(), info.count, - h->mHeapId, h->mBase, h->mSize); + h->mHeapId.load(memory_order_relaxed), h->mBase, h->mSize); } } diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index d90798f51e..9b5f0d7fcf 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -330,6 +330,7 @@ void IPCThreadState::shutdown() delete st; pthread_setspecific(gTLS, NULL); } + pthread_key_delete(gTLS); gHaveTLS = false; } } diff --git a/libs/binder/IPermissionController.cpp b/libs/binder/IPermissionController.cpp index 6bba9968bc..674bddf218 100644 --- a/libs/binder/IPermissionController.cpp +++ b/libs/binder/IPermissionController.cpp @@ -31,7 +31,7 @@ namespace android { class BpPermissionController : public BpInterface<IPermissionController> { public: - BpPermissionController(const sp<IBinder>& impl) + explicit BpPermissionController(const sp<IBinder>& impl) : BpInterface<IPermissionController>(impl) { } diff --git a/libs/binder/IProcessInfoService.cpp b/libs/binder/IProcessInfoService.cpp index 76508b88bf..96e1a8c239 100644 --- a/libs/binder/IProcessInfoService.cpp +++ b/libs/binder/IProcessInfoService.cpp @@ -25,7 +25,7 @@ namespace android { class BpProcessInfoService : public BpInterface<IProcessInfoService> { public: - BpProcessInfoService(const sp<IBinder>& impl) + explicit BpProcessInfoService(const sp<IBinder>& impl) : BpInterface<IProcessInfoService>(impl) {} virtual status_t getProcessStatesFromPids(size_t length, /*in*/ int32_t* pids, diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index 61f24d6805..2062b3b509 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -67,11 +67,6 @@ bool checkCallingPermission(const String16& permission, int32_t* outPid, int32_t bool checkPermission(const String16& permission, pid_t pid, uid_t uid) { -#ifdef __BRILLO__ - // Brillo doesn't currently run ActivityManager or support framework permissions. - return true; -#endif - sp<IPermissionController> pc; gDefaultServiceManagerLock.lock(); pc = gPermissionController; @@ -131,7 +126,7 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid) class BpServiceManager : public BpInterface<IServiceManager> { public: - BpServiceManager(const sp<IBinder>& impl) + explicit BpServiceManager(const sp<IBinder>& impl) : BpInterface<IServiceManager>(impl) { } diff --git a/libs/binder/MemoryDealer.cpp b/libs/binder/MemoryDealer.cpp index 51eac1104b..2a15773aa3 100644 --- a/libs/binder/MemoryDealer.cpp +++ b/libs/binder/MemoryDealer.cpp @@ -126,7 +126,7 @@ class SimpleBestFitAllocator PAGE_ALIGNED = 0x00000001 }; public: - SimpleBestFitAllocator(size_t size); + explicit SimpleBestFitAllocator(size_t size); ~SimpleBestFitAllocator(); size_t allocate(size_t size, uint32_t flags = 0); diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index e88ae29518..061cb08fde 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -100,32 +100,6 @@ enum { BLOB_ASHMEM_MUTABLE = 2, }; -static dev_t ashmem_rdev() -{ - static dev_t __ashmem_rdev; - static pthread_mutex_t __ashmem_rdev_lock = PTHREAD_MUTEX_INITIALIZER; - - pthread_mutex_lock(&__ashmem_rdev_lock); - - dev_t rdev = __ashmem_rdev; - if (!rdev) { - int fd = TEMP_FAILURE_RETRY(open("/dev/ashmem", O_RDONLY)); - if (fd >= 0) { - struct stat st; - - int ret = TEMP_FAILURE_RETRY(fstat(fd, &st)); - close(fd); - if ((ret >= 0) && S_ISCHR(st.st_mode)) { - rdev = __ashmem_rdev = st.st_rdev; - } - } - } - - pthread_mutex_unlock(&__ashmem_rdev_lock); - - return rdev; -} - void acquire_object(const sp<ProcessState>& proc, const flat_binder_object& obj, const void* who, size_t* outAshmemSize) { @@ -154,15 +128,11 @@ void acquire_object(const sp<ProcessState>& proc, return; } case BINDER_TYPE_FD: { - if ((obj.cookie != 0) && (outAshmemSize != NULL)) { - struct stat st; - int ret = fstat(obj.handle, &st); - if (!ret && S_ISCHR(st.st_mode) && (st.st_rdev == ashmem_rdev())) { - // If we own an ashmem fd, keep track of how much memory it refers to. - int size = ashmem_get_size_region(obj.handle); - if (size > 0) { - *outAshmemSize += size; - } + if ((obj.cookie != 0) && (outAshmemSize != NULL) && ashmem_valid(obj.handle)) { + // If we own an ashmem fd, keep track of how much memory it refers to. + int size = ashmem_get_size_region(obj.handle); + if (size > 0) { + *outAshmemSize += size; } } return; @@ -207,14 +177,10 @@ static void release_object(const sp<ProcessState>& proc, } case BINDER_TYPE_FD: { if (obj.cookie != 0) { // owned - if (outAshmemSize != NULL) { - struct stat st; - int ret = fstat(obj.handle, &st); - if (!ret && S_ISCHR(st.st_mode) && (st.st_rdev == ashmem_rdev())) { - int size = ashmem_get_size_region(obj.handle); - if (size > 0) { - *outAshmemSize -= size; - } + if ((outAshmemSize != NULL) && ashmem_valid(obj.handle)) { + int size = ashmem_get_size_region(obj.handle); + if (size > 0) { + *outAshmemSize -= size; } } @@ -784,7 +750,7 @@ status_t Parcel::writeUtf8AsUtf16(const std::string& str) { const uint8_t* strData = (uint8_t*)str.data(); const size_t strLen= str.length(); const ssize_t utf16Len = utf8_to_utf16_length(strData, strLen); - if (utf16Len < 0 || utf16Len> std::numeric_limits<int32_t>::max()) { + if (utf16Len < 0 || utf16Len > std::numeric_limits<int32_t>::max()) { return BAD_VALUE; } @@ -799,7 +765,7 @@ status_t Parcel::writeUtf8AsUtf16(const std::string& str) { return NO_MEMORY; } - utf8_to_utf16(strData, strLen, (char16_t*)dst); + utf8_to_utf16(strData, strLen, (char16_t*)dst, (size_t) utf16Len + 1); return NO_ERROR; } @@ -1112,7 +1078,7 @@ status_t Parcel::writeStrongBinderVector(const std::unique_ptr<std::vector<sp<IB } status_t Parcel::readStrongBinderVector(std::unique_ptr<std::vector<sp<IBinder>>>* val) const { - return readNullableTypedVector(val, &Parcel::readStrongBinder); + return readNullableTypedVector(val, &Parcel::readNullableStrongBinder); } status_t Parcel::readStrongBinderVector(std::vector<sp<IBinder>>* val) const { @@ -1187,15 +1153,15 @@ status_t Parcel::writeDupFileDescriptor(int fd) return err; } -status_t Parcel::writeUniqueFileDescriptor(const ScopedFd& fd) { +status_t Parcel::writeUniqueFileDescriptor(const base::unique_fd& fd) { return writeDupFileDescriptor(fd.get()); } -status_t Parcel::writeUniqueFileDescriptorVector(const std::vector<ScopedFd>& val) { +status_t Parcel::writeUniqueFileDescriptorVector(const std::vector<base::unique_fd>& val) { return writeTypedVector(val, &Parcel::writeUniqueFileDescriptor); } -status_t Parcel::writeUniqueFileDescriptorVector(const std::unique_ptr<std::vector<ScopedFd>>& val) { +status_t Parcel::writeUniqueFileDescriptorVector(const std::unique_ptr<std::vector<base::unique_fd>>& val) { return writeNullableTypedVector(val, &Parcel::writeUniqueFileDescriptor); } @@ -1842,13 +1808,37 @@ const char* Parcel::readCString() const String8 Parcel::readString8() const { - int32_t size = readInt32(); - // watch for potential int overflow adding 1 for trailing NUL - if (size > 0 && size < INT32_MAX) { - const char* str = (const char*)readInplace(size+1); - if (str) return String8(str, size); + String8 retString; + status_t status = readString8(&retString); + if (status != OK) { + // We don't care about errors here, so just return an empty string. + return String8(); } - return String8(); + return retString; +} + +status_t Parcel::readString8(String8* pArg) const +{ + int32_t size; + status_t status = readInt32(&size); + if (status != OK) { + return status; + } + // watch for potential int overflow from size+1 + if (size < 0 || size >= INT32_MAX) { + return BAD_VALUE; + } + // |writeString8| writes nothing for empty string. + if (size == 0) { + *pArg = String8(); + return OK; + } + const char* str = (const char*)readInplace(size + 1); + if (str == NULL) { + return BAD_VALUE; + } + pArg->setTo(str, size); + return OK; } String16 Parcel::readString16() const @@ -1913,13 +1903,25 @@ const char16_t* Parcel::readString16Inplace(size_t* outLen) const status_t Parcel::readStrongBinder(sp<IBinder>* val) const { + status_t status = readNullableStrongBinder(val); + if (status == OK && !val->get()) { + status = UNEXPECTED_NULL; + } + return status; +} + +status_t Parcel::readNullableStrongBinder(sp<IBinder>* val) const +{ return unflatten_binder(ProcessState::self(), *this, val); } sp<IBinder> Parcel::readStrongBinder() const { sp<IBinder> val; - readStrongBinder(&val); + // Note that a lot of code in Android reads binders by hand with this + // method, and that code has historically been ok with getting nullptr + // back (while ignoring error codes). + readNullableStrongBinder(&val); return val; } @@ -1994,7 +1996,7 @@ int Parcel::readFileDescriptor() const return BAD_TYPE; } -status_t Parcel::readUniqueFileDescriptor(ScopedFd* val) const +status_t Parcel::readUniqueFileDescriptor(base::unique_fd* val) const { int got = readFileDescriptor(); @@ -2012,11 +2014,11 @@ status_t Parcel::readUniqueFileDescriptor(ScopedFd* val) const } -status_t Parcel::readUniqueFileDescriptorVector(std::unique_ptr<std::vector<ScopedFd>>* val) const { +status_t Parcel::readUniqueFileDescriptorVector(std::unique_ptr<std::vector<base::unique_fd>>* val) const { return readNullableTypedVector(val, &Parcel::readUniqueFileDescriptor); } -status_t Parcel::readUniqueFileDescriptorVector(std::vector<ScopedFd>* val) const { +status_t Parcel::readUniqueFileDescriptorVector(std::vector<base::unique_fd>* val) const { return readTypedVector(val, &Parcel::readUniqueFileDescriptor); } diff --git a/libs/binder/PersistableBundle.cpp b/libs/binder/PersistableBundle.cpp index aef791c37b..e7078baa82 100644 --- a/libs/binder/PersistableBundle.cpp +++ b/libs/binder/PersistableBundle.cpp @@ -32,6 +32,9 @@ using android::Parcel; using android::sp; using android::status_t; using android::UNEXPECTED_NULL; +using std::map; +using std::set; +using std::vector; enum { // Keep in sync with BUNDLE_MAGIC in frameworks/base/core/java/android/os/BaseBundle.java. @@ -55,12 +58,22 @@ enum { namespace { template <typename T> -bool getValue(const android::String16& key, T* out, const std::map<android::String16, T>& map) { +bool getValue(const android::String16& key, T* out, const map<android::String16, T>& map) { const auto& it = map.find(key); if (it == map.end()) return false; *out = it->second; return true; } + +template <typename T> +set<android::String16> getKeys(const map<android::String16, T>& map) { + if (map.empty()) return set<android::String16>(); + set<android::String16> keys; + for (const auto& key_value_pair : map) { + keys.emplace(key_value_pair.first); + } + return keys; +} } // namespace namespace android { @@ -78,7 +91,7 @@ namespace os { #define RETURN_IF_ENTRY_ERASED(map, key) \ { \ - size_t num_erased = map.erase(key); \ + size_t num_erased = (map).erase(key); \ if (num_erased) { \ ALOGE("Failed at %s:%d (%s)", __FILE__, __LINE__, __func__); \ return num_erased; \ @@ -188,27 +201,27 @@ void PersistableBundle::putString(const String16& key, const String16& value) { mStringMap[key] = value; } -void PersistableBundle::putBooleanVector(const String16& key, const std::vector<bool>& value) { +void PersistableBundle::putBooleanVector(const String16& key, const vector<bool>& value) { erase(key); mBoolVectorMap[key] = value; } -void PersistableBundle::putIntVector(const String16& key, const std::vector<int32_t>& value) { +void PersistableBundle::putIntVector(const String16& key, const vector<int32_t>& value) { erase(key); mIntVectorMap[key] = value; } -void PersistableBundle::putLongVector(const String16& key, const std::vector<int64_t>& value) { +void PersistableBundle::putLongVector(const String16& key, const vector<int64_t>& value) { erase(key); mLongVectorMap[key] = value; } -void PersistableBundle::putDoubleVector(const String16& key, const std::vector<double>& value) { +void PersistableBundle::putDoubleVector(const String16& key, const vector<double>& value) { erase(key); mDoubleVectorMap[key] = value; } -void PersistableBundle::putStringVector(const String16& key, const std::vector<String16>& value) { +void PersistableBundle::putStringVector(const String16& key, const vector<String16>& value) { erase(key); mStringVectorMap[key] = value; } @@ -238,23 +251,23 @@ bool PersistableBundle::getString(const String16& key, String16* out) const { return getValue(key, out, mStringMap); } -bool PersistableBundle::getBooleanVector(const String16& key, std::vector<bool>* out) const { +bool PersistableBundle::getBooleanVector(const String16& key, vector<bool>* out) const { return getValue(key, out, mBoolVectorMap); } -bool PersistableBundle::getIntVector(const String16& key, std::vector<int32_t>* out) const { +bool PersistableBundle::getIntVector(const String16& key, vector<int32_t>* out) const { return getValue(key, out, mIntVectorMap); } -bool PersistableBundle::getLongVector(const String16& key, std::vector<int64_t>* out) const { +bool PersistableBundle::getLongVector(const String16& key, vector<int64_t>* out) const { return getValue(key, out, mLongVectorMap); } -bool PersistableBundle::getDoubleVector(const String16& key, std::vector<double>* out) const { +bool PersistableBundle::getDoubleVector(const String16& key, vector<double>* out) const { return getValue(key, out, mDoubleVectorMap); } -bool PersistableBundle::getStringVector(const String16& key, std::vector<String16>* out) const { +bool PersistableBundle::getStringVector(const String16& key, vector<String16>* out) const { return getValue(key, out, mStringVectorMap); } @@ -262,6 +275,50 @@ bool PersistableBundle::getPersistableBundle(const String16& key, PersistableBun return getValue(key, out, mPersistableBundleMap); } +set<String16> PersistableBundle::getBooleanKeys() const { + return getKeys(mBoolMap); +} + +set<String16> PersistableBundle::getIntKeys() const { + return getKeys(mIntMap); +} + +set<String16> PersistableBundle::getLongKeys() const { + return getKeys(mLongMap); +} + +set<String16> PersistableBundle::getDoubleKeys() const { + return getKeys(mDoubleMap); +} + +set<String16> PersistableBundle::getStringKeys() const { + return getKeys(mStringMap); +} + +set<String16> PersistableBundle::getBooleanVectorKeys() const { + return getKeys(mBoolVectorMap); +} + +set<String16> PersistableBundle::getIntVectorKeys() const { + return getKeys(mIntVectorMap); +} + +set<String16> PersistableBundle::getLongVectorKeys() const { + return getKeys(mLongVectorMap); +} + +set<String16> PersistableBundle::getDoubleVectorKeys() const { + return getKeys(mDoubleVectorMap); +} + +set<String16> PersistableBundle::getStringVectorKeys() const { + return getKeys(mStringVectorMap); +} + +set<String16> PersistableBundle::getPersistableBundleKeys() const { + return getKeys(mPersistableBundleMap); +} + status_t PersistableBundle::writeToParcelInner(Parcel* parcel) const { /* * To keep this implementation in sync with writeArrayMapInternal() in @@ -363,7 +420,6 @@ status_t PersistableBundle::readFromParcelInner(const Parcel* parcel, size_t len RETURN_IF_FAILED(parcel->readInt32(&num_entries)); for (; num_entries > 0; --num_entries) { - size_t start_pos = parcel->dataPosition(); String16 key; int32_t value_type; RETURN_IF_FAILED(parcel->readString16(&key)); diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index f13f49fe93..d42bb82415 100644 --- a/libs/binder/ProcessState.cpp +++ b/libs/binder/ProcessState.cpp @@ -16,8 +16,6 @@ #define LOG_TAG "ProcessState" -#include <cutils/process_name.h> - #include <binder/ProcessState.h> #include <utils/Atomic.h> @@ -52,7 +50,7 @@ namespace android { class PoolThread : public Thread { public: - PoolThread(bool isMain) + explicit PoolThread(bool isMain) : mIsMain(isMain) { } @@ -366,6 +364,13 @@ ProcessState::ProcessState() ProcessState::~ProcessState() { + if (mDriverFD >= 0) { + if (mVMStart != MAP_FAILED) { + munmap(mVMStart, BINDER_VM_SIZE); + } + close(mDriverFD); + } + mDriverFD = -1; } }; // namespace android diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp index cd9509f707..f0613d1631 100644 --- a/libs/binder/Static.cpp +++ b/libs/binder/Static.cpp @@ -48,7 +48,7 @@ protected: class FdTextOutput : public BufferedTextOutput { public: - FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { } + explicit FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { } virtual ~FdTextOutput() { }; protected: diff --git a/libs/binder/Status.cpp b/libs/binder/Status.cpp index d3520d62e9..8466863865 100644 --- a/libs/binder/Status.cpp +++ b/libs/binder/Status.cpp @@ -32,6 +32,11 @@ Status Status::fromExceptionCode(int32_t exceptionCode, return Status(exceptionCode, OK, message); } +Status Status::fromExceptionCode(int32_t exceptionCode, + const char* message) { + return fromExceptionCode(exceptionCode, String8(message)); +} + Status Status::fromServiceSpecificError(int32_t serviceSpecificErrorCode) { return Status(EX_SERVICE_SPECIFIC, serviceSpecificErrorCode); } @@ -41,6 +46,11 @@ Status Status::fromServiceSpecificError(int32_t serviceSpecificErrorCode, return Status(EX_SERVICE_SPECIFIC, serviceSpecificErrorCode, message); } +Status Status::fromServiceSpecificError(int32_t serviceSpecificErrorCode, + const char* message) { + return fromServiceSpecificError(serviceSpecificErrorCode, String8(message)); +} + Status Status::fromStatusT(status_t status) { Status ret; ret.setFromStatusT(status); @@ -158,5 +168,10 @@ String8 Status::toString8() const { return ret; } +std::stringstream& operator<< (std::stringstream& stream, const Status& s) { + stream << s.toString8().string(); + return stream; +} + } // namespace binder } // namespace android diff --git a/libs/binder/tests/Android.bp b/libs/binder/tests/Android.bp new file mode 100644 index 0000000000..e354b11f6d --- /dev/null +++ b/libs/binder/tests/Android.bp @@ -0,0 +1,54 @@ +// +// Copyright (C) 2014 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. +// + +cc_test { + product_variables: { + binder32bit: { + cflags: ["-DBINDER_IPC_32BIT=1"], + }, + }, + + name: "binderDriverInterfaceTest", + srcs: ["binderDriverInterfaceTest.cpp"], +} + +cc_test { + name: "binderLibTest", + srcs: ["binderLibTest.cpp"], + shared_libs: [ + "libbinder", + "libutils", + ], +} + +cc_test { + name: "binderThroughputTest", + srcs: ["binderThroughputTest.cpp"], + shared_libs: [ + "libbinder", + "libutils", + ], + clang: true, + cflags: [ + "-g", + "-Wall", + "-Werror", + "-std=c++11", + "-Wno-missing-field-initializers", + "-Wno-sign-compare", + "-O3", + ], +} diff --git a/libs/binder/tests/Android.mk b/libs/binder/tests/Android.mk deleted file mode 100644 index a40523d4b3..0000000000 --- a/libs/binder/tests/Android.mk +++ /dev/null @@ -1,42 +0,0 @@ -# -# Copyright (C) 2014 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. -# - -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) -ifneq ($(TARGET_USES_64_BIT_BINDER),true) -ifneq ($(TARGET_IS_64_BIT),true) -LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1 -endif -endif - -LOCAL_MODULE := binderDriverInterfaceTest -LOCAL_SRC_FILES := binderDriverInterfaceTest.cpp -include $(BUILD_NATIVE_TEST) - -include $(CLEAR_VARS) -LOCAL_MODULE := binderLibTest -LOCAL_SRC_FILES := binderLibTest.cpp -LOCAL_SHARED_LIBRARIES := libbinder libutils -include $(BUILD_NATIVE_TEST) - -include $(CLEAR_VARS) -LOCAL_MODULE := binderThroughputTest -LOCAL_SRC_FILES := binderThroughputTest.cpp -LOCAL_SHARED_LIBRARIES := libbinder libutils -LOCAL_CLANG := true -LOCAL_CFLAGS += -g -Wall -Werror -std=c++11 -Wno-missing-field-initializers -Wno-sign-compare -O3 -include $(BUILD_NATIVE_TEST) diff --git a/libs/binder/tests/binderDriverInterfaceTest.cpp b/libs/binder/tests/binderDriverInterfaceTest.cpp index 0277550258..e02844e4ec 100644 --- a/libs/binder/tests/binderDriverInterfaceTest.cpp +++ b/libs/binder/tests/binderDriverInterfaceTest.cpp @@ -20,7 +20,7 @@ #include <stdlib.h> #include <gtest/gtest.h> -#include <linux/binder.h> +#include <linux/android/binder.h> #include <binder/IBinder.h> #include <sys/mman.h> #include <poll.h> diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp index 3df3acf9db..17479ca77e 100644 --- a/libs/binder/tests/binderLibTest.cpp +++ b/libs/binder/tests/binderLibTest.cpp @@ -252,14 +252,10 @@ class BinderLibTestEvent int ret; pthread_mutex_lock(&m_waitMutex); if (!m_eventTriggered) { -#if defined(HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE) - pthread_cond_timeout_np(&m_waitCond, &m_waitMutex, timeout_s * 1000); -#else struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += timeout_s; pthread_cond_timedwait(&m_waitCond, &m_waitMutex, &ts); -#endif } ret = m_eventTriggered ? NO_ERROR : TIMED_OUT; pthread_mutex_unlock(&m_waitMutex); @@ -739,14 +735,10 @@ class BinderLibTestService : public BBinder } if (ret > 0) { if (m_serverStartRequested) { -#if defined(HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE) - ret = pthread_cond_timeout_np(&m_serverWaitCond, &m_serverWaitMutex, 5000); -#else struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += 5; ret = pthread_cond_timedwait(&m_serverWaitCond, &m_serverWaitMutex, &ts); -#endif } if (m_serverStartRequested) { m_serverStartRequested = false; diff --git a/libs/diskusage/Android.bp b/libs/diskusage/Android.bp new file mode 100644 index 0000000000..156ddff2c6 --- /dev/null +++ b/libs/diskusage/Android.bp @@ -0,0 +1,18 @@ +// Copyright (C) 2010 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. + +cc_library_static { + name: "libdiskusage", + srcs: ["dirsize.c"], +} diff --git a/libs/gui/Android.mk b/libs/gui/Android.mk index 46feb1cc36..71b5ccae46 100644 --- a/libs/gui/Android.mk +++ b/libs/gui/Android.mk @@ -36,6 +36,9 @@ LOCAL_CPPFLAGS += -Wno-gnu-zero-variadic-macro-arguments # Don't warn about struct padding LOCAL_CPPFLAGS += -Wno-padded +# android/sensors.h uses nested anonymous unions and anonymous structs +LOCAL_CPPFLAGS += -Wno-nested-anon-types -Wno-gnu-anonymous-struct + LOCAL_CPPFLAGS += -DDEBUG_ONLY_CODE=$(if $(filter userdebug eng,$(TARGET_BUILD_VARIANT)),1,0) LOCAL_SRC_FILES := \ @@ -84,6 +87,7 @@ LOCAL_SHARED_LIBRARIES := \ libutils \ liblog +LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libbinder LOCAL_MODULE := libgui @@ -94,6 +98,10 @@ ifeq ($(TARGET_BOARD_PLATFORM), tegra3) LOCAL_CFLAGS += -DDONT_USE_FENCE_SYNC endif +ifeq ($(TARGET_BOARD_HAS_NO_SURFACE_FLINGER), true) + LOCAL_CFLAGS += -DHAVE_NO_SURFACE_FLINGER +endif + include $(BUILD_SHARED_LIBRARY) ifeq (,$(ONE_SHOT_MAKEFILE)) diff --git a/libs/gui/BufferItem.cpp b/libs/gui/BufferItem.cpp index 5e3924a7ee..1357a4aa1a 100644 --- a/libs/gui/BufferItem.cpp +++ b/libs/gui/BufferItem.cpp @@ -23,6 +23,21 @@ namespace android { +template<typename T> +static inline constexpr uint32_t low32(const T n) { + return static_cast<uint32_t>(static_cast<uint64_t>(n)); +} + +template<typename T> +static inline constexpr uint32_t high32(const T n) { + return static_cast<uint32_t>(static_cast<uint64_t>(n)>>32); +} + +template<typename T> +static inline constexpr T to64(const uint32_t lo, const uint32_t hi) { + return static_cast<T>(static_cast<uint64_t>(hi)<<32 | lo); +} + BufferItem::BufferItem() : mGraphicBuffer(NULL), mFence(NULL), @@ -56,12 +71,12 @@ size_t BufferItem::getPodSize() const { addAligned(size, mCrop); addAligned(size, mTransform); addAligned(size, mScalingMode); - addAligned(size, mTimestampLo); - addAligned(size, mTimestampHi); + addAligned(size, low32(mTimestamp)); + addAligned(size, high32(mTimestamp)); addAligned(size, mIsAutoTimestamp); addAligned(size, mDataSpace); - addAligned(size, mFrameNumberLo); - addAligned(size, mFrameNumberHi); + addAligned(size, low32(mFrameNumber)); + addAligned(size, high32(mFrameNumber)); addAligned(size, mSlot); addAligned(size, mIsDroppable); addAligned(size, mAcquireCalled); @@ -141,12 +156,12 @@ status_t BufferItem::flatten( writeAligned(buffer, size, mCrop); writeAligned(buffer, size, mTransform); writeAligned(buffer, size, mScalingMode); - writeAligned(buffer, size, mTimestampLo); - writeAligned(buffer, size, mTimestampHi); + writeAligned(buffer, size, low32(mTimestamp)); + writeAligned(buffer, size, high32(mTimestamp)); writeAligned(buffer, size, mIsAutoTimestamp); writeAligned(buffer, size, mDataSpace); - writeAligned(buffer, size, mFrameNumberLo); - writeAligned(buffer, size, mFrameNumberHi); + writeAligned(buffer, size, low32(mFrameNumber)); + writeAligned(buffer, size, high32(mFrameNumber)); writeAligned(buffer, size, mSlot); writeAligned(buffer, size, mIsDroppable); writeAligned(buffer, size, mAcquireCalled); @@ -194,15 +209,20 @@ status_t BufferItem::unflatten( return NO_MEMORY; } + uint32_t timestampLo = 0, timestampHi = 0; + uint32_t frameNumberLo = 0, frameNumberHi = 0; + readAligned(buffer, size, mCrop); readAligned(buffer, size, mTransform); readAligned(buffer, size, mScalingMode); - readAligned(buffer, size, mTimestampLo); - readAligned(buffer, size, mTimestampHi); + readAligned(buffer, size, timestampLo); + readAligned(buffer, size, timestampHi); + mTimestamp = to64<int64_t>(timestampLo, timestampHi); readAligned(buffer, size, mIsAutoTimestamp); readAligned(buffer, size, mDataSpace); - readAligned(buffer, size, mFrameNumberLo); - readAligned(buffer, size, mFrameNumberHi); + readAligned(buffer, size, frameNumberLo); + readAligned(buffer, size, frameNumberHi); + mFrameNumber = to64<uint64_t>(frameNumberLo, frameNumberHi); readAligned(buffer, size, mSlot); readAligned(buffer, size, mIsDroppable); readAligned(buffer, size, mAcquireCalled); diff --git a/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp index ca2a374e16..7fbf312727 100644 --- a/libs/gui/BufferQueueConsumer.cpp +++ b/libs/gui/BufferQueueConsumer.cpp @@ -259,7 +259,8 @@ status_t BufferQueueConsumer::acquireBuffer(BufferItem* outBuffer, // decrease. mCore->mDequeueCondition.broadcast(); - ATRACE_INT(mCore->mConsumerName.string(), mCore->mQueue.size()); + ATRACE_INT(mCore->mConsumerName.string(), + static_cast<int32_t>(mCore->mQueue.size())); mCore->mOccupancyTracker.registerOccupancyChange(mCore->mQueue.size()); VALIDATE_CONSISTENCY(); @@ -731,7 +732,7 @@ status_t BufferQueueConsumer::discardFreeBuffers() { return NO_ERROR; } -void BufferQueueConsumer::dump(String8& result, const char* prefix) const { +void BufferQueueConsumer::dumpState(String8& result, const char* prefix) const { const IPCThreadState* ipc = IPCThreadState::self(); const pid_t pid = ipc->getCallingPid(); const uid_t uid = ipc->getCallingUid(); @@ -740,9 +741,10 @@ void BufferQueueConsumer::dump(String8& result, const char* prefix) const { "android.permission.DUMP"), pid, uid)) { result.appendFormat("Permission Denial: can't dump BufferQueueConsumer " "from pid=%d, uid=%d\n", pid, uid); - android_errorWriteWithInfoLog(0x534e4554, "27046057", uid, NULL, 0); + android_errorWriteWithInfoLog(0x534e4554, "27046057", + static_cast<int32_t>(uid), NULL, 0); } else { - mCore->dump(result, prefix); + mCore->dumpState(result, prefix); } } diff --git a/libs/gui/BufferQueueCore.cpp b/libs/gui/BufferQueueCore.cpp index fd85c43b6d..d74d32c06d 100644 --- a/libs/gui/BufferQueueCore.cpp +++ b/libs/gui/BufferQueueCore.cpp @@ -28,8 +28,11 @@ #include <inttypes.h> +#include <cutils/properties.h> + #include <gui/BufferItem.h> #include <gui/BufferQueueCore.h> +#include <gui/GraphicBufferAlloc.h> #include <gui/IConsumerListener.h> #include <gui/IGraphicBufferAlloc.h> #include <gui/IProducerListener.h> @@ -93,8 +96,24 @@ BufferQueueCore::BufferQueueCore(const sp<IGraphicBufferAlloc>& allocator) : mUniqueId(getUniqueId()) { if (allocator == NULL) { - sp<ISurfaceComposer> composer(ComposerService::getComposerService()); - mAllocator = composer->createGraphicBufferAlloc(); + +#ifdef HAVE_NO_SURFACE_FLINGER + // Without a SurfaceFlinger, allocate in-process. This only makes + // sense in systems with static SELinux configurations and no + // applications (since applications need dynamic SELinux policy). + mAllocator = new GraphicBufferAlloc(); +#else + // Run time check for headless, where we also allocate in-process. + char value[PROPERTY_VALUE_MAX]; + property_get("config.headless", value, "0"); + if (atoi(value) == 1) { + mAllocator = new GraphicBufferAlloc(); + } else { + sp<ISurfaceComposer> composer(ComposerService::getComposerService()); + mAllocator = composer->createGraphicBufferAlloc(); + } +#endif // HAVE_NO_SURFACE_FLINGER + if (mAllocator == NULL) { BQ_LOGE("createGraphicBufferAlloc failed"); } @@ -112,7 +131,7 @@ BufferQueueCore::BufferQueueCore(const sp<IGraphicBufferAlloc>& allocator) : BufferQueueCore::~BufferQueueCore() {} -void BufferQueueCore::dump(String8& result, const char* prefix) const { +void BufferQueueCore::dumpState(String8& result, const char* prefix) const { Mutex::Autolock lock(mMutex); String8 fifo; diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index 7020214238..f8f38725b5 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -905,7 +905,8 @@ status_t BufferQueueProducer::queueBuffer(int slot, static_cast<uint32_t>(mCore->mQueue.size()), mCore->mFrameCounter + 1); - ATRACE_INT(mCore->mConsumerName.string(), mCore->mQueue.size()); + ATRACE_INT(mCore->mConsumerName.string(), + static_cast<int32_t>(mCore->mQueue.size())); mCore->mOccupancyTracker.registerOccupancyChange(mCore->mQueue.size()); // Take a ticket for the callback functions diff --git a/libs/gui/ConsumerBase.cpp b/libs/gui/ConsumerBase.cpp index a1bdf4a4a1..805a10d1b6 100644 --- a/libs/gui/ConsumerBase.cpp +++ b/libs/gui/ConsumerBase.cpp @@ -254,11 +254,11 @@ status_t ConsumerBase::discardFreeBuffers() { return mConsumer->discardFreeBuffers(); } -void ConsumerBase::dump(String8& result) const { - dump(result, ""); +void ConsumerBase::dumpState(String8& result) const { + dumpState(result, ""); } -void ConsumerBase::dump(String8& result, const char* prefix) const { +void ConsumerBase::dumpState(String8& result, const char* prefix) const { Mutex::Autolock _l(mMutex); dumpLocked(result, prefix); } @@ -267,7 +267,7 @@ void ConsumerBase::dumpLocked(String8& result, const char* prefix) const { result.appendFormat("%smAbandoned=%d\n", prefix, int(mAbandoned)); if (!mAbandoned) { - mConsumer->dump(result, prefix); + mConsumer->dumpState(result, prefix); } } diff --git a/libs/gui/IConsumerListener.cpp b/libs/gui/IConsumerListener.cpp index 9a06011ce0..ff7b83a7d6 100644 --- a/libs/gui/IConsumerListener.cpp +++ b/libs/gui/IConsumerListener.cpp @@ -37,7 +37,7 @@ enum { class BpConsumerListener : public BpInterface<IConsumerListener> { public: - BpConsumerListener(const sp<IBinder>& impl) + explicit BpConsumerListener(const sp<IBinder>& impl) : BpInterface<IConsumerListener>(impl) { } @@ -153,6 +153,7 @@ status_t BnConsumerListener::onTransact( return BBinder::onTransact(code, data, reply, flags); } +ConsumerListener::~ConsumerListener() = default; // --------------------------------------------------------------------------- }; // namespace android diff --git a/libs/gui/IDisplayEventConnection.cpp b/libs/gui/IDisplayEventConnection.cpp index 9890f44ef7..b1d3b00dbb 100644 --- a/libs/gui/IDisplayEventConnection.cpp +++ b/libs/gui/IDisplayEventConnection.cpp @@ -39,7 +39,7 @@ enum { class BpDisplayEventConnection : public BpInterface<IDisplayEventConnection> { public: - BpDisplayEventConnection(const sp<IBinder>& impl) + explicit BpDisplayEventConnection(const sp<IBinder>& impl) : BpInterface<IDisplayEventConnection>(impl) { } diff --git a/libs/gui/IGraphicBufferAlloc.cpp b/libs/gui/IGraphicBufferAlloc.cpp index 7b3b7c1dc5..2fb380ccd1 100644 --- a/libs/gui/IGraphicBufferAlloc.cpp +++ b/libs/gui/IGraphicBufferAlloc.cpp @@ -37,7 +37,7 @@ enum { class BpGraphicBufferAlloc : public BpInterface<IGraphicBufferAlloc> { public: - BpGraphicBufferAlloc(const sp<IBinder>& impl) + explicit BpGraphicBufferAlloc(const sp<IBinder>& impl) : BpInterface<IGraphicBufferAlloc>(impl) { } @@ -96,7 +96,7 @@ status_t BnGraphicBufferAlloc::onTransact( class BufferReference : public BBinder { sp<GraphicBuffer> mBuffer; public: - BufferReference(const sp<GraphicBuffer>& buffer) : mBuffer(buffer) {} + explicit BufferReference(const sp<GraphicBuffer>& buffer) : mBuffer(buffer) {} }; diff --git a/libs/gui/IGraphicBufferConsumer.cpp b/libs/gui/IGraphicBufferConsumer.cpp index c8eff00e3f..240146455e 100644 --- a/libs/gui/IGraphicBufferConsumer.cpp +++ b/libs/gui/IGraphicBufferConsumer.cpp @@ -60,7 +60,7 @@ enum { class BpGraphicBufferConsumer : public BpInterface<IGraphicBufferConsumer> { public: - BpGraphicBufferConsumer(const sp<IBinder>& impl) + explicit BpGraphicBufferConsumer(const sp<IBinder>& impl) : BpInterface<IGraphicBufferConsumer>(impl) { } @@ -302,7 +302,7 @@ public: return result; } - virtual void dump(String8& result, const char* prefix) const { + virtual void dumpState(String8& result, const char* prefix) const { Parcel data, reply; data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); data.writeString8(result); @@ -480,7 +480,7 @@ status_t BnGraphicBufferConsumer::onTransact( CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); String8 result = data.readString8(); String8 prefix = data.readString8(); - static_cast<IGraphicBufferConsumer*>(this)->dump(result, prefix); + static_cast<IGraphicBufferConsumer*>(this)->dumpState(result, prefix); reply->writeString8(result); return NO_ERROR; } diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp index f4ba3bf15f..846c205c00 100644 --- a/libs/gui/IGraphicBufferProducer.cpp +++ b/libs/gui/IGraphicBufferProducer.cpp @@ -61,7 +61,7 @@ enum { class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer> { public: - BpGraphicBufferProducer(const sp<IBinder>& impl) + explicit BpGraphicBufferProducer(const sp<IBinder>& impl) : BpInterface<IGraphicBufferProducer>(impl) { } diff --git a/libs/gui/IProducerListener.cpp b/libs/gui/IProducerListener.cpp index da54ce1c2b..62abfa81c4 100644 --- a/libs/gui/IProducerListener.cpp +++ b/libs/gui/IProducerListener.cpp @@ -28,7 +28,7 @@ enum { class BpProducerListener : public BpInterface<IProducerListener> { public: - BpProducerListener(const sp<IBinder>& impl) + explicit BpProducerListener(const sp<IBinder>& impl) : BpInterface<IProducerListener>(impl) {} virtual ~BpProducerListener(); @@ -78,6 +78,10 @@ status_t BnProducerListener::onTransact(uint32_t code, const Parcel& data, return BBinder::onTransact(code, data, reply, flags); } +ProducerListener::~ProducerListener() = default; + +DummyProducerListener::~DummyProducerListener() = default; + bool BnProducerListener::needsReleaseNotify() { return true; } diff --git a/libs/gui/ISensorEventConnection.cpp b/libs/gui/ISensorEventConnection.cpp index dc7a35cef9..59ecee7501 100644 --- a/libs/gui/ISensorEventConnection.cpp +++ b/libs/gui/ISensorEventConnection.cpp @@ -40,7 +40,7 @@ enum { class BpSensorEventConnection : public BpInterface<ISensorEventConnection> { public: - BpSensorEventConnection(const sp<IBinder>& impl) + explicit BpSensorEventConnection(const sp<IBinder>& impl) : BpInterface<ISensorEventConnection>(impl) { } diff --git a/libs/gui/ISensorServer.cpp b/libs/gui/ISensorServer.cpp index 3a4c7e4edc..07c507a082 100644 --- a/libs/gui/ISensorServer.cpp +++ b/libs/gui/ISensorServer.cpp @@ -42,7 +42,7 @@ enum { class BpSensorServer : public BpInterface<ISensorServer> { public: - BpSensorServer(const sp<IBinder>& impl) + explicit BpSensorServer(const sp<IBinder>& impl) : BpInterface<ISensorServer>(impl) { } diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index f0b0ada270..0a8e6a555e 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -49,7 +49,7 @@ class IDisplayEventConnection; class BpSurfaceComposer : public BpInterface<ISurfaceComposer> { public: - BpSurfaceComposer(const sp<IBinder>& impl) + explicit BpSurfaceComposer(const sp<IBinder>& impl) : BpInterface<ISurfaceComposer>(impl) { } diff --git a/libs/gui/ISurfaceComposerClient.cpp b/libs/gui/ISurfaceComposerClient.cpp index dd5b169dba..47cb0473e8 100644 --- a/libs/gui/ISurfaceComposerClient.cpp +++ b/libs/gui/ISurfaceComposerClient.cpp @@ -48,7 +48,7 @@ enum { class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient> { public: - BpSurfaceComposerClient(const sp<IBinder>& impl) + explicit BpSurfaceComposerClient(const sp<IBinder>& impl) : BpInterface<ISurfaceComposerClient>(impl) { } diff --git a/libs/gui/SensorManager.cpp b/libs/gui/SensorManager.cpp index 225bfa885f..5338034fd6 100644 --- a/libs/gui/SensorManager.cpp +++ b/libs/gui/SensorManager.cpp @@ -139,7 +139,7 @@ status_t SensorManager::assertStateLocked() { mSensorManager.sensorManagerDied(); } public: - DeathObserver(SensorManager& mgr) : mSensorManager(mgr) { } + explicit DeathObserver(SensorManager& mgr) : mSensorManager(mgr) { } }; LOG_ALWAYS_FATAL_IF(mSensorServer.get() == NULL, "getService(SensorService) NULL"); diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 08382908ba..8e6ab1c73b 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -408,7 +408,7 @@ int Surface::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { timestamp = systemTime(SYSTEM_TIME_MONOTONIC); isAutoTimestamp = true; ALOGV("Surface::queueBuffer making up timestamp: %.2f ms", - timestamp / 1000000.f); + timestamp / 1000000.0); } else { timestamp = mTimestamp; } diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index b78de2ea59..43506e9191 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -69,7 +69,7 @@ void ComposerService::connectLocked() { mComposerService.composerServiceDied(); } public: - DeathObserver(ComposerService& mgr) : mComposerService(mgr) { } + explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { } }; mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this)); diff --git a/libs/gui/tests/Android.mk b/libs/gui/tests/Android.mk index 6ad9986220..efae7f63d4 100644 --- a/libs/gui/tests/Android.mk +++ b/libs/gui/tests/Android.mk @@ -16,6 +16,7 @@ LOCAL_SRC_FILES := \ GLTest.cpp \ IGraphicBufferProducer_test.cpp \ MultiTextureConsumer_test.cpp \ + Sensor_test.cpp \ SRGB_test.cpp \ StreamSplitter_test.cpp \ SurfaceTextureClient_test.cpp \ @@ -28,6 +29,7 @@ LOCAL_SRC_FILES := \ TextureRenderer.cpp \ LOCAL_SHARED_LIBRARIES := \ + liblog \ libEGL \ libGLESv1_CM \ libGLESv2 \ diff --git a/libs/gui/tests/BufferQueue_test.cpp b/libs/gui/tests/BufferQueue_test.cpp index 8a9eeeec21..65df7dc991 100644 --- a/libs/gui/tests/BufferQueue_test.cpp +++ b/libs/gui/tests/BufferQueue_test.cpp @@ -1044,7 +1044,7 @@ TEST_F(BufferQueueTest, TestDiscardFreeBuffers) { // Check no free buffers in dump String8 dumpString; - mConsumer->dump(dumpString, nullptr); + mConsumer->dumpState(dumpString, nullptr); // Parse the dump to ensure that all buffer slots that are FREE also // have a null GraphicBuffer diff --git a/libs/gui/tests/CpuConsumer_test.cpp b/libs/gui/tests/CpuConsumer_test.cpp index 289cc74039..9c2e838b09 100644 --- a/libs/gui/tests/CpuConsumer_test.cpp +++ b/libs/gui/tests/CpuConsumer_test.cpp @@ -160,7 +160,7 @@ protected: }; #define ASSERT_NO_ERROR(err, msg) \ - ASSERT_EQ(NO_ERROR, err) << msg << strerror(-err) + ASSERT_EQ(NO_ERROR, err) << (msg) << strerror(-(err)) void checkPixel(const CpuConsumer::LockedBuffer &buf, uint32_t x, uint32_t y, uint32_t r, uint32_t g=0, uint32_t b=0) { diff --git a/libs/gui/tests/Sensor_test.cpp b/libs/gui/tests/Sensor_test.cpp new file mode 100644 index 0000000000..fbf282d1cf --- /dev/null +++ b/libs/gui/tests/Sensor_test.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2012 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 "Sensor_test" + +#include <gui/Sensor.h> +#include <hardware/sensors.h> +#include <utils/Errors.h> + +#include <gtest/gtest.h> + +namespace android { + +// Returns true if the two sensors have the same attributes. Does not compare +// UUID since that should not be transmitted via flatten/unflatten. +static bool sensorsMatch(const Sensor& a, const Sensor& b) { + return a.getName() == b.getName () && + a.getVendor() == b.getVendor () && + a.getHandle() == b.getHandle () && + a.getType() == b.getType () && + a.getMinValue() == b.getMinValue () && + a.getMaxValue() == b.getMaxValue () && + a.getResolution() == b.getResolution () && + a.getPowerUsage() == b.getPowerUsage () && + a.getMinDelay() == b.getMinDelay () && + a.getMinDelayNs() == b.getMinDelayNs () && + a.getVersion() == b.getVersion () && + a.getFifoReservedEventCount() == b.getFifoReservedEventCount () && + a.getFifoMaxEventCount() == b.getFifoMaxEventCount () && + a.getStringType() == b.getStringType () && + a.getRequiredPermission() == b.getRequiredPermission () && + a.isRequiredPermissionRuntime() == b.isRequiredPermissionRuntime () && + a.getRequiredAppOp() == b.getRequiredAppOp () && + a.getMaxDelay() == b.getMaxDelay () && + a.getFlags() == b.getFlags () && + a.isWakeUpSensor() == b.isWakeUpSensor () && + a.isDynamicSensor() == b.isDynamicSensor () && + a.hasAdditionalInfo() == b.hasAdditionalInfo () && + a.getReportingMode() == b.getReportingMode(); +} + +// Creates and returns a sensor_t struct with some default values filled in. +static sensor_t getTestSensorT() { + sensor_t hwSensor = {}; + hwSensor.name = "Test Sensor"; + hwSensor.vendor = "Test Vendor"; + hwSensor.version = 1; + hwSensor.handle = 2; + hwSensor.type = SENSOR_TYPE_ACCELEROMETER; + hwSensor.maxRange = 10.f; + hwSensor.resolution = 1.f; + hwSensor.power = 5.f; + hwSensor.minDelay = 1000; + hwSensor.fifoReservedEventCount = 50; + hwSensor.fifoMaxEventCount = 100; + hwSensor.stringType = SENSOR_STRING_TYPE_ACCELEROMETER; + hwSensor.requiredPermission = ""; + hwSensor.maxDelay = 5000; + hwSensor.flags = SENSOR_FLAG_CONTINUOUS_MODE; + return hwSensor; +} + +TEST(SensorTest, FlattenAndUnflatten) { + sensor_t hwSensor = getTestSensorT(); + Sensor sensor1(&hwSensor, SENSORS_DEVICE_API_VERSION_1_4); + Sensor sensor2; + + std::vector<uint8_t> buffer(sensor1.getFlattenedSize()); + ASSERT_EQ(OK, sensor1.flatten(buffer.data(), buffer.size())); + ASSERT_EQ(OK, sensor2.unflatten(buffer.data(), buffer.size())); + + EXPECT_TRUE(sensorsMatch(sensor1, sensor2)); +} + +} // namespace android diff --git a/libs/gui/tests/SurfaceTextureClient_test.cpp b/libs/gui/tests/SurfaceTextureClient_test.cpp index a1578f671e..b10d4ebde7 100644 --- a/libs/gui/tests/SurfaceTextureClient_test.cpp +++ b/libs/gui/tests/SurfaceTextureClient_test.cpp @@ -535,7 +535,7 @@ TEST_F(SurfaceTextureClientTest, DISABLED_SurfaceTextureSyncModeWaitRetire) { return false; } public: - MyThread(const sp<GLConsumer>& mST) + explicit MyThread(const sp<GLConsumer>& mST) : mST(mST), mBufferRetired(false) { ctx = eglGetCurrentContext(); sur = eglGetCurrentSurface(EGL_DRAW); diff --git a/libs/gui/tests/SurfaceTextureGL_test.cpp b/libs/gui/tests/SurfaceTextureGL_test.cpp index 5311c5957e..308bd7d69c 100644 --- a/libs/gui/tests/SurfaceTextureGL_test.cpp +++ b/libs/gui/tests/SurfaceTextureGL_test.cpp @@ -437,7 +437,7 @@ TEST_F(SurfaceTextureGLTest, DisconnectStressTest) { class ProducerThread : public Thread { public: - ProducerThread(const sp<ANativeWindow>& anw): + explicit ProducerThread(const sp<ANativeWindow>& anw): mANW(anw) { } @@ -620,7 +620,7 @@ TEST_F(SurfaceTextureGLTest, CroppedScalingMode) { TEST_F(SurfaceTextureGLTest, AbandonUnblocksDequeueBuffer) { class ProducerThread : public Thread { public: - ProducerThread(const sp<ANativeWindow>& anw): + explicit ProducerThread(const sp<ANativeWindow>& anw): mANW(anw), mDequeueError(NO_ERROR) { } diff --git a/libs/input/Android.bp b/libs/input/Android.bp new file mode 100644 index 0000000000..bd28af14fc --- /dev/null +++ b/libs/input/Android.bp @@ -0,0 +1,62 @@ +// Copyright (C) 2013 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. + +// libinput is partially built for the host (used by build time keymap validation tool) + +cc_library { + name: "libinput", + host_supported: true, + + srcs: [ + "Input.cpp", + "InputDevice.cpp", + "Keyboard.cpp", + "KeyCharacterMap.cpp", + "KeyLayoutMap.cpp", + "VirtualKeyMap.cpp", + ], + + clang: true, + sanitize: { + misc_undefined: ["integer"], + }, + + shared_libs: [ + "liblog", + "libcutils", + ], + + target: { + android: { + srcs: [ + "IInputFlinger.cpp", + "InputTransport.cpp", + "VelocityControl.cpp", + "VelocityTracker.cpp", + ], + + shared_libs: [ + "libutils", + "libbinder", + ], + }, + host: { + shared: { + enabled: false, + }, + }, + }, +} + +subdirs = ["tests"] diff --git a/libs/input/Android.mk b/libs/input/Android.mk deleted file mode 100644 index 746de66d62..0000000000 --- a/libs/input/Android.mk +++ /dev/null @@ -1,82 +0,0 @@ -# Copyright (C) 2013 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. - -LOCAL_PATH:= $(call my-dir) - -# libinput is partially built for the host (used by build time keymap validation tool) -# These files are common to host and target builds. - -commonSources := \ - Input.cpp \ - InputDevice.cpp \ - Keyboard.cpp \ - KeyCharacterMap.cpp \ - KeyLayoutMap.cpp \ - VirtualKeyMap.cpp - -deviceSources := \ - $(commonSources) \ - IInputFlinger.cpp \ - InputTransport.cpp \ - VelocityControl.cpp \ - VelocityTracker.cpp - -hostSources := \ - $(commonSources) - -# For the host -# ===================================================== - -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= $(hostSources) - -LOCAL_MODULE:= libinput - -LOCAL_MODULE_TAGS := optional - -include $(BUILD_HOST_STATIC_LIBRARY) - - -# For the device -# ===================================================== - -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= $(deviceSources) - -LOCAL_CLANG := true -LOCAL_SANITIZE := integer - -LOCAL_SHARED_LIBRARIES := \ - liblog \ - libcutils \ - libutils \ - libbinder - -LOCAL_MODULE:= libinput - -LOCAL_MODULE_TAGS := optional - -include $(BUILD_SHARED_LIBRARY) - - -# Include subdirectory makefiles -# ============================================================ - -# If we're building with ONE_SHOT_MAKEFILE (mm, mmm), then what the framework -# team really wants is to build the stuff defined by this makefile. -ifeq (,$(ONE_SHOT_MAKEFILE)) -include $(call first-makefiles-under,$(LOCAL_PATH)) -endif diff --git a/libs/input/IInputFlinger.cpp b/libs/input/IInputFlinger.cpp index e00973149c..003e73dae6 100644 --- a/libs/input/IInputFlinger.cpp +++ b/libs/input/IInputFlinger.cpp @@ -28,7 +28,7 @@ namespace android { class BpInputFlinger : public BpInterface<IInputFlinger> { public: - BpInputFlinger(const sp<IBinder>& impl) : + explicit BpInputFlinger(const sp<IBinder>& impl) : BpInterface<IInputFlinger>(impl) { } virtual status_t doSomething() { diff --git a/libs/input/tests/Android.bp b/libs/input/tests/Android.bp new file mode 100644 index 0000000000..f0b5edaf66 --- /dev/null +++ b/libs/input/tests/Android.bp @@ -0,0 +1,29 @@ +// Build the unit tests. +cc_test { + name: "libinput_tests", + test_per_src: true, + srcs: [ + "InputChannel_test.cpp", + "InputEvent_test.cpp", + "InputPublisherAndConsumer_test.cpp", + ], + shared_libs: [ + "libinput", + "libcutils", + "libutils", + "libbinder", + "libui", + ] +} + +// NOTE: This is a compile time test, and does not need to be +// run. All assertions are static_asserts and will fail during +// buildtime if something's wrong. +cc_library_static { + name: "StructLayout_test", + srcs: ["StructLayout_test.cpp"], + cflags: [ + "-std=c++11", + "-O0", + ], +} diff --git a/libs/input/tests/Android.mk b/libs/input/tests/Android.mk deleted file mode 100644 index 5bfa3d4808..0000000000 --- a/libs/input/tests/Android.mk +++ /dev/null @@ -1,40 +0,0 @@ -# Build the unit tests. -LOCAL_PATH:= $(call my-dir) - -# Build the unit tests. -test_src_files := \ - InputChannel_test.cpp \ - InputEvent_test.cpp \ - InputPublisherAndConsumer_test.cpp - -shared_libraries := \ - libinput \ - libcutils \ - libutils \ - libbinder \ - libui \ - -$(foreach file,$(test_src_files), \ - $(eval include $(CLEAR_VARS)) \ - $(eval LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk) \ - $(eval LOCAL_SHARED_LIBRARIES := $(shared_libraries)) \ - $(eval LOCAL_STATIC_LIBRARIES := $(static_libraries)) \ - $(eval LOCAL_SRC_FILES := $(file)) \ - $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \ - $(eval include $(BUILD_NATIVE_TEST)) \ -) - -# NOTE: This is a compile time test, and does not need to be -# run. All assertions are static_asserts and will fail during -# buildtime if something's wrong. -include $(CLEAR_VARS) -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk -LOCAL_SRC_FILES := StructLayout_test.cpp -LOCAL_MODULE := StructLayout_test -LOCAL_CFLAGS := -std=c++11 -O0 -LOCAL_MULTILIB := both -include $(BUILD_STATIC_LIBRARY) - - -# Build the manual test programs. -include $(call all-makefiles-under, $(LOCAL_PATH)) diff --git a/libs/input/tests/StructLayout_test.cpp b/libs/input/tests/StructLayout_test.cpp index 8d73f453e0..81b99531c1 100644 --- a/libs/input/tests/StructLayout_test.cpp +++ b/libs/input/tests/StructLayout_test.cpp @@ -20,7 +20,7 @@ namespace android { #define CHECK_OFFSET(type, member, expected_offset) \ - static_assert((offsetof(type, member) == expected_offset), "") + static_assert((offsetof(type, member) == (expected_offset)), "") struct Foo { uint32_t dummy; diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp new file mode 100644 index 0000000000..0777468585 --- /dev/null +++ b/libs/ui/Android.bp @@ -0,0 +1,69 @@ +// Copyright (C) 2010 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. + +cc_library_shared { + name: "libui", + + clang: true, + cppflags: [ + "-std=c++1y", + "-Weverything", + "-Werror", + + // The static constructors and destructors in this library have not been noted to + // introduce significant overheads + "-Wno-exit-time-destructors", + "-Wno-global-constructors", + + // We only care about compiling as C++14 + "-Wno-c++98-compat-pedantic", + + // We use four-character constants for the GraphicBuffer header, and don't care + // that they're non-portable as long as they're consistent within one execution + "-Wno-four-char-constants", + + // Don't warn about struct padding + "-Wno-padded", + ], + + sanitize: { + //misc_undefined: ["integer"], + }, + + srcs: [ + "Fence.cpp", + "FrameStats.cpp", + "Gralloc1.cpp", + "Gralloc1On0Adapter.cpp", + "GraphicBuffer.cpp", + "GraphicBufferAllocator.cpp", + "GraphicBufferMapper.cpp", + "HdrCapabilities.cpp", + "PixelFormat.cpp", + "Rect.cpp", + "Region.cpp", + "UiConfig.cpp", + ], + + shared_libs: [ + "libbinder", + "libcutils", + "libhardware", + "libsync", + "libutils", + "liblog", + ], +} + +subdirs = ["tests"] diff --git a/libs/ui/Android.mk b/libs/ui/Android.mk deleted file mode 100644 index e690ede195..0000000000 --- a/libs/ui/Android.mk +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright (C) 2010 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. - -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_CLANG := true -LOCAL_CPPFLAGS := -std=c++1y -Weverything -Werror -# LOCAL_SANITIZE := integer - -# The static constructors and destructors in this library have not been noted to -# introduce significant overheads -LOCAL_CPPFLAGS += -Wno-exit-time-destructors -LOCAL_CPPFLAGS += -Wno-global-constructors - -# We only care about compiling as C++14 -LOCAL_CPPFLAGS += -Wno-c++98-compat-pedantic - -# We use four-character constants for the GraphicBuffer header, and don't care -# that they're non-portable as long as they're consistent within one execution -LOCAL_CPPFLAGS += -Wno-four-char-constants - -# Don't warn about struct padding -LOCAL_CPPFLAGS += -Wno-padded - -LOCAL_SRC_FILES := \ - Fence.cpp \ - FrameStats.cpp \ - Gralloc1.cpp \ - Gralloc1On0Adapter.cpp \ - GraphicBuffer.cpp \ - GraphicBufferAllocator.cpp \ - GraphicBufferMapper.cpp \ - HdrCapabilities.cpp \ - PixelFormat.cpp \ - Rect.cpp \ - Region.cpp \ - UiConfig.cpp - -LOCAL_SHARED_LIBRARIES := \ - libbinder \ - libcutils \ - libhardware \ - libsync \ - libutils \ - liblog - -ifneq ($(BOARD_FRAMEBUFFER_FORCE_FORMAT),) -LOCAL_CFLAGS += -DFRAMEBUFFER_FORCE_FORMAT=$(BOARD_FRAMEBUFFER_FORCE_FORMAT) -endif - -LOCAL_MODULE := libui - -include $(BUILD_SHARED_LIBRARY) - - -# Include subdirectory makefiles -# ============================================================ - -# If we're building with ONE_SHOT_MAKEFILE (mm, mmm), then what the framework -# team really wants is to build the stuff defined by this makefile. -ifeq (,$(ONE_SHOT_MAKEFILE)) -include $(call first-makefiles-under,$(LOCAL_PATH)) -endif diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp index ee152bf91c..b53c563624 100644 --- a/libs/ui/Region.cpp +++ b/libs/ui/Region.cpp @@ -294,7 +294,7 @@ Region& Region::andSelf(const Rect& r) { Region& Region::subtractSelf(const Rect& r) { return operationSelf(r, op_nand); } -Region& Region::operationSelf(const Rect& r, int op) { +Region& Region::operationSelf(const Rect& r, uint32_t op) { Region lhs(*this); boolean_operation(op, *this, lhs, r); return *this; @@ -314,7 +314,7 @@ Region& Region::andSelf(const Region& rhs) { Region& Region::subtractSelf(const Region& rhs) { return operationSelf(rhs, op_nand); } -Region& Region::operationSelf(const Region& rhs, int op) { +Region& Region::operationSelf(const Region& rhs, uint32_t op) { Region lhs(*this); boolean_operation(op, *this, lhs, rhs); return *this; @@ -339,7 +339,7 @@ const Region Region::intersect(const Rect& rhs) const { const Region Region::subtract(const Rect& rhs) const { return operation(rhs, op_nand); } -const Region Region::operation(const Rect& rhs, int op) const { +const Region Region::operation(const Rect& rhs, uint32_t op) const { Region result; boolean_operation(op, result, *this, rhs); return result; @@ -359,7 +359,7 @@ const Region Region::intersect(const Region& rhs) const { const Region Region::subtract(const Region& rhs) const { return operation(rhs, op_nand); } -const Region Region::operation(const Region& rhs, int op) const { +const Region Region::operation(const Region& rhs, uint32_t op) const { Region result; boolean_operation(op, result, *this, rhs); return result; @@ -385,7 +385,7 @@ Region& Region::andSelf(const Region& rhs, int dx, int dy) { Region& Region::subtractSelf(const Region& rhs, int dx, int dy) { return operationSelf(rhs, dx, dy, op_nand); } -Region& Region::operationSelf(const Region& rhs, int dx, int dy, int op) { +Region& Region::operationSelf(const Region& rhs, int dx, int dy, uint32_t op) { Region lhs(*this); boolean_operation(op, *this, lhs, rhs, dx, dy); return *this; @@ -405,7 +405,7 @@ const Region Region::intersect(const Region& rhs, int dx, int dy) const { const Region Region::subtract(const Region& rhs, int dx, int dy) const { return operation(rhs, dx, dy, op_nand); } -const Region Region::operation(const Region& rhs, int dx, int dy, int op) const { +const Region Region::operation(const Region& rhs, int dx, int dy, uint32_t op) const { Region result; boolean_operation(op, result, *this, rhs, dx, dy); return result; @@ -424,7 +424,7 @@ class Region::rasterizer : public region_operator<Rect>::region_rasterizer Vector<Rect> span; Rect* cur; public: - rasterizer(Region& reg) + explicit rasterizer(Region& reg) : bounds(INT_MAX, 0, INT_MIN, 0), storage(reg.mStorage), head(), tail(), cur() { storage.clear(); } @@ -489,7 +489,8 @@ void Region::rasterizer::flushSpan() merge = false; break; } - p++, q++; + p++; + q++; } } } @@ -582,7 +583,7 @@ bool Region::validate(const Region& reg, const char* name, bool silent) return result; } -void Region::boolean_operation(int op, Region& dst, +void Region::boolean_operation(uint32_t op, Region& dst, const Region& lhs, const Region& rhs, int dx, int dy) { @@ -692,7 +693,7 @@ void Region::boolean_operation(int op, Region& dst, #endif } -void Region::boolean_operation(int op, Region& dst, +void Region::boolean_operation(uint32_t op, Region& dst, const Region& lhs, const Rect& rhs, int dx, int dy) { @@ -721,13 +722,13 @@ void Region::boolean_operation(int op, Region& dst, #endif } -void Region::boolean_operation(int op, Region& dst, +void Region::boolean_operation(uint32_t op, Region& dst, const Region& lhs, const Region& rhs) { boolean_operation(op, dst, lhs, rhs, 0, 0); } -void Region::boolean_operation(int op, Region& dst, +void Region::boolean_operation(uint32_t op, Region& dst, const Region& lhs, const Rect& rhs) { boolean_operation(op, dst, lhs, rhs, 0, 0); diff --git a/libs/ui/UiConfig.cpp b/libs/ui/UiConfig.cpp index 9e7ba8e886..7730690cfd 100644 --- a/libs/ui/UiConfig.cpp +++ b/libs/ui/UiConfig.cpp @@ -18,20 +18,10 @@ namespace android { -#ifdef FRAMEBUFFER_FORCE_FORMAT -// We need the two-level macro to stringify the contents of a macro argument -#define STRINGIFY(x) #x -#define TOSTRING(x) STRINGIFY(x) -#endif - void appendUiConfigString(String8& configStr) { static const char* config = - " [libui" -#ifdef FRAMEBUFFER_FORCE_FORMAT - " FRAMEBUFFER_FORCE_FORMAT=" TOSTRING(FRAMEBUFFER_FORCE_FORMAT) -#endif - "]"; + " [libui]"; configStr.append(config); } diff --git a/libs/ui/tests/Android.bp b/libs/ui/tests/Android.bp new file mode 100644 index 0000000000..8cdab8ccf8 --- /dev/null +++ b/libs/ui/tests/Android.bp @@ -0,0 +1,31 @@ +// +// Copyright (C) 2014 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. +// + +cc_test { + name: "Region_test", + shared_libs: ["libui"], + srcs: ["Region_test.cpp"], +} + +cc_test { + name: "vec_test", + srcs: ["vec_test.cpp"], +} + +cc_test { + name: "mat_test", + srcs: ["mat_test.cpp"], +} diff --git a/libs/ui/tests/Android.mk b/libs/ui/tests/Android.mk deleted file mode 100644 index 6438b1f9a4..0000000000 --- a/libs/ui/tests/Android.mk +++ /dev/null @@ -1,36 +0,0 @@ -# -# Copyright (C) 2014 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. -# - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk -LOCAL_SHARED_LIBRARIES := libui -LOCAL_SRC_FILES := Region_test.cpp -LOCAL_MODULE := Region_test -include $(BUILD_NATIVE_TEST) - -include $(CLEAR_VARS) -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk -LOCAL_SRC_FILES := vec_test.cpp -LOCAL_MODULE := vec_test -include $(BUILD_NATIVE_TEST) - -include $(CLEAR_VARS) -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk -LOCAL_SRC_FILES := mat_test.cpp -LOCAL_MODULE := mat_test -include $(BUILD_NATIVE_TEST) diff --git a/opengl/Android.bp b/opengl/Android.bp new file mode 100644 index 0000000000..164be2054a --- /dev/null +++ b/opengl/Android.bp @@ -0,0 +1,52 @@ +// Copyright (C) 2016 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. + +ndk_headers { + name: "libEGL_headers", + from: "include", + to: "", + srcs: ["include/EGL/**/*.h"], +} + +ndk_headers { + name: "libGLESv1_CM_headers", + from: "include", + to: "", + srcs: ["include/GLES/**/*.h"], +} + +ndk_headers { + name: "libGLESv2_headers", + from: "include", + to: "", + srcs: ["include/GLES2/**/*.h"], +} + +ndk_headers { + name: "libGLESv3_headers", + from: "include", + to: "", + srcs: ["include/GLES3/**/*.h"], +} + +ndk_headers { + name: "khr_headers", + from: "include", + to: "", + srcs: ["include/KHR/**/*.h"], +} + +subdirs = [ + "*", +] diff --git a/opengl/include/EGL/eglext.h b/opengl/include/EGL/eglext.h index 2e186985e6..8e69330968 100644 --- a/opengl/include/EGL/eglext.h +++ b/opengl/include/EGL/eglext.h @@ -115,6 +115,13 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGL #define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD /* eglCreateImageKHR attribute */ #endif +#ifndef EGL_KHR_gl_colorspace +#define EGL_KHR_gl_colorspace 1 +#define EGL_GL_COLORSPACE_KHR 0x309D +#define EGL_GL_COLORSPACE_SRGB_KHR 0x3089 +#define EGL_GL_COLORSPACE_LINEAR_KHR 0x308A +#endif + #ifndef EGL_KHR_gl_renderbuffer_image #define EGL_KHR_gl_renderbuffer_image 1 #define EGL_GL_RENDERBUFFER_KHR 0x30B9 /* eglCreateImageKHR target */ @@ -545,7 +552,7 @@ typedef void (EGLAPIENTRYP PFNEGLSETBLOBCACHEFUNCSANDROIDPROC)(EGLDisplay dpy, E #define EGL_SYNC_NATIVE_FENCE_ANDROID 0x3144 #define EGL_SYNC_NATIVE_FENCE_FD_ANDROID 0x3145 #define EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID 0x3146 -#define EGL_NO_NATIVE_FENCE_FD_ANDROID -1 +#define EGL_NO_NATIVE_FENCE_FD_ANDROID (-1) #ifdef EGL_EGLEXT_PROTOTYPES EGLAPI EGLint EGLAPIENTRY eglDupNativeFenceFDANDROID( EGLDisplay dpy, EGLSyncKHR); #endif /* EGL_EGLEXT_PROTOTYPES */ diff --git a/opengl/libagl/arch-mips/fixed_asm.S b/opengl/libagl/arch-mips/fixed_asm.S index e1a53bc745..a30ffc5473 100644 --- a/opengl/libagl/arch-mips/fixed_asm.S +++ b/opengl/libagl/arch-mips/fixed_asm.S @@ -17,7 +17,7 @@ .text - .align + .align 4 /* * this version rounds-to-nearest and saturates numbers diff --git a/opengl/libs/Android.bp b/opengl/libs/Android.bp new file mode 100644 index 0000000000..bdd5152209 --- /dev/null +++ b/opengl/libs/Android.bp @@ -0,0 +1,47 @@ +// Build the ETC1 library +cc_library { + name: "libETC1", + srcs: ["ETC1/etc1.cpp"], + host_supported: true, + + target: { + android: { + static: { + enabled: false, + }, + }, + host: { + shared: { + enabled: false, + }, + }, + windows: { + enabled: true, + }, + }, +} + +// The headers modules are in frameworks/native/opengl/Android.bp. +ndk_library { + name: "libEGL.ndk", + symbol_file: "libEGL.map.txt", + first_version: "9", +} + +ndk_library { + name: "libGLESv1_CM.ndk", + symbol_file: "libGLESv1_CM.map.txt", + first_version: "9", +} + +ndk_library { + name: "libGLESv2.ndk", + symbol_file: "libGLESv2.map.txt", + first_version: "9", +} + +ndk_library { + name: "libGLESv3.ndk", + symbol_file: "libGLESv3.map.txt", + first_version: "18", +} diff --git a/opengl/libs/Android.mk b/opengl/libs/Android.mk index 24e4c19a58..f0ba7280db 100644 --- a/opengl/libs/Android.mk +++ b/opengl/libs/Android.mk @@ -77,7 +77,6 @@ LOCAL_SRC_FILES:= \ GLES_CM/gl.cpp.arm \ # -LOCAL_CLANG := false LOCAL_SHARED_LIBRARIES += libcutils liblog libEGL LOCAL_MODULE:= libGLESv1_CM @@ -105,7 +104,6 @@ LOCAL_SRC_FILES:= \ GLES2/gl2.cpp \ # -LOCAL_CLANG := false LOCAL_ARM_MODE := arm LOCAL_SHARED_LIBRARIES += libcutils libutils liblog libEGL LOCAL_MODULE:= libGLESv2 @@ -133,7 +131,6 @@ LOCAL_SRC_FILES:= \ GLES2/gl2.cpp \ # -LOCAL_CLANG := false LOCAL_ARM_MODE := arm LOCAL_SHARED_LIBRARIES += libcutils libutils liblog libEGL LOCAL_MODULE:= libGLESv3 @@ -150,33 +147,4 @@ LOCAL_LDFLAGS_arm += -Wl,--hash-style,both include $(BUILD_SHARED_LIBRARY) -############################################################################### -# Build the ETC1 host static library -# - -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= \ - ETC1/etc1.cpp \ -# - -LOCAL_MODULE:= libETC1 -LOCAL_MODULE_HOST_OS := darwin linux windows - -include $(BUILD_HOST_STATIC_LIBRARY) - -############################################################################### -# Build the ETC1 device library -# - -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= \ - ETC1/etc1.cpp \ -# - -LOCAL_MODULE:= libETC1 - -include $(BUILD_SHARED_LIBRARY) - include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/opengl/libs/EGL/Loader.h b/opengl/libs/EGL/Loader.h index 8cefe32764..94f680e9ea 100644 --- a/opengl/libs/EGL/Loader.h +++ b/opengl/libs/EGL/Loader.h @@ -46,7 +46,7 @@ class Loader : public Singleton<Loader> GLESv2 = 0x04 }; struct driver_t { - driver_t(void* gles); + explicit driver_t(void* gles); ~driver_t(); status_t set(void* hnd, int32_t api); void* dso[3]; diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp index f41e6e2311..5e727942ac 100644 --- a/opengl/libs/EGL/eglApi.cpp +++ b/opengl/libs/EGL/eglApi.cpp @@ -56,10 +56,6 @@ using namespace android; -// This extension has not been ratified yet, so can't be shipped. -// Implementation is incomplete and untested. -#define ENABLE_EGL_KHR_GL_COLORSPACE 0 - #define ENABLE_EGL_ANDROID_GET_FRAME_TIMESTAMPS 0 // ---------------------------------------------------------------------------- @@ -101,9 +97,7 @@ extern char const * const gExtensionString = "EGL_KHR_image_base " // mandatory "EGL_KHR_image_pixmap " "EGL_KHR_lock_surface " -#if (ENABLE_EGL_KHR_GL_COLORSPACE != 0) "EGL_KHR_gl_colorspace " -#endif "EGL_KHR_gl_texture_2D_image " "EGL_KHR_gl_texture_3D_image " "EGL_KHR_gl_texture_cubemap_image " @@ -442,12 +436,6 @@ EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, // surfaces // ---------------------------------------------------------------------------- -// The EGL_KHR_gl_colorspace spec hasn't been ratified yet, so these haven't -// been added to the Khronos egl.h. -#define EGL_GL_COLORSPACE_KHR EGL_VG_COLORSPACE -#define EGL_GL_COLORSPACE_SRGB_KHR EGL_VG_COLORSPACE_sRGB -#define EGL_GL_COLORSPACE_LINEAR_KHR EGL_VG_COLORSPACE_LINEAR - // Turn linear formats into corresponding sRGB formats when colorspace is // EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear // formats when colorspace is EGL_GL_COLORSPACE_LINEAR_KHR. In any cases where @@ -514,17 +502,7 @@ EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) { for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) { if (*attr == EGL_GL_COLORSPACE_KHR) { - if (ENABLE_EGL_KHR_GL_COLORSPACE) { - dataSpace = modifyBufferDataspace(dataSpace, *(attr+1)); - } else { - // Normally we'd pass through unhandled attributes to - // the driver. But in case the driver implements this - // extension but we're disabling it, we want to prevent - // it getting through -- support will be broken without - // our help. - ALOGE("sRGB window surfaces not supported"); - return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); - } + dataSpace = modifyBufferDataspace(dataSpace, *(attr+1)); } } } @@ -1352,13 +1330,14 @@ EGLBoolean eglReleaseThread(void) { clearError(); - // If there is context bound to the thread, release it - egl_display_t::loseCurrent(get_context(getContext())); - egl_connection_t* const cnx = &gEGLImpl; if (cnx->dso && cnx->egl.eglReleaseThread) { cnx->egl.eglReleaseThread(); } + + // If there is context bound to the thread, release it + egl_display_t::loseCurrent(get_context(getContext())); + egl_tls_t::clearTLS(); return EGL_TRUE; } diff --git a/opengl/libs/EGL/egl_object.h b/opengl/libs/EGL/egl_object.h index 97eda4ce79..3150ba6918 100644 --- a/opengl/libs/EGL/egl_object.h +++ b/opengl/libs/EGL/egl_object.h @@ -48,7 +48,7 @@ protected: virtual void terminate(); public: - egl_object_t(egl_display_t* display); + explicit egl_object_t(egl_display_t* display); void destroy(); inline void incRef() { count.fetch_add(1, std::memory_order_relaxed); } @@ -63,7 +63,7 @@ public: class LocalRef { egl_object_t* ref; LocalRef(); - LocalRef(const LocalRef* rhs); + explicit LocalRef(const LocalRef* rhs); public: ~LocalRef(); explicit LocalRef(egl_object_t* rhs); diff --git a/opengl/libs/GLES2/gl2.cpp b/opengl/libs/GLES2/gl2.cpp index 6034a8edc0..6dd87c28e4 100644 --- a/opengl/libs/GLES2/gl2.cpp +++ b/opengl/libs/GLES2/gl2.cpp @@ -34,39 +34,65 @@ using namespace android; #undef API_ENTRY #undef CALL_GL_API +#undef CALL_GL_API_INTERNAL_CALL +#undef CALL_GL_API_INTERNAL_SET_RETURN_VALUE +#undef CALL_GL_API_INTERNAL_DO_RETURN #undef CALL_GL_API_RETURN #if USE_SLOW_BINDING #define API_ENTRY(_api) _api - #define CALL_GL_API(_api, ...) \ + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ if (_c) return _c->_api(__VA_ARGS__); + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE return 0; + + // This stays blank, since void functions will implicitly return, and + // all of the other functions will return 0 based on the previous macro. + #define CALL_GL_API_INTERNAL_DO_RETURN + #elif defined(__arm__) #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n" - #define API_ENTRY(_api) __attribute__((noinline)) _api - - #define CALL_GL_API(_api, ...) \ - asm volatile( \ - GET_TLS(r12) \ - "ldr r12, [r12, %[tls]] \n" \ - "cmp r12, #0 \n" \ - "ldrne pc, [r12, %[api]] \n" \ - : \ - : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ - [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \ - : "r12" \ - ); + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api + + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ + asm volatile( \ + GET_TLS(r12) \ + "ldr r12, [r12, %[tls]] \n" \ + "cmp r12, #0 \n" \ + "ldrne pc, [r12, %[api]] \n" \ + : \ + : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ + [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \ + : "r0", "r1", "r2", "r3", "r12" \ + ); + + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ + asm volatile( \ + "mov r0, #0 \n" \ + : \ + : \ + : "r0" \ + ); + + + #define CALL_GL_API_INTERNAL_DO_RETURN \ + asm volatile( \ + "bx lr \n" \ + : \ + : \ + : "r0" \ + ); #elif defined(__aarch64__) - #define API_ENTRY(_api) __attribute__((noinline)) _api + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api - #define CALL_GL_API(_api, ...) \ + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ asm volatile( \ "mrs x16, tpidr_el0\n" \ "ldr x16, [x16, %[tls]]\n" \ @@ -77,121 +103,173 @@ using namespace android; : \ : [tls] "i" (TLS_SLOT_OPENGL_API * sizeof(void*)), \ [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api)) \ - : "x16" \ + : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x16" \ + ); + + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ + asm volatile( \ + "mov w0, wzr \n" \ + : \ + : \ + : "w0" \ + ); + + #define CALL_GL_API_INTERNAL_DO_RETURN \ + asm volatile( \ + "ret \n" \ + : \ + : \ + : \ ); #elif defined(__i386__) - #define API_ENTRY(_api) __attribute__((noinline,optimize("omit-frame-pointer"))) _api + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api - #define CALL_GL_API(_api, ...) \ - register void** fn; \ + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ __asm__ volatile( \ - "mov %%gs:0, %[fn]\n" \ - "mov %P[tls](%[fn]), %[fn]\n" \ - "test %[fn], %[fn]\n" \ + "mov %%gs:0, %%eax\n" \ + "mov %P[tls](%%eax), %%eax\n" \ + "test %%eax, %%eax\n" \ "je 1f\n" \ - "jmp *%P[api](%[fn])\n" \ + "jmp *%P[api](%%eax)\n" \ "1:\n" \ - : [fn] "=r" (fn) \ + : \ : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)), \ [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api)) \ - : "cc" \ + : "cc", "%eax" \ ); + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ + __asm__ volatile( \ + "xor %%eax, %%eax\n" \ + : \ + : \ + : "%eax" \ + ); + + #define CALL_GL_API_INTERNAL_DO_RETURN \ + __asm__ volatile( \ + "ret\n" \ + : \ + : \ + : \ + ); + #elif defined(__x86_64__) - #define API_ENTRY(_api) __attribute__((noinline,optimize("omit-frame-pointer"))) _api + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api - #define CALL_GL_API(_api, ...) \ - register void** fn; \ - __asm__ volatile( \ - "mov %%fs:0, %[fn]\n" \ - "mov %P[tls](%[fn]), %[fn]\n" \ - "test %[fn], %[fn]\n" \ + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ + __asm__ volatile( \ + "mov %%fs:0, %%rax\n" \ + "mov %P[tls](%%rax), %%rax\n" \ + "test %%rax, %%rax\n" \ "je 1f\n" \ - "jmp *%P[api](%[fn])\n" \ + "jmp *%P[api](%%rax)\n" \ "1:\n" \ - : [fn] "=r" (fn) \ + : \ : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)), \ [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api)) \ - : "cc" \ - ); + : "cc", "%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9", \ + "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", \ + "%xmm6", "%xmm7" \ + ); + + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ + __asm__ volatile( \ + "xor %%eax, %%eax\n" \ + : \ + : \ + : "%eax" \ + ); + + #define CALL_GL_API_INTERNAL_DO_RETURN \ + __asm__ volatile( \ + "retq\n" \ + : \ + : \ + : \ + ); #elif defined(__mips64) - #define API_ENTRY(_api) __attribute__((noinline)) _api - - #define CALL_GL_API(_api, ...) \ - register unsigned long _t0 asm("$12"); \ - register unsigned long _fn asm("$25"); \ - register unsigned long _tls asm("$3"); \ - register unsigned long _v0 asm("$2"); \ - asm volatile( \ - ".set push\n\t" \ - ".set noreorder\n\t" \ - "rdhwr %[tls], $29\n\t" \ - "ld %[t0], %[OPENGL_API](%[tls])\n\t" \ - "beqz %[t0], 1f\n\t" \ - " move %[fn], $ra\n\t" \ - "ld %[t0], %[API](%[t0])\n\t" \ - "beqz %[t0], 1f\n\t" \ - " nop\n\t" \ - "move %[fn], %[t0]\n\t" \ - "1:\n\t" \ - "jalr $0, %[fn]\n\t" \ - " move %[v0], $0\n\t" \ - ".set pop\n\t" \ - : [fn] "=c"(_fn), \ - [tls] "=&r"(_tls), \ - [t0] "=&r"(_t0), \ - [v0] "=&r"(_v0) \ - : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*sizeof(void*)),\ - [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \ - : \ + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api + + // t0: $12 + // fn: $25 + // tls: $3 + // v0: $2 + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ + asm volatile( \ + ".set push\n\t" \ + ".set noreorder\n\t" \ + "rdhwr $3, $29\n\t" \ + "ld $12, %[OPENGL_API]($3)\n\t" \ + "beqz $12, 1f\n\t" \ + " move $25, $ra\n\t" \ + "ld $12, %[API]($12)\n\t" \ + "beqz $12, 1f\n\t" \ + " nop\n\t" \ + "move $25, $12\n\t" \ + "1:\n\t" \ + "jalr $0, $25\n\t" \ + " move $2, $0\n\t" \ + ".set pop\n\t" \ + : \ + : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*sizeof(void*)),\ + [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \ + : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", \ + "$10", "$11", "$12", "$25" \ ); + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE + #define CALL_GL_API_INTERNAL_DO_RETURN + #elif defined(__mips__) - #define API_ENTRY(_api) __attribute__((noinline)) _api + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api - #define CALL_GL_API(_api, ...) \ - register unsigned int _t0 asm("$8"); \ - register unsigned int _fn asm("$25"); \ - register unsigned int _tls asm("$3"); \ - register unsigned int _v0 asm("$2"); \ + // t0: $8 + // fn: $25 + // tls: $3 + // v0: $2 + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ asm volatile( \ ".set push\n\t" \ ".set noreorder\n\t" \ ".set mips32r2\n\t" \ - "rdhwr %[tls], $29\n\t" \ - "lw %[t0], %[OPENGL_API](%[tls])\n\t" \ - "beqz %[t0], 1f\n\t" \ - " move %[fn],$ra\n\t" \ - "lw %[t0], %[API](%[t0])\n\t" \ - "beqz %[t0], 1f\n\t" \ + "rdhwr $3, $29\n\t" \ + "lw $3, %[OPENGL_API]($3)\n\t" \ + "beqz $3, 1f\n\t" \ + " move $25,$ra\n\t" \ + "lw $3, %[API]($3)\n\t" \ + "beqz $3, 1f\n\t" \ " nop\n\t" \ - "move %[fn], %[t0]\n\t" \ + "move $25, $3\n\t" \ "1:\n\t" \ - "jalr $0, %[fn]\n\t" \ - " move %[v0], $0\n\t" \ + "jalr $0, $25\n\t" \ + " move $2, $0\n\t" \ ".set pop\n\t" \ - : [fn] "=c"(_fn), \ - [tls] "=&r"(_tls), \ - [t0] "=&r"(_t0), \ - [v0] "=&r"(_v0) \ + : \ : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \ [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \ - : \ - ); + : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$25" \ + ); -#endif + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE + #define CALL_GL_API_INTERNAL_DO_RETURN -#define CALL_GL_API_RETURN(_api, ...) \ - CALL_GL_API(_api, __VA_ARGS__) \ - return 0; +#endif +#define CALL_GL_API(_api, ...) \ + CALL_GL_API_INTERNAL_CALL(_api, __VA_ARGS__) \ + CALL_GL_API_INTERNAL_DO_RETURN +#define CALL_GL_API_RETURN(_api, ...) \ + CALL_GL_API_INTERNAL_CALL(_api, __VA_ARGS__) \ + CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ + CALL_GL_API_INTERNAL_DO_RETURN extern "C" { #pragma GCC diagnostic ignored "-Wunused-parameter" @@ -202,6 +280,9 @@ extern "C" { #undef API_ENTRY #undef CALL_GL_API +#undef CALL_GL_API_INTERNAL_CALL +#undef CALL_GL_API_INTERNAL_SET_RETURN_VALUE +#undef CALL_GL_API_INTERNAL_DO_RETURN #undef CALL_GL_API_RETURN /* diff --git a/opengl/libs/GLES_CM/gl.cpp b/opengl/libs/GLES_CM/gl.cpp index b1b31f8294..8bde4e5f04 100644 --- a/opengl/libs/GLES_CM/gl.cpp +++ b/opengl/libs/GLES_CM/gl.cpp @@ -90,39 +90,65 @@ GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, #undef API_ENTRY #undef CALL_GL_API +#undef CALL_GL_API_INTERNAL_CALL +#undef CALL_GL_API_INTERNAL_SET_RETURN_VALUE +#undef CALL_GL_API_INTERNAL_DO_RETURN #undef CALL_GL_API_RETURN #if USE_SLOW_BINDING #define API_ENTRY(_api) _api - #define CALL_GL_API(_api, ...) \ + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ if (_c) return _c->_api(__VA_ARGS__); + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE return 0; + + // This stays blank, since void functions will implicitly return, and + // all of the other functions will return 0 based on the previous macro. + #define CALL_GL_API_INTERNAL_DO_RETURN + #elif defined(__arm__) #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n" - #define API_ENTRY(_api) __attribute__((noinline)) _api + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api - #define CALL_GL_API(_api, ...) \ - asm volatile( \ - GET_TLS(r12) \ - "ldr r12, [r12, %[tls]] \n" \ - "cmp r12, #0 \n" \ - "ldrne pc, [r12, %[api]] \n" \ - : \ - : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ - [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \ - : "r12" \ - ); + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ + asm volatile( \ + GET_TLS(r12) \ + "ldr r12, [r12, %[tls]] \n" \ + "cmp r12, #0 \n" \ + "ldrne pc, [r12, %[api]] \n" \ + : \ + : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ + [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \ + : "r0", "r1", "r2", "r3", "r12" \ + ); + + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ + asm volatile( \ + "mov r0, #0 \n" \ + : \ + : \ + : "r0" \ + ); + + + #define CALL_GL_API_INTERNAL_DO_RETURN \ + asm volatile( \ + "bx lr \n" \ + : \ + : \ + : "r0" \ + ); #elif defined(__aarch64__) - #define API_ENTRY(_api) __attribute__((noinline)) _api + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api - #define CALL_GL_API(_api, ...) \ + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ asm volatile( \ "mrs x16, tpidr_el0\n" \ "ldr x16, [x16, %[tls]]\n" \ @@ -133,120 +159,173 @@ GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, : \ : [tls] "i" (TLS_SLOT_OPENGL_API * sizeof(void*)), \ [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api)) \ - : "x16" \ + : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x16" \ + ); + + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ + asm volatile( \ + "mov w0, wzr \n" \ + : \ + : \ + : "w0" \ + ); + + #define CALL_GL_API_INTERNAL_DO_RETURN \ + asm volatile( \ + "ret \n" \ + : \ + : \ + : \ ); #elif defined(__i386__) - #define API_ENTRY(_api) __attribute__((noinline,optimize("omit-frame-pointer"))) _api + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api - #define CALL_GL_API(_api, ...) \ - register void* fn; \ + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ __asm__ volatile( \ - "mov %%gs:0, %[fn]\n" \ - "mov %P[tls](%[fn]), %[fn]\n" \ - "test %[fn], %[fn]\n" \ + "mov %%gs:0, %%eax\n" \ + "mov %P[tls](%%eax), %%eax\n" \ + "test %%eax, %%eax\n" \ "je 1f\n" \ - "jmp *%P[api](%[fn])\n" \ + "jmp *%P[api](%%eax)\n" \ "1:\n" \ - : [fn] "=r" (fn) \ + : \ : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)), \ [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api)) \ - : "cc" \ - ); + : "cc", "%eax" \ + ); + + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ + __asm__ volatile( \ + "xor %%eax, %%eax\n" \ + : \ + : \ + : "%eax" \ + ); + + #define CALL_GL_API_INTERNAL_DO_RETURN \ + __asm__ volatile( \ + "ret\n" \ + : \ + : \ + : \ + ); #elif defined(__x86_64__) - #define API_ENTRY(_api) __attribute__((noinline,optimize("omit-frame-pointer"))) _api + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api - #define CALL_GL_API(_api, ...) \ - register void** fn; \ - __asm__ volatile( \ - "mov %%fs:0, %[fn]\n" \ - "mov %P[tls](%[fn]), %[fn]\n" \ - "test %[fn], %[fn]\n" \ + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ + __asm__ volatile( \ + "mov %%fs:0, %%rax\n" \ + "mov %P[tls](%%rax), %%rax\n" \ + "test %%rax, %%rax\n" \ "je 1f\n" \ - "jmp *%P[api](%[fn])\n" \ + "jmp *%P[api](%%rax)\n" \ "1:\n" \ - : [fn] "=r" (fn) \ + : \ : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)), \ [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api)) \ - : "cc" \ - ); + : "cc", "%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9", \ + "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", \ + "%xmm6", "%xmm7" \ + ); + + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ + __asm__ volatile( \ + "xor %%eax, %%eax\n" \ + : \ + : \ + : "%eax" \ + ); + + #define CALL_GL_API_INTERNAL_DO_RETURN \ + __asm__ volatile( \ + "retq\n" \ + : \ + : \ + : \ + ); #elif defined(__mips64) - #define API_ENTRY(_api) __attribute__((noinline)) _api - - #define CALL_GL_API(_api, ...) \ - register unsigned long _t0 asm("$12"); \ - register unsigned long _fn asm("$25"); \ - register unsigned long _tls asm("$3"); \ - register unsigned long _v0 asm("$2"); \ - asm volatile( \ - ".set push\n\t" \ - ".set noreorder\n\t" \ - "rdhwr %[tls], $29\n\t" \ - "ld %[t0], %[OPENGL_API](%[tls])\n\t" \ - "beqz %[t0], 1f\n\t" \ - " move %[fn], $ra\n\t" \ - "ld %[t0], %[API](%[t0])\n\t" \ - "beqz %[t0], 1f\n\t" \ - " nop\n\t" \ - "move %[fn], %[t0]\n\t" \ - "1:\n\t" \ - "jalr $0, %[fn]\n\t" \ - " move %[v0], $0\n\t" \ - ".set pop\n\t" \ - : [fn] "=c"(_fn), \ - [tls] "=&r"(_tls), \ - [t0] "=&r"(_t0), \ - [v0] "=&r"(_v0) \ - : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*sizeof(void*)),\ - [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \ - : \ + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api + + // t0: $12 + // fn: $25 + // tls: $3 + // v0: $2 + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ + asm volatile( \ + ".set push\n\t" \ + ".set noreorder\n\t" \ + "rdhwr $3, $29\n\t" \ + "ld $12, %[OPENGL_API]($3)\n\t" \ + "beqz $12, 1f\n\t" \ + " move $25, $ra\n\t" \ + "ld $12, %[API]($12)\n\t" \ + "beqz $12, 1f\n\t" \ + " nop\n\t" \ + "move $25, $12\n\t" \ + "1:\n\t" \ + "jalr $0, $25\n\t" \ + " move $2, $0\n\t" \ + ".set pop\n\t" \ + : \ + : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*sizeof(void*)),\ + [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \ + : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", \ + "$10", "$11", "$12", "$25" \ ); + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE + #define CALL_GL_API_INTERNAL_DO_RETURN + #elif defined(__mips__) - #define API_ENTRY(_api) __attribute__((noinline)) _api + #define API_ENTRY(_api) __attribute__((naked,noinline)) _api - #define CALL_GL_API(_api, ...) \ - register unsigned int _t0 asm("$8"); \ - register unsigned int _fn asm("$25"); \ - register unsigned int _tls asm("$3"); \ - register unsigned int _v0 asm("$2"); \ + // t0: $8 + // fn: $25 + // tls: $3 + // v0: $2 + #define CALL_GL_API_INTERNAL_CALL(_api, ...) \ asm volatile( \ ".set push\n\t" \ ".set noreorder\n\t" \ ".set mips32r2\n\t" \ - "rdhwr %[tls], $29\n\t" \ - "lw %[t0], %[OPENGL_API](%[tls])\n\t" \ - "beqz %[t0], 1f\n\t" \ - " move %[fn], $ra\n\t" \ - "lw %[t0], %[API](%[t0])\n\t" \ - "beqz %[t0], 1f\n\t" \ + "rdhwr $3, $29\n\t" \ + "lw $3, %[OPENGL_API]($3)\n\t" \ + "beqz $3, 1f\n\t" \ + " move $25,$ra\n\t" \ + "lw $3, %[API]($3)\n\t" \ + "beqz $3, 1f\n\t" \ " nop\n\t" \ - "move %[fn], %[t0]\n\t" \ + "move $25, $3\n\t" \ "1:\n\t" \ - "jalr $0, %[fn]\n\t" \ - " move %[v0], $0\n\t" \ + "jalr $0, $25\n\t" \ + " move $2, $0\n\t" \ ".set pop\n\t" \ - : [fn] "=c"(_fn), \ - [tls] "=&r"(_tls), \ - [t0] "=&r"(_t0), \ - [v0] "=&r"(_v0) \ + : \ : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \ [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \ - : \ - ); + : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$25" \ + ); + + #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE + #define CALL_GL_API_INTERNAL_DO_RETURN #endif -#define CALL_GL_API_RETURN(_api, ...) \ - CALL_GL_API(_api, __VA_ARGS__) \ - return 0; +#define CALL_GL_API(_api, ...) \ + CALL_GL_API_INTERNAL_CALL(_api, __VA_ARGS__) \ + CALL_GL_API_INTERNAL_DO_RETURN +#define CALL_GL_API_RETURN(_api, ...) \ + CALL_GL_API_INTERNAL_CALL(_api, __VA_ARGS__) \ + CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ + CALL_GL_API_INTERNAL_DO_RETURN extern "C" { #pragma GCC diagnostic ignored "-Wunused-parameter" @@ -257,6 +336,9 @@ extern "C" { #undef API_ENTRY #undef CALL_GL_API +#undef CALL_GL_API_INTERNAL_CALL +#undef CALL_GL_API_INTERNAL_SET_RETURN_VALUE +#undef CALL_GL_API_INTERNAL_DO_RETURN #undef CALL_GL_API_RETURN /* diff --git a/opengl/libs/hooks.h b/opengl/libs/hooks.h index e14075cdb7..81dbe0e34b 100644 --- a/opengl/libs/hooks.h +++ b/opengl/libs/hooks.h @@ -56,8 +56,8 @@ namespace android { #undef GL_ENTRY #undef EGL_ENTRY -#define GL_ENTRY(_r, _api, ...) _r (*_api)(__VA_ARGS__); -#define EGL_ENTRY(_r, _api, ...) _r (*_api)(__VA_ARGS__); +#define GL_ENTRY(_r, _api, ...) _r (*(_api))(__VA_ARGS__); +#define EGL_ENTRY(_r, _api, ...) _r (*(_api))(__VA_ARGS__); struct egl_t { #include "EGL/egl_entries.in" diff --git a/opengl/libs/libEGL.map.txt b/opengl/libs/libEGL.map.txt new file mode 100644 index 0000000000..c8b83f544e --- /dev/null +++ b/opengl/libs/libEGL.map.txt @@ -0,0 +1,67 @@ +LIBEGL { + global: + eglBindAPI; + eglBindTexImage; + eglChooseConfig; + eglClientWaitSyncKHR; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21 + eglCopyBuffers; + eglCreateContext; + eglCreateImageKHR; + eglCreateNativeClientBufferANDROID; # introduced=24 + eglCreatePbufferFromClientBuffer; + eglCreatePbufferSurface; + eglCreatePixmapSurface; + eglCreateStreamFromFileDescriptorKHR; # introduced=23 + eglCreateStreamKHR; # introduced=23 + eglCreateStreamProducerSurfaceKHR; # introduced=23 + eglCreateSyncKHR; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21 + eglCreateWindowSurface; + eglDestroyContext; + eglDestroyImageKHR; + eglDestroyStreamKHR; # introduced=23 + eglDestroySurface; + eglDestroySyncKHR; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21 + eglGetConfigAttrib; + eglGetConfigs; + eglGetCurrentContext; + eglGetCurrentDisplay; + eglGetCurrentSurface; + eglGetDisplay; + eglGetError; + eglGetProcAddress; + eglGetStreamFileDescriptorKHR; # introduced=23 + eglGetSyncAttribKHR; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21 + eglGetSystemTimeFrequencyNV; # introduced-arm=14 introduced-arm64=21 introduced-mips=14 introduced-mips64=21 introduced-x86=14 introduced-x86_64=21 + eglGetSystemTimeNV; # introduced-arm=14 introduced-arm64=21 introduced-mips=14 introduced-mips64=21 introduced-x86=14 introduced-x86_64=21 + eglInitialize; + eglLockSurfaceKHR; + eglMakeCurrent; + eglPresentationTimeANDROID; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21 + eglQueryAPI; + eglQueryContext; + eglQueryStreamKHR; # introduced=23 + eglQueryStreamTimeKHR; # introduced=23 + eglQueryStreamu64KHR; # introduced=23 + eglQueryString; + eglQuerySurface; + eglReleaseTexImage; + eglReleaseThread; + eglSetDamageRegionKHR; # introduced=23 + eglSignalSyncKHR; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21 + eglStreamAttribKHR; # introduced=23 + eglStreamConsumerAcquireKHR; # introduced=23 + eglStreamConsumerGLTextureExternalKHR; # introduced=23 + eglStreamConsumerReleaseKHR; # introduced=23 + eglSurfaceAttrib; + eglSwapBuffers; + eglSwapBuffersWithDamageKHR; # introduced=23 + eglSwapInterval; + eglTerminate; + eglUnlockSurfaceKHR; + eglWaitClient; + eglWaitGL; + eglWaitNative; + eglWaitSyncKHR; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21 + local: + *; +}; diff --git a/opengl/libs/libGLESv1_CM.map.txt b/opengl/libs/libGLESv1_CM.map.txt new file mode 100644 index 0000000000..8ba91e6e65 --- /dev/null +++ b/opengl/libs/libGLESv1_CM.map.txt @@ -0,0 +1,283 @@ +LIBGLESV1_CM { + global: + glActiveTexture; + glAlphaFunc; + glAlphaFuncx; + glAlphaFuncxOES; + glBindBuffer; + glBindFramebufferOES; + glBindRenderbufferOES; + glBindTexture; + glBindVertexArrayOES; # introduced-mips=9 introduced-x86=9 + glBlendEquationOES; + glBlendEquationSeparateOES; + glBlendFunc; + glBlendFuncSeparateOES; + glBufferData; + glBufferSubData; + glCheckFramebufferStatusOES; + glClear; + glClearColor; + glClearColorx; + glClearColorxOES; + glClearDepthf; + glClearDepthfOES; + glClearDepthx; + glClearDepthxOES; + glClearStencil; + glClientActiveTexture; + glClipPlanef; + glClipPlanefIMG; # introduced-mips=9 introduced-x86=9 + glClipPlanefOES; + glClipPlanex; + glClipPlanexIMG; # introduced-mips=9 introduced-x86=9 + glClipPlanexOES; + glColor4f; + glColor4ub; + glColor4x; + glColor4xOES; + glColorMask; + glColorPointer; + glColorPointerBounds; + glCompressedTexImage2D; + glCompressedTexSubImage2D; + glCopyTexImage2D; + glCopyTexSubImage2D; + glCullFace; + glCurrentPaletteMatrixOES; + glDeleteBuffers; + glDeleteFencesNV; # introduced-mips=9 introduced-x86=9 + glDeleteFramebuffersOES; + glDeleteRenderbuffersOES; + glDeleteTextures; + glDeleteVertexArraysOES; # introduced-mips=9 introduced-x86=9 + glDepthFunc; + glDepthMask; + glDepthRangef; + glDepthRangefOES; + glDepthRangex; + glDepthRangexOES; + glDisable; + glDisableClientState; + glDisableDriverControlQCOM; # introduced-mips=9 introduced-x86=9 + glDiscardFramebufferEXT; # introduced-mips=9 introduced-x86=9 + glDrawArrays; + glDrawElements; + glDrawTexfOES; + glDrawTexfvOES; + glDrawTexiOES; + glDrawTexivOES; + glDrawTexsOES; + glDrawTexsvOES; + glDrawTexxOES; + glDrawTexxvOES; + glEGLImageTargetRenderbufferStorageOES; + glEGLImageTargetTexture2DOES; + glEnable; + glEnableClientState; + glEnableDriverControlQCOM; # introduced-mips=9 introduced-x86=9 + glEndTilingQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetBufferPointervQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetBuffersQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetFramebuffersQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetProgramBinarySourceQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetProgramsQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetRenderbuffersQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetShadersQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetTexLevelParameterivQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetTexSubImageQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetTexturesQCOM; # introduced-mips=9 introduced-x86=9 + glExtIsProgramBinaryQCOM; # introduced-mips=9 introduced-x86=9 + glExtTexObjectStateOverrideiQCOM; # introduced-mips=9 introduced-x86=9 + glFinish; + glFinishFenceNV; # introduced-mips=9 introduced-x86=9 + glFlush; + glFogf; + glFogfv; + glFogx; + glFogxOES; + glFogxv; + glFogxvOES; + glFramebufferRenderbufferOES; + glFramebufferTexture2DMultisampleIMG; # introduced-mips=9 introduced-x86=9 + glFramebufferTexture2DOES; + glFrontFace; + glFrustumf; + glFrustumfOES; + glFrustumx; + glFrustumxOES; + glGenBuffers; + glGenFencesNV; # introduced-mips=9 introduced-x86=9 + glGenFramebuffersOES; + glGenRenderbuffersOES; + glGenTextures; + glGenVertexArraysOES; # introduced-mips=9 introduced-x86=9 + glGenerateMipmapOES; + glGetBooleanv; + glGetBufferParameteriv; + glGetBufferPointervOES; + glGetClipPlanef; + glGetClipPlanefOES; + glGetClipPlanex; + glGetClipPlanexOES; + glGetDriverControlStringQCOM; # introduced-mips=9 introduced-x86=9 + glGetDriverControlsQCOM; # introduced-mips=9 introduced-x86=9 + glGetError; + glGetFenceivNV; # introduced-mips=9 introduced-x86=9 + glGetFixedv; + glGetFixedvOES; + glGetFloatv; + glGetFramebufferAttachmentParameterivOES; + glGetIntegerv; + glGetLightfv; + glGetLightxv; + glGetLightxvOES; + glGetMaterialfv; + glGetMaterialxv; + glGetMaterialxvOES; + glGetPointerv; + glGetRenderbufferParameterivOES; + glGetString; + glGetTexEnvfv; + glGetTexEnviv; + glGetTexEnvxv; + glGetTexEnvxvOES; + glGetTexGenfvOES; + glGetTexGenivOES; + glGetTexGenxvOES; + glGetTexParameterfv; + glGetTexParameteriv; + glGetTexParameterxv; + glGetTexParameterxvOES; + glHint; + glIsBuffer; + glIsEnabled; + glIsFenceNV; # introduced-mips=9 introduced-x86=9 + glIsFramebufferOES; + glIsRenderbufferOES; + glIsTexture; + glIsVertexArrayOES; # introduced-mips=9 introduced-x86=9 + glLightModelf; + glLightModelfv; + glLightModelx; + glLightModelxOES; + glLightModelxv; + glLightModelxvOES; + glLightf; + glLightfv; + glLightx; + glLightxOES; + glLightxv; + glLightxvOES; + glLineWidth; + glLineWidthx; + glLineWidthxOES; + glLoadIdentity; + glLoadMatrixf; + glLoadMatrixx; + glLoadMatrixxOES; + glLoadPaletteFromModelViewMatrixOES; + glLogicOp; + glMapBufferOES; + glMaterialf; + glMaterialfv; + glMaterialx; + glMaterialxOES; + glMaterialxv; + glMaterialxvOES; + glMatrixIndexPointerOES; + glMatrixIndexPointerOESBounds; # introduced-mips=9 introduced-x86=9 + glMatrixMode; + glMultMatrixf; + glMultMatrixx; + glMultMatrixxOES; + glMultiDrawArraysEXT; # introduced-mips=9 introduced-x86=9 + glMultiDrawElementsEXT; # introduced-mips=9 introduced-x86=9 + glMultiTexCoord4f; + glMultiTexCoord4x; + glMultiTexCoord4xOES; + glNormal3f; + glNormal3x; + glNormal3xOES; + glNormalPointer; + glNormalPointerBounds; + glOrthof; + glOrthofOES; + glOrthox; + glOrthoxOES; + glPixelStorei; + glPointParameterf; + glPointParameterfv; + glPointParameterx; + glPointParameterxOES; + glPointParameterxv; + glPointParameterxvOES; + glPointSize; + glPointSizePointerOES; + glPointSizePointerOESBounds; # introduced-mips=9 introduced-x86=9 + glPointSizex; + glPointSizexOES; + glPolygonOffset; + glPolygonOffsetx; + glPolygonOffsetxOES; + glPopMatrix; + glPushMatrix; + glQueryMatrixxOES; + glReadPixels; + glRenderbufferStorageMultisampleIMG; # introduced-mips=9 introduced-x86=9 + glRenderbufferStorageOES; + glRotatef; + glRotatex; + glRotatexOES; + glSampleCoverage; + glSampleCoveragex; + glSampleCoveragexOES; + glScalef; + glScalex; + glScalexOES; + glScissor; + glSetFenceNV; # introduced-mips=9 introduced-x86=9 + glShadeModel; + glStartTilingQCOM; # introduced-mips=9 introduced-x86=9 + glStencilFunc; + glStencilMask; + glStencilOp; + glTestFenceNV; # introduced-mips=9 introduced-x86=9 + glTexCoordPointer; + glTexCoordPointerBounds; + glTexEnvf; + glTexEnvfv; + glTexEnvi; + glTexEnviv; + glTexEnvx; + glTexEnvxOES; + glTexEnvxv; + glTexEnvxvOES; + glTexGenfOES; + glTexGenfvOES; + glTexGeniOES; + glTexGenivOES; + glTexGenxOES; + glTexGenxvOES; + glTexImage2D; + glTexParameterf; + glTexParameterfv; + glTexParameteri; + glTexParameteriv; + glTexParameterx; + glTexParameterxOES; + glTexParameterxv; + glTexParameterxvOES; + glTexSubImage2D; + glTranslatef; + glTranslatex; + glTranslatexOES; + glUnmapBufferOES; + glVertexPointer; + glVertexPointerBounds; + glViewport; + glWeightPointerOES; + glWeightPointerOESBounds; # introduced-mips=9 introduced-x86=9 + local: + *; +}; diff --git a/opengl/libs/libGLESv2.map.txt b/opengl/libs/libGLESv2.map.txt new file mode 100644 index 0000000000..1b0042aef5 --- /dev/null +++ b/opengl/libs/libGLESv2.map.txt @@ -0,0 +1,207 @@ +LIBGLESV2 { + global: + glActiveTexture; + glAttachShader; + glBeginPerfMonitorAMD; + glBindAttribLocation; + glBindBuffer; + glBindFramebuffer; + glBindRenderbuffer; + glBindTexture; + glBindVertexArrayOES; # introduced-mips=9 introduced-x86=9 + glBlendColor; + glBlendEquation; + glBlendEquationSeparate; + glBlendFunc; + glBlendFuncSeparate; + glBufferData; + glBufferSubData; + glCheckFramebufferStatus; + glClear; + glClearColor; + glClearDepthf; + glClearStencil; + glColorMask; + glCompileShader; + glCompressedTexImage2D; + glCompressedTexImage3DOES; + glCompressedTexSubImage2D; + glCompressedTexSubImage3DOES; + glCopyTexImage2D; + glCopyTexSubImage2D; + glCopyTexSubImage3DOES; + glCoverageMaskNV; # introduced-mips=9 introduced-x86=9 + glCoverageOperationNV; # introduced-mips=9 introduced-x86=9 + glCreateProgram; + glCreateShader; + glCullFace; + glDeleteBuffers; + glDeleteFencesNV; + glDeleteFramebuffers; + glDeletePerfMonitorsAMD; + glDeleteProgram; + glDeleteRenderbuffers; + glDeleteShader; + glDeleteTextures; + glDeleteVertexArraysOES; # introduced-mips=9 introduced-x86=9 + glDepthFunc; + glDepthMask; + glDepthRangef; + glDetachShader; + glDisable; + glDisableDriverControlQCOM; + glDisableVertexAttribArray; + glDiscardFramebufferEXT; # introduced-mips=9 introduced-x86=9 + glDrawArrays; + glDrawElements; + glEGLImageTargetRenderbufferStorageOES; + glEGLImageTargetTexture2DOES; + glEnable; + glEnableDriverControlQCOM; + glEnableVertexAttribArray; + glEndPerfMonitorAMD; + glEndTilingQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetBufferPointervQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetBuffersQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetFramebuffersQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetProgramBinarySourceQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetProgramsQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetRenderbuffersQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetShadersQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetTexLevelParameterivQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetTexSubImageQCOM; # introduced-mips=9 introduced-x86=9 + glExtGetTexturesQCOM; # introduced-mips=9 introduced-x86=9 + glExtIsProgramBinaryQCOM; # introduced-mips=9 introduced-x86=9 + glExtTexObjectStateOverrideiQCOM; # introduced-mips=9 introduced-x86=9 + glFinish; + glFinishFenceNV; + glFlush; + glFramebufferRenderbuffer; + glFramebufferTexture2D; + glFramebufferTexture2DMultisampleIMG; # introduced-mips=9 introduced-x86=9 + glFramebufferTexture3DOES; + glFrontFace; + glGenBuffers; + glGenFencesNV; + glGenFramebuffers; + glGenPerfMonitorsAMD; + glGenRenderbuffers; + glGenTextures; + glGenVertexArraysOES; # introduced-mips=9 introduced-x86=9 + glGenerateMipmap; + glGetActiveAttrib; + glGetActiveUniform; + glGetAttachedShaders; + glGetAttribLocation; + glGetBooleanv; + glGetBufferParameteriv; + glGetBufferPointervOES; + glGetDriverControlStringQCOM; + glGetDriverControlsQCOM; + glGetError; + glGetFenceivNV; + glGetFloatv; + glGetFramebufferAttachmentParameteriv; + glGetIntegerv; + glGetPerfMonitorCounterDataAMD; + glGetPerfMonitorCounterInfoAMD; + glGetPerfMonitorCounterStringAMD; + glGetPerfMonitorCountersAMD; + glGetPerfMonitorGroupStringAMD; + glGetPerfMonitorGroupsAMD; + glGetProgramBinaryOES; + glGetProgramInfoLog; + glGetProgramiv; + glGetRenderbufferParameteriv; + glGetShaderInfoLog; + glGetShaderPrecisionFormat; + glGetShaderSource; + glGetShaderiv; + glGetString; + glGetTexParameterfv; + glGetTexParameteriv; + glGetUniformLocation; + glGetUniformfv; + glGetUniformiv; + glGetVertexAttribPointerv; + glGetVertexAttribfv; + glGetVertexAttribiv; + glHint; + glIsBuffer; + glIsEnabled; + glIsFenceNV; + glIsFramebuffer; + glIsProgram; + glIsRenderbuffer; + glIsShader; + glIsTexture; + glIsVertexArrayOES; # introduced-mips=9 introduced-x86=9 + glLineWidth; + glLinkProgram; + glMapBufferOES; + glMultiDrawArraysEXT; # introduced-mips=9 introduced-x86=9 + glMultiDrawElementsEXT; # introduced-mips=9 introduced-x86=9 + glPixelStorei; + glPolygonOffset; + glProgramBinaryOES; + glReadPixels; + glReleaseShaderCompiler; + glRenderbufferStorage; + glRenderbufferStorageMultisampleIMG; # introduced-mips=9 introduced-x86=9 + glSampleCoverage; + glScissor; + glSelectPerfMonitorCountersAMD; + glSetFenceNV; + glShaderBinary; + glShaderSource; + glStartTilingQCOM; # introduced-mips=9 introduced-x86=9 + glStencilFunc; + glStencilFuncSeparate; + glStencilMask; + glStencilMaskSeparate; + glStencilOp; + glStencilOpSeparate; + glTestFenceNV; + glTexImage2D; + glTexImage3DOES; + glTexParameterf; + glTexParameterfv; + glTexParameteri; + glTexParameteriv; + glTexSubImage2D; + glTexSubImage3DOES; + glUniform1f; + glUniform1fv; + glUniform1i; + glUniform1iv; + glUniform2f; + glUniform2fv; + glUniform2i; + glUniform2iv; + glUniform3f; + glUniform3fv; + glUniform3i; + glUniform3iv; + glUniform4f; + glUniform4fv; + glUniform4i; + glUniform4iv; + glUniformMatrix2fv; + glUniformMatrix3fv; + glUniformMatrix4fv; + glUnmapBufferOES; + glUseProgram; + glValidateProgram; + glVertexAttrib1f; + glVertexAttrib1fv; + glVertexAttrib2f; + glVertexAttrib2fv; + glVertexAttrib3f; + glVertexAttrib3fv; + glVertexAttrib4f; + glVertexAttrib4fv; + glVertexAttribPointer; + glViewport; + local: + *; +}; diff --git a/opengl/libs/libGLESv3.map.txt b/opengl/libs/libGLESv3.map.txt new file mode 100644 index 0000000000..21f6cb665e --- /dev/null +++ b/opengl/libs/libGLESv3.map.txt @@ -0,0 +1,416 @@ +LIBGLESV3 { + global: + glActiveShaderProgram; # introduced=21 + glActiveTexture; + glAttachShader; + glBeginQuery; + glBeginTransformFeedback; + glBindAttribLocation; + glBindBuffer; + glBindBufferBase; + glBindBufferRange; + glBindFramebuffer; + glBindImageTexture; # introduced=21 + glBindProgramPipeline; # introduced=21 + glBindRenderbuffer; + glBindSampler; + glBindTexture; + glBindTransformFeedback; + glBindVertexArray; + glBindVertexArrayOES; + glBindVertexBuffer; # introduced=21 + glBlendBarrier; # introduced=24 + glBlendBarrierKHR; # introduced=21 + glBlendColor; + glBlendEquation; + glBlendEquationSeparate; + glBlendEquationSeparatei; # introduced=24 + glBlendEquationSeparateiEXT; # introduced=21 + glBlendEquationi; # introduced=24 + glBlendEquationiEXT; # introduced=21 + glBlendFunc; + glBlendFuncSeparate; + glBlendFuncSeparatei; # introduced=24 + glBlendFuncSeparateiEXT; # introduced=21 + glBlendFunci; # introduced=24 + glBlendFunciEXT; # introduced=21 + glBlitFramebuffer; + glBufferData; + glBufferSubData; + glCheckFramebufferStatus; + glClear; + glClearBufferfi; + glClearBufferfv; + glClearBufferiv; + glClearBufferuiv; + glClearColor; + glClearDepthf; + glClearStencil; + glClientWaitSync; + glColorMask; + glColorMaski; # introduced=24 + glColorMaskiEXT; # introduced=21 + glCompileShader; + glCompressedTexImage2D; + glCompressedTexImage3D; + glCompressedTexImage3DOES; + glCompressedTexSubImage2D; + glCompressedTexSubImage3D; + glCompressedTexSubImage3DOES; + glCopyBufferSubData; + glCopyImageSubData; # introduced=24 + glCopyImageSubDataEXT; # introduced=21 + glCopyTexImage2D; + glCopyTexSubImage2D; + glCopyTexSubImage3D; + glCopyTexSubImage3DOES; + glCreateProgram; + glCreateShader; + glCreateShaderProgramv; # introduced=21 + glCullFace; + glDebugMessageCallback; # introduced=24 + glDebugMessageCallbackKHR; # introduced=21 + glDebugMessageControl; # introduced=24 + glDebugMessageControlKHR; # introduced=21 + glDebugMessageInsert; # introduced=24 + glDebugMessageInsertKHR; # introduced=21 + glDeleteBuffers; + glDeleteFramebuffers; + glDeleteProgram; + glDeleteProgramPipelines; # introduced=21 + glDeleteQueries; + glDeleteRenderbuffers; + glDeleteSamplers; + glDeleteShader; + glDeleteSync; + glDeleteTextures; + glDeleteTransformFeedbacks; + glDeleteVertexArrays; + glDeleteVertexArraysOES; + glDepthFunc; + glDepthMask; + glDepthRangef; + glDetachShader; + glDisable; + glDisableVertexAttribArray; + glDisablei; # introduced=24 + glDisableiEXT; # introduced=21 + glDispatchCompute; # introduced=21 + glDispatchComputeIndirect; # introduced=21 + glDrawArrays; + glDrawArraysIndirect; # introduced=21 + glDrawArraysInstanced; + glDrawBuffers; + glDrawElements; + glDrawElementsBaseVertex; # introduced=24 + glDrawElementsIndirect; # introduced=21 + glDrawElementsInstanced; + glDrawElementsInstancedBaseVertex; # introduced=24 + glDrawRangeElements; + glDrawRangeElementsBaseVertex; # introduced=24 + glEGLImageTargetRenderbufferStorageOES; + glEGLImageTargetTexture2DOES; + glEnable; + glEnableVertexAttribArray; + glEnablei; # introduced=24 + glEnableiEXT; # introduced=21 + glEndQuery; + glEndTransformFeedback; + glFenceSync; + glFinish; + glFlush; + glFlushMappedBufferRange; + glFramebufferParameteri; # introduced=21 + glFramebufferRenderbuffer; + glFramebufferTexture; # introduced=24 + glFramebufferTexture2D; + glFramebufferTexture3DOES; + glFramebufferTextureEXT; # introduced=21 + glFramebufferTextureLayer; + glFrontFace; + glGenBuffers; + glGenFramebuffers; + glGenProgramPipelines; # introduced=21 + glGenQueries; + glGenRenderbuffers; + glGenSamplers; + glGenTextures; + glGenTransformFeedbacks; + glGenVertexArrays; + glGenVertexArraysOES; + glGenerateMipmap; + glGetActiveAttrib; + glGetActiveUniform; + glGetActiveUniformBlockName; + glGetActiveUniformBlockiv; + glGetActiveUniformsiv; + glGetAttachedShaders; + glGetAttribLocation; + glGetBooleani_v; # introduced=21 + glGetBooleanv; + glGetBufferParameteri64v; + glGetBufferParameteriv; + glGetBufferPointerv; + glGetBufferPointervOES; + glGetDebugMessageLog; # introduced=24 + glGetDebugMessageLogKHR; # introduced=21 + glGetError; + glGetFloatv; + glGetFragDataLocation; + glGetFramebufferAttachmentParameteriv; + glGetFramebufferParameteriv; # introduced=21 + glGetGraphicsResetStatus; # introduced=24 + glGetInteger64i_v; + glGetInteger64v; + glGetIntegeri_v; + glGetIntegerv; + glGetInternalformativ; + glGetMultisamplefv; # introduced=21 + glGetObjectLabel; # introduced=24 + glGetObjectLabelKHR; # introduced=21 + glGetObjectPtrLabel; # introduced=24 + glGetObjectPtrLabelKHR; # introduced=21 + glGetPointerv; # introduced=24 + glGetPointervKHR; # introduced=21 + glGetProgramBinary; + glGetProgramBinaryOES; + glGetProgramInfoLog; + glGetProgramInterfaceiv; # introduced=21 + glGetProgramPipelineInfoLog; # introduced=21 + glGetProgramPipelineiv; # introduced=21 + glGetProgramResourceIndex; # introduced=21 + glGetProgramResourceLocation; # introduced=21 + glGetProgramResourceName; # introduced=21 + glGetProgramResourceiv; # introduced=21 + glGetProgramiv; + glGetQueryObjectuiv; + glGetQueryiv; + glGetRenderbufferParameteriv; + glGetSamplerParameterIiv; # introduced=24 + glGetSamplerParameterIivEXT; # introduced=21 + glGetSamplerParameterIuiv; # introduced=24 + glGetSamplerParameterIuivEXT; # introduced=21 + glGetSamplerParameterfv; + glGetSamplerParameteriv; + glGetShaderInfoLog; + glGetShaderPrecisionFormat; + glGetShaderSource; + glGetShaderiv; + glGetString; + glGetStringi; + glGetSynciv; + glGetTexLevelParameterfv; # introduced=21 + glGetTexLevelParameteriv; # introduced=21 + glGetTexParameterIiv; # introduced=24 + glGetTexParameterIivEXT; # introduced=21 + glGetTexParameterIuiv; # introduced=24 + glGetTexParameterIuivEXT; # introduced=21 + glGetTexParameterfv; + glGetTexParameteriv; + glGetTransformFeedbackVarying; + glGetUniformBlockIndex; + glGetUniformIndices; + glGetUniformLocation; + glGetUniformfv; + glGetUniformiv; + glGetUniformuiv; + glGetVertexAttribIiv; + glGetVertexAttribIuiv; + glGetVertexAttribPointerv; + glGetVertexAttribfv; + glGetVertexAttribiv; + glGetnUniformfv; # introduced=24 + glGetnUniformiv; # introduced=24 + glGetnUniformuiv; # introduced=24 + glHint; + glInvalidateFramebuffer; + glInvalidateSubFramebuffer; + glIsBuffer; + glIsEnabled; + glIsEnabledi; # introduced=24 + glIsEnablediEXT; # introduced=21 + glIsFramebuffer; + glIsProgram; + glIsProgramPipeline; # introduced=21 + glIsQuery; + glIsRenderbuffer; + glIsSampler; + glIsShader; + glIsSync; + glIsTexture; + glIsTransformFeedback; + glIsVertexArray; + glIsVertexArrayOES; + glLineWidth; + glLinkProgram; + glMapBufferOES; + glMapBufferRange; + glMemoryBarrier; # introduced=21 + glMemoryBarrierByRegion; # introduced=21 + glMinSampleShading; # introduced=24 + glMinSampleShadingOES; # introduced=21 + glObjectLabel; # introduced=24 + glObjectLabelKHR; # introduced=21 + glObjectPtrLabel; # introduced=24 + glObjectPtrLabelKHR; # introduced=21 + glPatchParameteri; # introduced=24 + glPatchParameteriEXT; # introduced=21 + glPauseTransformFeedback; + glPixelStorei; + glPolygonOffset; + glPopDebugGroup; # introduced=24 + glPopDebugGroupKHR; # introduced=21 + glPrimitiveBoundingBox; # introduced=24 + glPrimitiveBoundingBoxEXT; # introduced=21 + glProgramBinary; + glProgramBinaryOES; + glProgramParameteri; + glProgramUniform1f; # introduced=21 + glProgramUniform1fv; # introduced=21 + glProgramUniform1i; # introduced=21 + glProgramUniform1iv; # introduced=21 + glProgramUniform1ui; # introduced=21 + glProgramUniform1uiv; # introduced=21 + glProgramUniform2f; # introduced=21 + glProgramUniform2fv; # introduced=21 + glProgramUniform2i; # introduced=21 + glProgramUniform2iv; # introduced=21 + glProgramUniform2ui; # introduced=21 + glProgramUniform2uiv; # introduced=21 + glProgramUniform3f; # introduced=21 + glProgramUniform3fv; # introduced=21 + glProgramUniform3i; # introduced=21 + glProgramUniform3iv; # introduced=21 + glProgramUniform3ui; # introduced=21 + glProgramUniform3uiv; # introduced=21 + glProgramUniform4f; # introduced=21 + glProgramUniform4fv; # introduced=21 + glProgramUniform4i; # introduced=21 + glProgramUniform4iv; # introduced=21 + glProgramUniform4ui; # introduced=21 + glProgramUniform4uiv; # introduced=21 + glProgramUniformMatrix2fv; # introduced=21 + glProgramUniformMatrix2x3fv; # introduced=21 + glProgramUniformMatrix2x4fv; # introduced=21 + glProgramUniformMatrix3fv; # introduced=21 + glProgramUniformMatrix3x2fv; # introduced=21 + glProgramUniformMatrix3x4fv; # introduced=21 + glProgramUniformMatrix4fv; # introduced=21 + glProgramUniformMatrix4x2fv; # introduced=21 + glProgramUniformMatrix4x3fv; # introduced=21 + glPushDebugGroup; # introduced=24 + glPushDebugGroupKHR; # introduced=21 + glReadBuffer; + glReadPixels; + glReadnPixels; # introduced=24 + glReleaseShaderCompiler; + glRenderbufferStorage; + glRenderbufferStorageMultisample; + glResumeTransformFeedback; + glSampleCoverage; + glSampleMaski; # introduced=21 + glSamplerParameterIiv; # introduced=24 + glSamplerParameterIivEXT; # introduced=21 + glSamplerParameterIuiv; # introduced=24 + glSamplerParameterIuivEXT; # introduced=21 + glSamplerParameterf; + glSamplerParameterfv; + glSamplerParameteri; + glSamplerParameteriv; + glScissor; + glShaderBinary; + glShaderSource; + glStencilFunc; + glStencilFuncSeparate; + glStencilMask; + glStencilMaskSeparate; + glStencilOp; + glStencilOpSeparate; + glTexBuffer; # introduced=24 + glTexBufferEXT; # introduced=21 + glTexBufferRange; # introduced=24 + glTexBufferRangeEXT; # introduced=21 + glTexImage2D; + glTexImage3D; + glTexImage3DOES; + glTexParameterIiv; # introduced=24 + glTexParameterIivEXT; # introduced=21 + glTexParameterIuiv; # introduced=24 + glTexParameterIuivEXT; # introduced=21 + glTexParameterf; + glTexParameterfv; + glTexParameteri; + glTexParameteriv; + glTexStorage2D; + glTexStorage2DMultisample; # introduced=21 + glTexStorage3D; + glTexStorage3DMultisample; # introduced=24 + glTexStorage3DMultisampleOES; # introduced=21 + glTexSubImage2D; + glTexSubImage3D; + glTexSubImage3DOES; + glTransformFeedbackVaryings; + glUniform1f; + glUniform1fv; + glUniform1i; + glUniform1iv; + glUniform1ui; + glUniform1uiv; + glUniform2f; + glUniform2fv; + glUniform2i; + glUniform2iv; + glUniform2ui; + glUniform2uiv; + glUniform3f; + glUniform3fv; + glUniform3i; + glUniform3iv; + glUniform3ui; + glUniform3uiv; + glUniform4f; + glUniform4fv; + glUniform4i; + glUniform4iv; + glUniform4ui; + glUniform4uiv; + glUniformBlockBinding; + glUniformMatrix2fv; + glUniformMatrix2x3fv; + glUniformMatrix2x4fv; + glUniformMatrix3fv; + glUniformMatrix3x2fv; + glUniformMatrix3x4fv; + glUniformMatrix4fv; + glUniformMatrix4x2fv; + glUniformMatrix4x3fv; + glUnmapBuffer; + glUnmapBufferOES; + glUseProgram; + glUseProgramStages; # introduced=21 + glValidateProgram; + glValidateProgramPipeline; # introduced=21 + glVertexAttrib1f; + glVertexAttrib1fv; + glVertexAttrib2f; + glVertexAttrib2fv; + glVertexAttrib3f; + glVertexAttrib3fv; + glVertexAttrib4f; + glVertexAttrib4fv; + glVertexAttribBinding; # introduced=21 + glVertexAttribDivisor; + glVertexAttribFormat; # introduced=21 + glVertexAttribI4i; + glVertexAttribI4iv; + glVertexAttribI4ui; + glVertexAttribI4uiv; + glVertexAttribIFormat; # introduced=21 + glVertexAttribIPointer; + glVertexAttribPointer; + glVertexBindingDivisor; # introduced=21 + glViewport; + glWaitSync; + local: + *; +}; diff --git a/opengl/tests/angeles/demo.c b/opengl/tests/angeles/demo.c index 802f3980fa..39d871e968 100644 --- a/opengl/tests/angeles/demo.c +++ b/opengl/tests/angeles/demo.c @@ -666,7 +666,7 @@ static void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, y[2] /= mag; } -#define M(row,col) m[col*4+row] +#define M(row,col) m[(col)*4+(row)] M(0, 0) = x[0]; M(0, 1) = x[1]; M(0, 2) = x[2]; diff --git a/opengl/tests/hwc/hwcColorEquiv.cpp b/opengl/tests/hwc/hwcColorEquiv.cpp index f1361b8c43..a9bbcb6f5f 100644 --- a/opengl/tests/hwc/hwcColorEquiv.cpp +++ b/opengl/tests/hwc/hwcColorEquiv.cpp @@ -116,7 +116,7 @@ const float defaultEndDelay = 2.0; // Default delay after rendering graphics #define CMD_START_FRAMEWORK "start 2>&1" // Macros -#define NUMA(a) (sizeof(a) / sizeof(a [0])) // Num elements in an array +#define NUMA(a) (sizeof(a) / sizeof((a)[0])) // Num elements in an array #define MEMCLR(addr, size) do { \ memset((addr), 0, (size)); \ } while (0) diff --git a/opengl/tests/hwc/hwcCommit.cpp b/opengl/tests/hwc/hwcCommit.cpp index 6b287e9126..3686dab654 100644 --- a/opengl/tests/hwc/hwcCommit.cpp +++ b/opengl/tests/hwc/hwcCommit.cpp @@ -156,12 +156,12 @@ const struct blendType { #define CMD_START_FRAMEWORK "start 2>&1" // Macros -#define NUMA(a) (sizeof(a) / sizeof(a [0])) // Num elements in an array +#define NUMA(a) (sizeof(a) / sizeof((a)[0])) // Num elements in an array // Local types class Rectangle { public: - Rectangle(uint32_t graphicFormat = defaultFormat, + explicit Rectangle(uint32_t graphicFormat = defaultFormat, HwcTestDim dfDim = HwcTestDim(1, 1), HwcTestDim sDim = HwcTestDim(1, 1)); void setSourceDim(HwcTestDim dim); diff --git a/opengl/tests/hwc/hwcRects.cpp b/opengl/tests/hwc/hwcRects.cpp index 2e2b204b4d..69e56ff59b 100644 --- a/opengl/tests/hwc/hwcRects.cpp +++ b/opengl/tests/hwc/hwcRects.cpp @@ -137,7 +137,7 @@ const struct hwc_rect defaultDisplayFrame = {0, 0, 100, 100}; #define CMD_START_FRAMEWORK "start 2>&1" // Macros -#define NUMA(a) (sizeof(a) / sizeof(a [0])) // Num elements in an array +#define NUMA(a) (sizeof(a) / sizeof((a)[0])) // Num elements in an array // Local types class Rectangle { diff --git a/opengl/tests/hwc/hwcStress.cpp b/opengl/tests/hwc/hwcStress.cpp index 60c29efa4c..1469f7c76d 100644 --- a/opengl/tests/hwc/hwcStress.cpp +++ b/opengl/tests/hwc/hwcStress.cpp @@ -162,7 +162,7 @@ bool eFlag, sFlag, pFlag; #define CMD_STOP_FRAMEWORK "stop 2>&1" #define CMD_START_FRAMEWORK "start 2>&1" -#define NUMA(a) (sizeof(a) / sizeof(a [0])) +#define NUMA(a) (sizeof(a) / sizeof((a)[0])) #define MEMCLR(addr, size) do { \ memset((addr), 0, (size)); \ } while (0) diff --git a/opengl/tests/hwc/hwcTestLib.h b/opengl/tests/hwc/hwcTestLib.h index a942c10e34..922fc1990b 100644 --- a/opengl/tests/hwc/hwcTestLib.h +++ b/opengl/tests/hwc/hwcTestLib.h @@ -71,7 +71,7 @@ class ColorFract { class ColorRGB { public: ColorRGB(): _r(0.0), _g(0.0), _b(0.0) {}; - ColorRGB(float f): _r(f), _g(f), _b(f) {}; // Gray + ColorRGB(float f): _r(f), _g(f), _b(f) {}; // Gray, NOLINT(implicit) ColorRGB(float r, float g, float b): _r(r), _g(g), _b(b) {}; float r(void) const { return _r; } float g(void) const { return _g; } diff --git a/services/batteryservice/Android.bp b/services/batteryservice/Android.bp new file mode 100644 index 0000000000..79db871d4e --- /dev/null +++ b/services/batteryservice/Android.bp @@ -0,0 +1,22 @@ +cc_library_static { + name: "libbatteryservice", + + srcs: [ + "BatteryProperties.cpp", + "BatteryProperty.cpp", + "IBatteryPropertiesListener.cpp", + "IBatteryPropertiesRegistrar.cpp", + ], + + static_libs: [ + "libutils", + "libbinder", + ], + + cflags: [ + "-Wall", + "-Werror", + "-Wunused", + "-Wunreachable-code", + ], +} diff --git a/services/batteryservice/Android.mk b/services/batteryservice/Android.mk deleted file mode 100644 index e4097d7104..0000000000 --- a/services/batteryservice/Android.mk +++ /dev/null @@ -1,20 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= \ - BatteryProperties.cpp \ - BatteryProperty.cpp \ - IBatteryPropertiesListener.cpp \ - IBatteryPropertiesRegistrar.cpp - -LOCAL_STATIC_LIBRARIES := \ - libutils \ - libbinder - -LOCAL_MODULE:= libbatteryservice - -LOCAL_MODULE_TAGS := optional - -LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code - -include $(BUILD_STATIC_LIBRARY) diff --git a/services/batteryservice/IBatteryPropertiesListener.cpp b/services/batteryservice/IBatteryPropertiesListener.cpp index 8aff26c4c8..7555f4b7c8 100644 --- a/services/batteryservice/IBatteryPropertiesListener.cpp +++ b/services/batteryservice/IBatteryPropertiesListener.cpp @@ -24,7 +24,7 @@ namespace android { class BpBatteryPropertiesListener : public BpInterface<IBatteryPropertiesListener> { public: - BpBatteryPropertiesListener(const sp<IBinder>& impl) + explicit BpBatteryPropertiesListener(const sp<IBinder>& impl) : BpInterface<IBatteryPropertiesListener>(impl) { } diff --git a/services/batteryservice/IBatteryPropertiesRegistrar.cpp b/services/batteryservice/IBatteryPropertiesRegistrar.cpp index 46934e04e1..1fdda4362d 100644 --- a/services/batteryservice/IBatteryPropertiesRegistrar.cpp +++ b/services/batteryservice/IBatteryPropertiesRegistrar.cpp @@ -28,7 +28,7 @@ namespace android { class BpBatteryPropertiesRegistrar : public BpInterface<IBatteryPropertiesRegistrar> { public: - BpBatteryPropertiesRegistrar(const sp<IBinder>& impl) + explicit BpBatteryPropertiesRegistrar(const sp<IBinder>& impl) : BpInterface<IBatteryPropertiesRegistrar>(impl) {} void registerListener(const sp<IBatteryPropertiesListener>& listener) { diff --git a/services/inputflinger/EventHub.cpp b/services/inputflinger/EventHub.cpp index 2a53dec416..d2f89959e1 100644 --- a/services/inputflinger/EventHub.cpp +++ b/services/inputflinger/EventHub.cpp @@ -55,10 +55,10 @@ * operation with a byte that only has the relevant bit set. * eg. to check for the 12th bit, we do (array[1] & 1<<4) */ -#define test_bit(bit, array) (array[bit/8] & (1<<(bit%8))) +#define test_bit(bit, array) ((array)[(bit)/8] & (1<<((bit)%8))) /* this macro computes the number of bytes needed to represent a bit array of the specified size */ -#define sizeof_bit_array(bits) ((bits + 7) / 8) +#define sizeof_bit_array(bits) (((bits) + 7) / 8) #define INDENT " " #define INDENT2 " " diff --git a/services/inputflinger/InputDispatcher.h b/services/inputflinger/InputDispatcher.h index 1c054f5ce0..90c69ce581 100644 --- a/services/inputflinger/InputDispatcher.h +++ b/services/inputflinger/InputDispatcher.h @@ -455,7 +455,7 @@ private: }; struct ConfigurationChangedEntry : EventEntry { - ConfigurationChangedEntry(nsecs_t eventTime); + explicit ConfigurationChangedEntry(nsecs_t eventTime); virtual void appendDescription(String8& msg) const; protected: @@ -591,7 +591,7 @@ private: class Connection; struct CommandEntry : Link<CommandEntry> { - CommandEntry(Command command); + explicit CommandEntry(Command command); ~CommandEntry(); Command command; diff --git a/services/inputflinger/InputListener.h b/services/inputflinger/InputListener.h index 1ec09ce4b5..ea3dd1caac 100644 --- a/services/inputflinger/InputListener.h +++ b/services/inputflinger/InputListener.h @@ -40,7 +40,7 @@ struct NotifyConfigurationChangedArgs : public NotifyArgs { inline NotifyConfigurationChangedArgs() { } - NotifyConfigurationChangedArgs(nsecs_t eventTime); + explicit NotifyConfigurationChangedArgs(nsecs_t eventTime); NotifyConfigurationChangedArgs(const NotifyConfigurationChangedArgs& other); @@ -178,7 +178,7 @@ protected: virtual ~QueuedInputListener(); public: - QueuedInputListener(const sp<InputListenerInterface>& innerListener); + explicit QueuedInputListener(const sp<InputListenerInterface>& innerListener); virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args); virtual void notifyKey(const NotifyKeyArgs* args); diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index b9be675686..4dec34bc93 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -6652,6 +6652,7 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { size_t inCount = mMultiTouchMotionAccumulator.getSlotCount(); size_t outCount = 0; BitSet32 newPointerIdBits; + mHavePointerIds = true; for (size_t inIndex = 0; inIndex < inCount; inIndex++) { const MultiTouchMotionAccumulator::Slot* inSlot = @@ -6696,33 +6697,33 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { outPointer.isHovering = isHovering; // Assign pointer id using tracking id if available. - mHavePointerIds = true; - int32_t trackingId = inSlot->getTrackingId(); - int32_t id = -1; - if (trackingId >= 0) { - for (BitSet32 idBits(mPointerIdBits); !idBits.isEmpty(); ) { - uint32_t n = idBits.clearFirstMarkedBit(); - if (mPointerTrackingIdMap[n] == trackingId) { - id = n; + if (mHavePointerIds) { + int32_t trackingId = inSlot->getTrackingId(); + int32_t id = -1; + if (trackingId >= 0) { + for (BitSet32 idBits(mPointerIdBits); !idBits.isEmpty(); ) { + uint32_t n = idBits.clearFirstMarkedBit(); + if (mPointerTrackingIdMap[n] == trackingId) { + id = n; + } } - } - if (id < 0 && !mPointerIdBits.isFull()) { - id = mPointerIdBits.markFirstUnmarkedBit(); - mPointerTrackingIdMap[id] = trackingId; + if (id < 0 && !mPointerIdBits.isFull()) { + id = mPointerIdBits.markFirstUnmarkedBit(); + mPointerTrackingIdMap[id] = trackingId; + } + } + if (id < 0) { + mHavePointerIds = false; + outState->rawPointerData.clearIdBits(); + newPointerIdBits.clear(); + } else { + outPointer.id = id; + outState->rawPointerData.idToIndex[id] = outCount; + outState->rawPointerData.markIdBit(id, isHovering); + newPointerIdBits.markBit(id); } } - if (id < 0) { - mHavePointerIds = false; - outState->rawPointerData.clearIdBits(); - newPointerIdBits.clear(); - } else { - outPointer.id = id; - outState->rawPointerData.idToIndex[id] = outCount; - outState->rawPointerData.markIdBit(id, isHovering); - newPointerIdBits.markBit(id); - } - outCount += 1; } diff --git a/services/inputflinger/InputReader.h b/services/inputflinger/InputReader.h index 076f3d651f..8e2fe95c06 100644 --- a/services/inputflinger/InputReader.h +++ b/services/inputflinger/InputReader.h @@ -484,7 +484,7 @@ protected: InputReader* mReader; public: - ContextImpl(InputReader* reader); + explicit ContextImpl(InputReader* reader); virtual void updateGlobalMetaState(); virtual int32_t getGlobalMetaState(); @@ -568,7 +568,7 @@ private: /* Reads raw events from the event hub and processes them, endlessly. */ class InputReaderThread : public Thread { public: - InputReaderThread(const sp<InputReaderInterface>& reader); + explicit InputReaderThread(const sp<InputReaderInterface>& reader); virtual ~InputReaderThread(); private: @@ -1007,7 +1007,7 @@ private: */ class InputMapper { public: - InputMapper(InputDevice* device); + explicit InputMapper(InputDevice* device); virtual ~InputMapper(); inline InputDevice* getDevice() { return mDevice; } @@ -1058,7 +1058,7 @@ protected: class SwitchInputMapper : public InputMapper { public: - SwitchInputMapper(InputDevice* device); + explicit SwitchInputMapper(InputDevice* device); virtual ~SwitchInputMapper(); virtual uint32_t getSources(); @@ -1078,7 +1078,7 @@ private: class VibratorInputMapper : public InputMapper { public: - VibratorInputMapper(InputDevice* device); + explicit VibratorInputMapper(InputDevice* device); virtual ~VibratorInputMapper(); virtual uint32_t getSources(); @@ -1178,7 +1178,7 @@ private: class CursorInputMapper : public InputMapper { public: - CursorInputMapper(InputDevice* device); + explicit CursorInputMapper(InputDevice* device); virtual ~CursorInputMapper(); virtual uint32_t getSources(); @@ -1243,7 +1243,7 @@ private: class RotaryEncoderInputMapper : public InputMapper { public: - RotaryEncoderInputMapper(InputDevice* device); + explicit RotaryEncoderInputMapper(InputDevice* device); virtual ~RotaryEncoderInputMapper(); virtual uint32_t getSources(); @@ -1264,7 +1264,7 @@ private: class TouchInputMapper : public InputMapper { public: - TouchInputMapper(InputDevice* device); + explicit TouchInputMapper(InputDevice* device); virtual ~TouchInputMapper(); virtual uint32_t getSources(); @@ -1887,7 +1887,7 @@ private: class SingleTouchInputMapper : public TouchInputMapper { public: - SingleTouchInputMapper(InputDevice* device); + explicit SingleTouchInputMapper(InputDevice* device); virtual ~SingleTouchInputMapper(); virtual void reset(nsecs_t when); @@ -1905,7 +1905,7 @@ private: class MultiTouchInputMapper : public TouchInputMapper { public: - MultiTouchInputMapper(InputDevice* device); + explicit MultiTouchInputMapper(InputDevice* device); virtual ~MultiTouchInputMapper(); virtual void reset(nsecs_t when); @@ -1926,7 +1926,7 @@ private: class ExternalStylusInputMapper : public InputMapper { public: - ExternalStylusInputMapper(InputDevice* device); + explicit ExternalStylusInputMapper(InputDevice* device); virtual ~ExternalStylusInputMapper() = default; virtual uint32_t getSources(); @@ -1948,7 +1948,7 @@ private: class JoystickInputMapper : public InputMapper { public: - JoystickInputMapper(InputDevice* device); + explicit JoystickInputMapper(InputDevice* device); virtual ~JoystickInputMapper(); virtual uint32_t getSources(); diff --git a/services/inputflinger/InputWindow.h b/services/inputflinger/InputWindow.h index e243637ed8..feca6cf4e2 100644 --- a/services/inputflinger/InputWindow.h +++ b/services/inputflinger/InputWindow.h @@ -196,7 +196,7 @@ public: void releaseInfo(); protected: - InputWindowHandle(const sp<InputApplicationHandle>& inputApplicationHandle); + explicit InputWindowHandle(const sp<InputApplicationHandle>& inputApplicationHandle); virtual ~InputWindowHandle(); InputWindowInfo* mInfo; diff --git a/services/inputflinger/host/InputDriver.h b/services/inputflinger/host/InputDriver.h index 8d5a31e0c5..e56673b4d3 100644 --- a/services/inputflinger/host/InputDriver.h +++ b/services/inputflinger/host/InputDriver.h @@ -82,7 +82,7 @@ public: class InputDriver : public InputDriverInterface { public: - InputDriver(const char* name); + explicit InputDriver(const char* name); virtual ~InputDriver() = default; virtual void init() override; diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index a7fe69c1ad..f12320d3ef 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -325,7 +325,7 @@ class FakeEventHub : public EventHubInterface { KeyedVector<int32_t, bool> leds; Vector<VirtualKeyDefinition> virtualKeys; - Device(uint32_t classes) : + explicit Device(uint32_t classes) : classes(classes) { } }; diff --git a/services/nativeperms/.clang-format b/services/nativeperms/.clang-format new file mode 100644 index 0000000000..6006e6f4fd --- /dev/null +++ b/services/nativeperms/.clang-format @@ -0,0 +1,13 @@ +BasedOnStyle: Google +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true +BinPackArguments: true +BinPackParameters: true +ColumnLimit: 80 +CommentPragmas: NOLINT:.* +ContinuationIndentWidth: 8 +DerivePointerAlignment: false +IndentWidth: 4 +PointerAlignment: Left +TabWidth: 4 diff --git a/libs/diskusage/Android.mk b/services/nativeperms/Android.mk index d54f8adf60..34ccd0bf79 100644 --- a/libs/diskusage/Android.mk +++ b/services/nativeperms/Android.mk @@ -1,4 +1,4 @@ -# Copyright (C) 2010 The Android Open Source Project +# Copyright 2016 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. @@ -11,14 +11,21 @@ # 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. +# -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE := libdiskusage - -LOCAL_MODULE_TAGS := optional - -LOCAL_SRC_FILES := dirsize.c +LOCAL_PATH := $(call my-dir) -include $(BUILD_STATIC_LIBRARY)
\ No newline at end of file +include $(CLEAR_VARS) +LOCAL_MODULE := nativeperms +LOCAL_SRC_FILES := \ + nativeperms.cpp \ + android/os/IPermissionController.aidl +LOCAL_CFLAGS := -Wall -Werror +LOCAL_SHARED_LIBRARIES := \ + libbinder \ + libbrillo \ + libbrillo-binder \ + libchrome \ + libutils +LOCAL_INIT_RC := nativeperms.rc +include $(BUILD_EXECUTABLE) diff --git a/services/nativeperms/android/os/IPermissionController.aidl b/services/nativeperms/android/os/IPermissionController.aidl new file mode 100644 index 0000000000..89db85ca0a --- /dev/null +++ b/services/nativeperms/android/os/IPermissionController.aidl @@ -0,0 +1,25 @@ +/* //device/java/android/android/os/IPowerManager.aidl +** +** Copyright 2007, 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. +*/ + +package android.os; + +/** @hide */ +interface IPermissionController { + boolean checkPermission(String permission, int pid, int uid); + String[] getPackagesForUid(int uid); + boolean isRuntimePermission(String permission); +} diff --git a/services/nativeperms/android/os/README b/services/nativeperms/android/os/README new file mode 100644 index 0000000000..e4144995b0 --- /dev/null +++ b/services/nativeperms/android/os/README @@ -0,0 +1,4 @@ +IPermissionController.aidl in this directory is a verbatim copy of +https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/IPermissionController.aidl, +because some Brillo manifests do not currently include the frameworks/base repo. +TODO(jorgelo): Figure out a way to use the .aidl file in frameworks/base. diff --git a/services/nativeperms/nativeperms.cpp b/services/nativeperms/nativeperms.cpp new file mode 100644 index 0000000000..7f03bedb29 --- /dev/null +++ b/services/nativeperms/nativeperms.cpp @@ -0,0 +1,87 @@ +/* + * Copyright 2016 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. + */ + +#include <base/at_exit.h> +#include <base/logging.h> +#include <base/message_loop/message_loop.h> +#include <binder/IServiceManager.h> +#include <binder/Status.h> +#include <brillo/binder_watcher.h> +#include <brillo/message_loops/base_message_loop.h> +#include <brillo/syslog_logging.h> +#include <utils/String16.h> + +#include "android/os/BnPermissionController.h" + +namespace { +static android::String16 serviceName("permission"); +} + +namespace android { + +class PermissionService : public android::os::BnPermissionController { + public: + ::android::binder::Status checkPermission( + const ::android::String16& permission, int32_t pid, int32_t uid, + bool* _aidl_return) { + (void)permission; + (void)pid; + (void)uid; + *_aidl_return = true; + return binder::Status::ok(); + } + + ::android::binder::Status getPackagesForUid( + int32_t uid, ::std::vector<::android::String16>* _aidl_return) { + (void)uid; + // Brillo doesn't currently have installable packages. + if (_aidl_return) { + _aidl_return->clear(); + } + return binder::Status::ok(); + } + + ::android::binder::Status isRuntimePermission( + const ::android::String16& permission, bool* _aidl_return) { + (void)permission; + // Brillo doesn't currently have runtime permissions. + *_aidl_return = false; + return binder::Status::ok(); + } +}; + +} // namespace android + +int main() { + base::AtExitManager atExitManager; + brillo::InitLog(brillo::kLogToSyslog); + // Register the service with servicemanager. + android::status_t status = android::defaultServiceManager()->addService( + serviceName, new android::PermissionService()); + CHECK(status == android::OK) << "Failed to get IPermissionController " + "binder from servicemanager."; + + // Create a message loop. + base::MessageLoopForIO messageLoopForIo; + brillo::BaseMessageLoop messageLoop{&messageLoopForIo}; + + // Initialize a binder watcher. + brillo::BinderWatcher watcher(&messageLoop); + watcher.Init(); + + // Run the message loop. + messageLoop.Run(); +} diff --git a/services/nativeperms/nativeperms.rc b/services/nativeperms/nativeperms.rc new file mode 100644 index 0000000000..704c0a2acc --- /dev/null +++ b/services/nativeperms/nativeperms.rc @@ -0,0 +1,4 @@ +service nativeperms /system/bin/nativeperms + class main + user system + group system diff --git a/services/powermanager/Android.bp b/services/powermanager/Android.bp new file mode 100644 index 0000000000..7b3af70927 --- /dev/null +++ b/services/powermanager/Android.bp @@ -0,0 +1,17 @@ +cc_library_shared { + name: "libpowermanager", + + srcs: ["IPowerManager.cpp"], + + shared_libs: [ + "libutils", + "libbinder", + ], + + cflags: [ + "-Wall", + "-Werror", + "-Wunused", + "-Wunreachable-code", + ], +} diff --git a/services/powermanager/Android.mk b/services/powermanager/Android.mk deleted file mode 100644 index 4deb115eee..0000000000 --- a/services/powermanager/Android.mk +++ /dev/null @@ -1,19 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= \ - IPowerManager.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libbinder - -LOCAL_MODULE:= libpowermanager - -LOCAL_MODULE_TAGS := optional - -LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code - -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../../include - -include $(BUILD_SHARED_LIBRARY) diff --git a/services/powermanager/IPowerManager.cpp b/services/powermanager/IPowerManager.cpp index bff871916f..ea3a831c13 100644 --- a/services/powermanager/IPowerManager.cpp +++ b/services/powermanager/IPowerManager.cpp @@ -30,7 +30,7 @@ namespace android { class BpPowerManager : public BpInterface<IPowerManager> { public: - BpPowerManager(const sp<IBinder>& impl) + explicit BpPowerManager(const sp<IBinder>& impl) : BpInterface<IPowerManager>(impl) { } diff --git a/services/sensorservice/RecentEventLogger.h b/services/sensorservice/RecentEventLogger.h index 8b15e5a007..bf1f655704 100644 --- a/services/sensorservice/RecentEventLogger.h +++ b/services/sensorservice/RecentEventLogger.h @@ -35,7 +35,7 @@ namespace SensorServiceUtil { // behavior. class RecentEventLogger : public Dumpable { public: - RecentEventLogger(int sensorType); + explicit RecentEventLogger(int sensorType); void addEvent(const sensors_event_t& event); bool populateLastEvent(sensors_event_t *event) const; bool isEmpty() const; @@ -47,7 +47,7 @@ public: protected: struct SensorEventLog { - SensorEventLog(const sensors_event_t& e); + explicit SensorEventLog(const sensors_event_t& e); timespec mWallTime; sensors_event_t mEvent; }; diff --git a/services/sensorservice/RingBuffer.h b/services/sensorservice/RingBuffer.h index ec98a01413..a60eb90053 100644 --- a/services/sensorservice/RingBuffer.h +++ b/services/sensorservice/RingBuffer.h @@ -39,7 +39,7 @@ public: /** * Construct a RingBuffer that can grow up to the given length. */ - RingBuffer(size_t length); + explicit RingBuffer(size_t length); /** * Forward iterator to this class. Implements an std:forward_iterator. diff --git a/services/sensorservice/RotationVectorSensor.h b/services/sensorservice/RotationVectorSensor.h index 3cc224888b..265b4c410e 100644 --- a/services/sensorservice/RotationVectorSensor.h +++ b/services/sensorservice/RotationVectorSensor.h @@ -34,7 +34,7 @@ namespace android { class RotationVectorSensor : public VirtualSensor { public: - RotationVectorSensor(int mode = FUSION_9AXIS); + explicit RotationVectorSensor(int mode = FUSION_9AXIS); virtual bool process(sensors_event_t* outEvent, const sensors_event_t& event) override; virtual status_t activate(void* ident, bool enabled) override; virtual status_t setDelay(void* ident, int handle, int64_t ns) override; diff --git a/services/sensorservice/SensorEventAckReceiver.h b/services/sensorservice/SensorEventAckReceiver.h index 998597a84b..20fa4c7911 100644 --- a/services/sensorservice/SensorEventAckReceiver.h +++ b/services/sensorservice/SensorEventAckReceiver.h @@ -27,7 +27,7 @@ class SensorService::SensorEventAckReceiver : public Thread { sp<SensorService> const mService; public: virtual bool threadLoop(); - SensorEventAckReceiver(const sp<SensorService>& service) + explicit SensorEventAckReceiver(const sp<SensorService>& service) : mService(service) { } }; diff --git a/services/sensorservice/SensorInterface.h b/services/sensorservice/SensorInterface.h index dafcf2ddca..0867dc278b 100644 --- a/services/sensorservice/SensorInterface.h +++ b/services/sensorservice/SensorInterface.h @@ -47,7 +47,7 @@ public: class BaseSensor : public SensorInterface { public: - BaseSensor(const sensor_t& sensor); + explicit BaseSensor(const sensor_t& sensor); BaseSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]); // Not all sensors need to support batching. @@ -74,7 +74,7 @@ protected: class HardwareSensor : public BaseSensor { public: - HardwareSensor(const sensor_t& sensor); + explicit HardwareSensor(const sensor_t& sensor); HardwareSensor(const sensor_t& sensor, const uint8_t (&uuid)[16]); virtual ~HardwareSensor(); diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp index 99da2c4974..7b47709a82 100644 --- a/services/sensorservice/SensorService.cpp +++ b/services/sensorservice/SensorService.cpp @@ -950,9 +950,11 @@ status_t SensorService::resetToNormalMode() { status_t SensorService::resetToNormalModeLocked() { SensorDevice& dev(SensorDevice::getInstance()); - dev.enableAllSensors(); status_t err = dev.setMode(NORMAL); - mCurrentOperatingMode = NORMAL; + if (err == NO_ERROR) { + mCurrentOperatingMode = NORMAL; + dev.enableAllSensors(); + } return err; } diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h index 4a63ef0afc..e969d8a9c0 100644 --- a/services/sensorservice/SensorService.h +++ b/services/sensorservice/SensorService.h @@ -49,9 +49,9 @@ #define IGNORE_HARDWARE_FUSION false #define DEBUG_CONNECTIONS false // Max size is 100 KB which is enough to accept a batch of about 1000 events. -#define MAX_SOCKET_BUFFER_SIZE_BATCHED 100 * 1024 +#define MAX_SOCKET_BUFFER_SIZE_BATCHED (100 * 1024) // For older HALs which don't support batching, use a smaller socket buffer size. -#define SOCKET_BUFFER_SIZE_NON_BATCHED 4 * 1024 +#define SOCKET_BUFFER_SIZE_NON_BATCHED (4 * 1024) #define SENSOR_REGISTRATIONS_BUF_SIZE 200 diff --git a/services/sensorservice/mat.h b/services/sensorservice/mat.h index a76fc91cb0..495c14e67e 100644 --- a/services/sensorservice/mat.h +++ b/services/sensorservice/mat.h @@ -139,13 +139,13 @@ public: mat() { } mat(const mat& rhs) : base(rhs) { } - mat(const base& rhs) : base(rhs) { } + mat(const base& rhs) : base(rhs) { } // NOLINT(implicit) // ----------------------------------------------------------------------- // conversion constructors // sets the diagonal to the value, off-diagonal to zero - mat(pTYPE rhs) { + mat(pTYPE rhs) { // NOLINT(implicit) helpers::doAssign(*this, rhs); } @@ -220,7 +220,7 @@ public: template<size_t PREV_COLUMN> struct column_builder { mat& matrix; - column_builder(mat& matrix) : matrix(matrix) { } + explicit column_builder(mat& matrix) : matrix(matrix) { } }; // operator << is not a method of column_builder<> so we can @@ -265,9 +265,9 @@ public: enum { ROWS = R, COLS = 1 }; mat() { } - mat(const base& rhs) : base(rhs) { } + explicit mat(const base& rhs) : base(rhs) { } mat(const mat& rhs) : base(rhs) { } - mat(const TYPE& rhs) { helpers::doAssign(*this, rhs); } + explicit mat(const TYPE& rhs) { helpers::doAssign(*this, rhs); } mat& operator=(const mat& rhs) { base::operator=(rhs); return *this; } mat& operator=(const base& rhs) { base::operator=(rhs); return *this; } mat& operator=(const TYPE& rhs) { return helpers::doAssign(*this, rhs); } diff --git a/services/sensorservice/vec.h b/services/sensorservice/vec.h index a142bad3a1..9e5d2809c3 100644 --- a/services/sensorservice/vec.h +++ b/services/sensorservice/vec.h @@ -322,12 +322,12 @@ public: vec() { } vec(const vec& rhs) : base(rhs) { } - vec(const base& rhs) : base(rhs) { } + vec(const base& rhs) : base(rhs) { } // NOLINT(implicit) // ----------------------------------------------------------------------- // conversion constructors - vec(pTYPE rhs) { + vec(pTYPE rhs) { // NOLINT(implicit) for (size_t i=0 ; i<SIZE ; i++) base::operator[](i) = rhs; } diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk index ffda035a9a..e8d2dbd4cb 100644 --- a/services/surfaceflinger/Android.mk +++ b/services/surfaceflinger/Android.mk @@ -154,7 +154,8 @@ include $(CLEAR_VARS) LOCAL_CLANG := true -LOCAL_LDFLAGS := -Wl,--version-script,art/sigchainlib/version-script.txt -Wl,--export-dynamic +LOCAL_LDFLAGS_32 := -Wl,--version-script,art/sigchainlib/version-script32.txt -Wl,--export-dynamic +LOCAL_LDFLAGS_64 := -Wl,--version-script,art/sigchainlib/version-script64.txt -Wl,--export-dynamic LOCAL_CFLAGS := -DLOG_TAG=\"SurfaceFlinger\" LOCAL_CPPFLAGS := -std=c++14 diff --git a/services/surfaceflinger/Client.h b/services/surfaceflinger/Client.h index 12db50568f..9c7d05042a 100644 --- a/services/surfaceflinger/Client.h +++ b/services/surfaceflinger/Client.h @@ -38,7 +38,7 @@ class SurfaceFlinger; class Client : public BnSurfaceComposerClient { public: - Client(const sp<SurfaceFlinger>& flinger); + explicit Client(const sp<SurfaceFlinger>& flinger); ~Client(); status_t initCheck() const; diff --git a/services/surfaceflinger/Colorizer.h b/services/surfaceflinger/Colorizer.h index 652448159f..f2e6491368 100644 --- a/services/surfaceflinger/Colorizer.h +++ b/services/surfaceflinger/Colorizer.h @@ -34,7 +34,7 @@ public: WHITE = 37 }; - Colorizer(bool enabled) + explicit Colorizer(bool enabled) : mEnabled(enabled) { } diff --git a/services/surfaceflinger/DispSync.h b/services/surfaceflinger/DispSync.h index 537c81bc2c..2763e59559 100644 --- a/services/surfaceflinger/DispSync.h +++ b/services/surfaceflinger/DispSync.h @@ -61,7 +61,7 @@ public: virtual void onDispSyncEvent(nsecs_t when) = 0; }; - DispSync(const char* name); + explicit DispSync(const char* name); ~DispSync(); // reset clears the resync samples and error value. diff --git a/services/surfaceflinger/DisplayHardware/FloatRect.h b/services/surfaceflinger/DisplayHardware/FloatRect.h index 9ad1040cd2..151eaaa622 100644 --- a/services/surfaceflinger/DisplayHardware/FloatRect.h +++ b/services/surfaceflinger/DisplayHardware/FloatRect.h @@ -32,7 +32,7 @@ public: inline FloatRect() : left(0), top(0), right(0), bottom(0) { } - inline FloatRect(const Rect& other) + inline FloatRect(const Rect& other) // NOLINT(implicit) : left(other.left), top(other.top), right(other.right), bottom(other.bottom) { } inline float getWidth() const { return right - left; } diff --git a/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp b/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp index 7368d775ad..18c7945577 100644 --- a/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp +++ b/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp @@ -240,7 +240,7 @@ status_t FramebufferSurface::compositionComplete() #endif void FramebufferSurface::dumpAsString(String8& result) const { - ConsumerBase::dump(result); + ConsumerBase::dumpState(result); } void FramebufferSurface::dumpLocked(String8& result, const char* prefix) const diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h index fb04af877e..32a9de0018 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.h +++ b/services/surfaceflinger/DisplayHardware/HWC2.h @@ -57,7 +57,7 @@ typedef std::function<void(std::shared_ptr<Display>, nsecs_t)> VsyncCallback; class Device { public: - Device(hwc2_device_t* device); + explicit Device(hwc2_device_t* device); ~Device(); friend class HWC2::Display; diff --git a/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.h b/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.h index bdacc737c6..962361ec6e 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.h +++ b/services/surfaceflinger/DisplayHardware/HWC2On1Adapter.h @@ -43,7 +43,7 @@ namespace android { class HWC2On1Adapter : public hwc2_device_t { public: - HWC2On1Adapter(struct hwc_composer_device_1* hwc1Device); + explicit HWC2On1Adapter(struct hwc_composer_device_1* hwc1Device); ~HWC2On1Adapter(); struct hwc_composer_device_1* getHwc1Device() const { return mHwc1Device; } @@ -495,7 +495,7 @@ private: class Layer { public: - Layer(Display& display); + explicit Layer(Display& display); bool operator==(const Layer& other) { return mId == other.mId; } bool operator!=(const Layer& other) { return !(*this == other); } diff --git a/services/surfaceflinger/EventControlThread.h b/services/surfaceflinger/EventControlThread.h index be6c53aa32..9368db6fc8 100644 --- a/services/surfaceflinger/EventControlThread.h +++ b/services/surfaceflinger/EventControlThread.h @@ -29,7 +29,7 @@ class SurfaceFlinger; class EventControlThread: public Thread { public: - EventControlThread(const sp<SurfaceFlinger>& flinger); + explicit EventControlThread(const sp<SurfaceFlinger>& flinger); virtual ~EventControlThread() {} void setVsyncEnabled(bool enabled); diff --git a/services/surfaceflinger/EventLog/EventLog.h b/services/surfaceflinger/EventLog/EventLog.h index 52075147ef..efc5d70cd3 100644 --- a/services/surfaceflinger/EventLog/EventLog.h +++ b/services/surfaceflinger/EventLog/EventLog.h @@ -52,7 +52,7 @@ private: bool mOverflow; char mStorage[STORAGE_MAX_SIZE]; public: - TagBuffer(int32_t tag); + explicit TagBuffer(int32_t tag); // starts list of items void startList(int8_t count); diff --git a/services/surfaceflinger/EventThread.h b/services/surfaceflinger/EventThread.h index 34654fa941..b6351150d7 100644 --- a/services/surfaceflinger/EventThread.h +++ b/services/surfaceflinger/EventThread.h @@ -57,7 +57,7 @@ public: class EventThread : public Thread, private VSyncSource::Callback { class Connection : public BnDisplayEventConnection { public: - Connection(const sp<EventThread>& eventThread); + explicit Connection(const sp<EventThread>& eventThread); status_t postEvent(const DisplayEventReceiver::Event& event); // count >= 1 : continuous event. count is the vsync rate diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index dfece935b1..d13b6dbe19 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -163,9 +163,7 @@ void Layer::onFirstRef() { mSurfaceFlingerConsumer->setContentsChangedListener(this); mSurfaceFlingerConsumer->setName(mName); -#ifdef TARGET_DISABLE_TRIPLE_BUFFERING -#warning "disabling triple buffering" -#else +#ifndef TARGET_DISABLE_TRIPLE_BUFFERING mProducer->setMaxDequeuedBufferCount(2); #endif @@ -2237,7 +2235,7 @@ void Layer::dump(String8& result, Colorizer& colorizer) const mQueuedFrames, mRefreshPending); if (mSurfaceFlingerConsumer != 0) { - mSurfaceFlingerConsumer->dump(result, " "); + mSurfaceFlingerConsumer->dumpState(result, " "); } } diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 2ce1340a23..24de87ee9b 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -477,7 +477,7 @@ private: class SyncPoint { public: - SyncPoint(uint64_t frameNumber) : mFrameNumber(frameNumber), + explicit SyncPoint(uint64_t frameNumber) : mFrameNumber(frameNumber), mFrameIsAvailable(false), mTransactionIsApplied(false) {} uint64_t getFrameNumber() const { diff --git a/services/surfaceflinger/MessageQueue.h b/services/surfaceflinger/MessageQueue.h index 1004f4c0c6..aed0aa90f2 100644 --- a/services/surfaceflinger/MessageQueue.h +++ b/services/surfaceflinger/MessageQueue.h @@ -69,7 +69,7 @@ class MessageQueue { MessageQueue& mQueue; int32_t mEventMask; public: - Handler(MessageQueue& queue) : mQueue(queue), mEventMask(0) { } + explicit Handler(MessageQueue& queue) : mQueue(queue), mEventMask(0) { } virtual void handleMessage(const Message& message); void dispatchRefresh(); void dispatchInvalidate(); diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 8db071ed2f..30ebfd56f6 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -90,6 +90,19 @@ EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name); +// Workaround for b/30067360: /proc/self/environ inaccessible in SurfaceFlinger +// => ASan fails to read ASAN_OPTIONS => alloc-dealloc-mismatch bug is not +// suppressed and prevents the device from booting. +#ifndef __has_feature +#define __has_feature(x) 0 +#endif +#if __has_feature(address_sanitizer) +__attribute__((visibility("default"))) +extern "C" const char* __asan_default_options() { + return "alloc_dealloc_mismatch=0"; +} +#endif + namespace android { // This is the phase offset in nanoseconds of the software vsync event diff --git a/vulkan/Android.bp b/vulkan/Android.bp new file mode 100644 index 0000000000..97d99d0950 --- /dev/null +++ b/vulkan/Android.bp @@ -0,0 +1,24 @@ +// Copyright (C) 2016 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. + +ndk_headers { + name: "libvulkan_headers", + from: "include", + to: "", + srcs: ["include/vulkan/**/*.h"], +} + +subdirs = [ + "libvulkan", +] diff --git a/vulkan/libvulkan/Android.bp b/vulkan/libvulkan/Android.bp new file mode 100644 index 0000000000..5e3f4dd8dc --- /dev/null +++ b/vulkan/libvulkan/Android.bp @@ -0,0 +1,20 @@ +// Copyright (C) 2016 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. + +// Headers module is in frameworks/native/vulkan/Android.bp. +ndk_library { + name: "libvulkan.ndk", + symbol_file: "libvulkan.map.txt", + first_version: "24", +} diff --git a/vulkan/libvulkan/Android.mk b/vulkan/libvulkan/Android.mk index d2e28ff665..f1155ca47b 100644 --- a/vulkan/libvulkan/Android.mk +++ b/vulkan/libvulkan/Android.mk @@ -26,6 +26,7 @@ LOCAL_CFLAGS := -DLOG_TAG=\"vulkan\" \ -Wno-padded \ -Wno-switch-enum \ -Wno-undef + #LOCAL_CFLAGS += -DLOG_NDEBUG=0 LOCAL_CPPFLAGS := -std=c++14 \ -Wno-c99-extensions \ diff --git a/vulkan/libvulkan/debug_report.h b/vulkan/libvulkan/debug_report.h index be9b645aa7..3d8bd50c28 100644 --- a/vulkan/libvulkan/debug_report.h +++ b/vulkan/libvulkan/debug_report.h @@ -85,9 +85,9 @@ class DebugReportCallbackList { class DebugReportLogger { public: - DebugReportLogger(const VkInstanceCreateInfo& info) + explicit DebugReportLogger(const VkInstanceCreateInfo& info) : instance_pnext_(info.pNext), callbacks_(nullptr) {} - DebugReportLogger(const DebugReportCallbackList& callbacks) + explicit DebugReportLogger(const DebugReportCallbackList& callbacks) : instance_pnext_(nullptr), callbacks_(&callbacks) {} void Message(VkDebugReportFlagsEXT flags, diff --git a/vulkan/libvulkan/driver.h b/vulkan/libvulkan/driver.h index a02ebd7f0b..a1612c7081 100644 --- a/vulkan/libvulkan/driver.h +++ b/vulkan/libvulkan/driver.h @@ -61,7 +61,7 @@ VK_DEFINE_HANDLE(InstanceDispatchable) VK_DEFINE_HANDLE(DeviceDispatchable) struct InstanceData { - InstanceData(const VkAllocationCallbacks& alloc) + explicit InstanceData(const VkAllocationCallbacks& alloc) : opaque_api_data(), allocator(alloc), driver(), diff --git a/vulkan/libvulkan/layers_extensions.h b/vulkan/libvulkan/layers_extensions.h index 79fe59d7cf..07ac1a3861 100644 --- a/vulkan/libvulkan/layers_extensions.h +++ b/vulkan/libvulkan/layers_extensions.h @@ -26,7 +26,7 @@ struct Layer; class LayerRef { public: - LayerRef(const Layer* layer); + explicit LayerRef(const Layer* layer); LayerRef(LayerRef&& other); ~LayerRef(); LayerRef(const LayerRef&) = delete; diff --git a/vulkan/libvulkan/libvulkan.map.txt b/vulkan/libvulkan/libvulkan.map.txt new file mode 100644 index 0000000000..174592564d --- /dev/null +++ b/vulkan/libvulkan/libvulkan.map.txt @@ -0,0 +1,153 @@ +LIBVULKAN { + global: + vkAcquireNextImageKHR; + vkAllocateCommandBuffers; + vkAllocateDescriptorSets; + vkAllocateMemory; + vkBeginCommandBuffer; + vkBindBufferMemory; + vkBindImageMemory; + vkCmdBeginQuery; + vkCmdBeginRenderPass; + vkCmdBindDescriptorSets; + vkCmdBindIndexBuffer; + vkCmdBindPipeline; + vkCmdBindVertexBuffers; + vkCmdBlitImage; + vkCmdClearAttachments; + vkCmdClearColorImage; + vkCmdClearDepthStencilImage; + vkCmdCopyBuffer; + vkCmdCopyBufferToImage; + vkCmdCopyImage; + vkCmdCopyImageToBuffer; + vkCmdCopyQueryPoolResults; + vkCmdDispatch; + vkCmdDispatchIndirect; + vkCmdDraw; + vkCmdDrawIndexed; + vkCmdDrawIndexedIndirect; + vkCmdDrawIndirect; + vkCmdEndQuery; + vkCmdEndRenderPass; + vkCmdExecuteCommands; + vkCmdFillBuffer; + vkCmdNextSubpass; + vkCmdPipelineBarrier; + vkCmdPushConstants; + vkCmdResetEvent; + vkCmdResetQueryPool; + vkCmdResolveImage; + vkCmdSetBlendConstants; + vkCmdSetDepthBias; + vkCmdSetDepthBounds; + vkCmdSetEvent; + vkCmdSetLineWidth; + vkCmdSetScissor; + vkCmdSetStencilCompareMask; + vkCmdSetStencilReference; + vkCmdSetStencilWriteMask; + vkCmdSetViewport; + vkCmdUpdateBuffer; + vkCmdWaitEvents; + vkCmdWriteTimestamp; + vkCreateAndroidSurfaceKHR; + vkCreateBuffer; + vkCreateBufferView; + vkCreateCommandPool; + vkCreateComputePipelines; + vkCreateDescriptorPool; + vkCreateDescriptorSetLayout; + vkCreateDevice; + vkCreateEvent; + vkCreateFence; + vkCreateFramebuffer; + vkCreateGraphicsPipelines; + vkCreateImage; + vkCreateImageView; + vkCreateInstance; + vkCreatePipelineCache; + vkCreatePipelineLayout; + vkCreateQueryPool; + vkCreateRenderPass; + vkCreateSampler; + vkCreateSemaphore; + vkCreateShaderModule; + vkCreateSwapchainKHR; + vkDestroyBuffer; + vkDestroyBufferView; + vkDestroyCommandPool; + vkDestroyDescriptorPool; + vkDestroyDescriptorSetLayout; + vkDestroyDevice; + vkDestroyEvent; + vkDestroyFence; + vkDestroyFramebuffer; + vkDestroyImage; + vkDestroyImageView; + vkDestroyInstance; + vkDestroyPipeline; + vkDestroyPipelineCache; + vkDestroyPipelineLayout; + vkDestroyQueryPool; + vkDestroyRenderPass; + vkDestroySampler; + vkDestroySemaphore; + vkDestroyShaderModule; + vkDestroySurfaceKHR; + vkDestroySwapchainKHR; + vkDeviceWaitIdle; + vkEndCommandBuffer; + vkEnumerateDeviceExtensionProperties; + vkEnumerateDeviceLayerProperties; + vkEnumerateInstanceExtensionProperties; + vkEnumerateInstanceLayerProperties; + vkEnumeratePhysicalDevices; + vkFlushMappedMemoryRanges; + vkFreeCommandBuffers; + vkFreeDescriptorSets; + vkFreeMemory; + vkGetBufferMemoryRequirements; + vkGetDeviceMemoryCommitment; + vkGetDeviceProcAddr; + vkGetDeviceQueue; + vkGetEventStatus; + vkGetFenceStatus; + vkGetImageMemoryRequirements; + vkGetImageSparseMemoryRequirements; + vkGetImageSubresourceLayout; + vkGetInstanceProcAddr; + vkGetPhysicalDeviceFeatures; + vkGetPhysicalDeviceFormatProperties; + vkGetPhysicalDeviceImageFormatProperties; + vkGetPhysicalDeviceMemoryProperties; + vkGetPhysicalDeviceProperties; + vkGetPhysicalDeviceQueueFamilyProperties; + vkGetPhysicalDeviceSparseImageFormatProperties; + vkGetPhysicalDeviceSurfaceCapabilitiesKHR; + vkGetPhysicalDeviceSurfaceFormatsKHR; + vkGetPhysicalDeviceSurfacePresentModesKHR; + vkGetPhysicalDeviceSurfaceSupportKHR; + vkGetPipelineCacheData; + vkGetQueryPoolResults; + vkGetRenderAreaGranularity; + vkGetSwapchainImagesKHR; + vkInvalidateMappedMemoryRanges; + vkMapMemory; + vkMergePipelineCaches; + vkQueueBindSparse; + vkQueuePresentKHR; + vkQueueSubmit; + vkQueueWaitIdle; + vkResetCommandBuffer; + vkResetCommandPool; + vkResetDescriptorPool; + vkResetEvent; + vkResetFences; + vkSetEvent; + vkUnmapMemory; + vkUpdateDescriptorSets; + vkWaitForFences; + local: + *; +}; diff --git a/vulkan/libvulkan/stubhal.cpp b/vulkan/libvulkan/stubhal.cpp index a74d3708e0..869317bcb9 100644 --- a/vulkan/libvulkan/stubhal.cpp +++ b/vulkan/libvulkan/stubhal.cpp @@ -43,7 +43,7 @@ static std::mutex g_instance_mutex; static std::bitset<kMaxInstances> g_instance_used(false); static std::array<hwvulkan_dispatch_t, kMaxInstances> g_instances; -[[noreturn]] void NoOp() { +[[noreturn]] VKAPI_ATTR void NoOp() { LOG_ALWAYS_FATAL("invalid stub function called"); } diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index adc7d5cf1c..63c597cd5f 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -361,9 +361,11 @@ VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice /*pdev*/, if (formats) { if (*count < kNumFormats) result = VK_INCOMPLETE; - std::copy(kFormats, kFormats + std::min(*count, kNumFormats), formats); + *count = std::min(*count, kNumFormats); + std::copy(kFormats, kFormats + *count, formats); + } else { + *count = kNumFormats; } - *count = kNumFormats; return result; } @@ -381,9 +383,11 @@ VkResult GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice /*pdev*/, if (modes) { if (*count < kNumModes) result = VK_INCOMPLETE; - std::copy(kModes, kModes + std::min(*count, kNumModes), modes); + *count = std::min(*count, kNumModes); + std::copy(kModes, kModes + *count, modes); + } else { + *count = kNumModes; } - *count = kNumModes; return result; } @@ -751,8 +755,10 @@ VkResult GetSwapchainImagesKHR(VkDevice, } for (uint32_t i = 0; i < n; i++) images[i] = swapchain.images[i].image; + *count = n; + } else { + *count = swapchain.num_images; } - *count = swapchain.num_images; return result; } |