diff options
31 files changed, 631 insertions, 173 deletions
diff --git a/cmds/dumpstate/Android.mk b/cmds/dumpstate/Android.mk index daeebc41e6..a3522596c0 100644 --- a/cmds/dumpstate/Android.mk +++ b/cmds/dumpstate/Android.mk @@ -10,7 +10,7 @@ LOCAL_SRC_FILES := dumpstate.cpp utils.cpp LOCAL_MODULE := dumpstate -LOCAL_SHARED_LIBRARIES := libcutils libdebuggerd_client liblog libselinux libbase libhardware_legacy +LOCAL_SHARED_LIBRARIES := libcutils libdebuggerd_client liblog libselinux libbase # ZipArchive support, the order matters here to get all symbols. LOCAL_STATIC_LIBRARIES := libziparchive libz libcrypto_static LOCAL_HAL_STATIC_LIBRARIES := libdumpstate diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 93f17fe144..a0f9b09992 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -23,7 +23,6 @@ #include <memory> #include <regex> #include <set> -#include <signal.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> @@ -36,11 +35,11 @@ #include <sys/wait.h> #include <unistd.h> +#include <android-base/file.h> #include <android-base/stringprintf.h> +#include <android-base/strings.h> #include <android-base/unique_fd.h> -#include <android-base/file.h> #include <cutils/properties.h> -#include <hardware_legacy/power.h> #include <private/android_filesystem_config.h> #include <private/android_logger.h> @@ -83,7 +82,6 @@ static std::string suffix; #define TOMBSTONE_MAX_LEN (sizeof(TOMBSTONE_FILE_PREFIX) + 4) #define NUM_TOMBSTONES 10 #define WLUTIL "/vendor/xbin/wlutil" -#define WAKE_LOCK_NAME "dumpstate_wakelock" typedef struct { char name[TOMBSTONE_MAX_LEN]; @@ -152,7 +150,7 @@ void do_mountinfo(int pid, const char *name) { } void add_mountinfo() { - if (!zip_writer) return; + if (!is_zipping()) return; const char *title = "MOUNT INFO"; mount_points.clear(); DurationReporter duration_reporter(title, NULL); @@ -313,8 +311,8 @@ static bool dump_anrd_trace() { } static void dump_systrace() { - if (!zip_writer) { - MYLOGD("Not dumping systrace because zip_writer is not set\n"); + if (!is_zipping()) { + MYLOGD("Not dumping systrace because dumpstate is not zipping\n"); return; } std::string systrace_path = bugreport_dir + "/systrace-" + suffix + ".txt"; @@ -370,7 +368,7 @@ static void dump_raft() { return; } - if (!zip_writer) { + if (!is_zipping()) { // Write compressed and encoded raft logs to stdout if not zip_writer. run_command("RAFT LOGS", 600, "logcompressor", "-r", RAFT_DIR, NULL); return; @@ -387,6 +385,83 @@ static void dump_raft() { } } +/** + * Finds the last modified file in the directory dir whose name starts with file_prefix + * Function returns empty string when it does not find a file + */ +static std::string get_last_modified_file_matching_prefix(const std::string& dir, + const std::string& file_prefix) { + std::unique_ptr<DIR, decltype(&closedir)> d(opendir(dir.c_str()), closedir); + if (d == nullptr) { + MYLOGD("Error %d opening %s\n", errno, dir.c_str()); + return ""; + } + + // Find the newest file matching the file_prefix in dir + struct dirent *de; + time_t last_modified = 0; + std::string last_modified_file = ""; + struct stat s; + + while ((de = readdir(d.get()))) { + std::string file = std::string(de->d_name); + if (!file_prefix.empty()) { + if (!android::base::StartsWith(file, file_prefix.c_str())) continue; + } + file = dir + "/" + file; + int ret = stat(file.c_str(), &s); + + if ((ret == 0) && (s.st_mtime > last_modified)) { + last_modified_file = file; + last_modified = s.st_mtime; + } + } + + return last_modified_file; +} + +void dump_modem_logs() { + DurationReporter duration_reporter("dump_modem_logs"); + if (is_user_build()) { + return; + } + + if (!is_zipping()) { + MYLOGD("Not dumping modem logs. dumpstate is not generating a zipping bugreport\n"); + return; + } + + char property[PROPERTY_VALUE_MAX]; + property_get("ro.radio.log_prefix", property, ""); + std::string file_prefix = std::string(property); + if(file_prefix.empty()) { + MYLOGD("No modem log : file_prefix is empty\n"); + return; + } + + MYLOGD("dump_modem_logs: directory is %s and file_prefix is %s\n", + bugreport_dir.c_str(), file_prefix.c_str()); + + std::string modem_log_file = + get_last_modified_file_matching_prefix(bugreport_dir, file_prefix); + + struct stat s; + if (modem_log_file.empty() || stat(modem_log_file.c_str(), &s) != 0) { + MYLOGD("Modem log %s does not exist\n", modem_log_file.c_str()); + return; + } + + std::string filename = basename(modem_log_file.c_str()); + if (!add_zip_entry(filename, modem_log_file)) { + MYLOGE("Unable to add modem log %s to zip file\n", modem_log_file.c_str()); + } else { + MYLOGD("Modem Log %s is added to zip\n", modem_log_file.c_str()); + if (remove(modem_log_file.c_str())) { + MYLOGE("Error removing modem log %s\n", modem_log_file.c_str()); + } + } +} + static bool skip_not_stat(const char *path) { static const char stat[] = "/stat"; size_t len = strlen(path); @@ -620,8 +695,8 @@ static const std::set<std::string> PROBLEMATIC_FILE_EXTENSIONS = { }; bool add_zip_entry_from_fd(const std::string& entry_name, int fd) { - if (!zip_writer) { - MYLOGD("Not adding zip entry %s from fd because zip_writer is not set\n", + if (!is_zipping()) { + MYLOGD("Not adding entry %s from fd because dumpstate is not zipping\n", entry_name.c_str()); return false; } @@ -691,8 +766,8 @@ static int _add_file_from_fd(const char *title, const char *path, int fd) { // TODO: move to util.cpp void add_dir(const char *dir, bool recursive) { - if (!zip_writer) { - MYLOGD("Not adding dir %s because zip_writer is not set\n", dir); + if (!is_zipping()) { + MYLOGD("Not adding dir %s because dumpstate is not zipping\n", dir); return; } MYLOGD("Adding dir %s (recursive: %d)\n", dir, recursive); @@ -700,10 +775,14 @@ void add_dir(const char *dir, bool recursive) { dump_files(NULL, dir, recursive ? skip_none : is_dir, _add_file_from_fd); } +bool is_zipping() { + return zip_writer != nullptr; +} + /* adds a text entry entry to the existing zip file. */ static bool add_text_zip_entry(const std::string& entry_name, const std::string& content) { - if (!zip_writer) { - MYLOGD("Not adding text zip entry %s because zip_writer is not set\n", entry_name.c_str()); + if (!is_zipping()) { + MYLOGD("Not adding text entry %s because dumpstate is not zipping\n", entry_name.c_str()); return false; } MYLOGD("Adding zip text entry %s\n", entry_name.c_str()); @@ -741,9 +820,63 @@ static void dump_iptables() { run_command("IP6TABLES RAW", 10, "ip6tables", "-t", "raw", "-L", "-nvx", NULL); } +static void do_kmsg() { + struct stat st; + if (!stat(PSTORE_LAST_KMSG, &st)) { + /* Also TODO: Make console-ramoops CAP_SYSLOG protected. */ + dump_file("LAST KMSG", PSTORE_LAST_KMSG); + } else if (!stat(ALT_PSTORE_LAST_KMSG, &st)) { + dump_file("LAST KMSG", ALT_PSTORE_LAST_KMSG); + } else { + /* TODO: Make last_kmsg CAP_SYSLOG protected. b/5555691 */ + dump_file("LAST KMSG", "/proc/last_kmsg"); + } +} + +static void do_logcat() { + unsigned long timeout; + // dump_file("EVENT LOG TAGS", "/etc/event-log-tags"); + // calculate timeout + timeout = logcat_timeout("main") + logcat_timeout("system") + logcat_timeout("crash"); + if (timeout < 20000) { + timeout = 20000; + } + run_command("SYSTEM LOG", timeout / 1000, "logcat", "-v", "threadtime", + "-v", "printable", + "-d", + "*:v", NULL); + timeout = logcat_timeout("events"); + if (timeout < 20000) { + timeout = 20000; + } + run_command("EVENT LOG", timeout / 1000, "logcat", "-b", "events", + "-v", "threadtime", + "-v", "printable", + "-d", + "*:v", NULL); + timeout = logcat_timeout("radio"); + if (timeout < 20000) { + timeout = 20000; + } + run_command("RADIO LOG", timeout / 1000, "logcat", "-b", "radio", + "-v", "threadtime", + "-v", "printable", + "-d", + "*:v", NULL); + + run_command("LOG STATISTICS", 10, "logcat", "-b", "all", "-S", NULL); + + /* kernels must set CONFIG_PSTORE_PMSG, slice up pstore with device tree */ + run_command("LAST LOGCAT", 10, "logcat", "-L", + "-b", "all", + "-v", "threadtime", + "-v", "printable", + "-d", + "*:v", NULL); +} + static void dumpstate(const std::string& screenshot_path, const std::string& version) { DurationReporter duration_reporter("DUMPSTATE"); - unsigned long timeout; dump_dev_files("TRUSTY VERSION", "/sys/bus/platform/drivers/trusty", "trusty_version"); run_command("UPTIME", 10, "uptime", NULL); @@ -789,36 +922,7 @@ static void dumpstate(const std::string& screenshot_path, const std::string& ver MYLOGI("wrote screenshot: %s\n", screenshot_path.c_str()); } - // dump_file("EVENT LOG TAGS", "/etc/event-log-tags"); - // calculate timeout - timeout = logcat_timeout("main") + logcat_timeout("system") + logcat_timeout("crash"); - if (timeout < 20000) { - timeout = 20000; - } - run_command("SYSTEM LOG", timeout / 1000, "logcat", "-v", "threadtime", - "-v", "printable", - "-d", - "*:v", NULL); - timeout = logcat_timeout("events"); - if (timeout < 20000) { - timeout = 20000; - } - run_command("EVENT LOG", timeout / 1000, "logcat", "-b", "events", - "-v", "threadtime", - "-v", "printable", - "-d", - "*:v", NULL); - timeout = logcat_timeout("radio"); - if (timeout < 20000) { - timeout = 20000; - } - run_command("RADIO LOG", timeout / 1000, "logcat", "-b", "radio", - "-v", "threadtime", - "-v", "printable", - "-d", - "*:v", NULL); - - run_command("LOG STATISTICS", 10, "logcat", "-b", "all", "-S", NULL); + do_logcat(); /* show the traces we collected in main(), if that was done */ if (dump_traces_path != NULL) { @@ -886,23 +990,7 @@ static void dumpstate(const std::string& screenshot_path, const std::string& ver dump_file("QTAGUID CTRL INFO", "/proc/net/xt_qtaguid/ctrl"); dump_file("QTAGUID STATS INFO", "/proc/net/xt_qtaguid/stats"); - if (!stat(PSTORE_LAST_KMSG, &st)) { - /* Also TODO: Make console-ramoops CAP_SYSLOG protected. */ - dump_file("LAST KMSG", PSTORE_LAST_KMSG); - } else if (!stat(ALT_PSTORE_LAST_KMSG, &st)) { - dump_file("LAST KMSG", ALT_PSTORE_LAST_KMSG); - } else { - /* TODO: Make last_kmsg CAP_SYSLOG protected. b/5555691 */ - dump_file("LAST KMSG", "/proc/last_kmsg"); - } - - /* kernels must set CONFIG_PSTORE_PMSG, slice up pstore with device tree */ - run_command("LAST LOGCAT", 10, "logcat", "-L", - "-b", "all", - "-v", "threadtime", - "-v", "printable", - "-d", - "*:v", NULL); + do_kmsg(); /* The following have a tendency to get wedged when wifi drivers/fw goes belly-up. */ @@ -1035,6 +1123,10 @@ static void dumpstate(const std::string& screenshot_path, const std::string& ver run_command("APP PROVIDERS", 30, "dumpsys", "-t", "30", "activity", "provider", "all", NULL); + // dump_modem_logs adds the modem logs if available to the bugreport. + // Do this at the end to allow for sufficient time for the modem logs to be + // collected. + dump_modem_logs(); printf("========================================================\n"); printf("== Final progress (pid %d): %d/%d (originally %d)\n", @@ -1046,14 +1138,15 @@ static void dumpstate(const std::string& screenshot_path, const std::string& ver static void usage() { fprintf(stderr, - "usage: dumpstate [-h] [-b soundfile] [-e soundfile] [-o file [-d] [-p] " - "[-z]] [-s] [-S] [-q] [-B] [-P] [-R] [-V version]\n" + "usage: dumpstate [-h] [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-t]" + "[-z] [-s] [-S] [-q] [-B] [-P] [-R] [-V version]\n" " -h: display this help message\n" " -b: play sound file instead of vibrate, at beginning of job\n" " -e: play sound file instead of vibrate, at end of job\n" " -o: write to file (instead of stdout)\n" " -d: append date to filename (requires -o)\n" " -p: capture screenshot to filename.png (requires -o)\n" + " -t: only captures telephony sections\n" " -z: generate zipped file (requires -o)\n" " -s: write output to control socket (for init)\n" " -S: write file location to control socket (for init; requires -o and -z)" @@ -1067,31 +1160,11 @@ static void usage() { VERSION_DEFAULT.c_str()); } -static void wake_lock_releaser() { - if (release_wake_lock(WAKE_LOCK_NAME) < 0) { - MYLOGE("Failed to release wake lock: %s \n", strerror(errno)); - } else { - MYLOGD("Wake lock released.\n"); - } -} - -static void sig_handler(int signo) { - wake_lock_releaser(); +static void sigpipe_handler(int n) { + // don't complain to stderr or stdout _exit(EXIT_FAILURE); } -static void register_sig_handler() { - struct sigaction sa; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sa.sa_handler = sig_handler; - sigaction(SIGPIPE, &sa, NULL); // broken pipe - sigaction(SIGSEGV, &sa, NULL); // segment fault - sigaction(SIGINT, &sa, NULL); // ctrl-c - sigaction(SIGTERM, &sa, NULL); // killed - sigaction(SIGQUIT, &sa, NULL); // quit -} - /* adds the temporary report to the existing .zip file, closes the .zip file, and removes the temporary file. */ @@ -1160,6 +1233,7 @@ static std::string SHA256_file_hash(std::string filepath) { } int main(int argc, char *argv[]) { + struct sigaction sigact; int do_add_date = 0; int do_zip_file = 0; int do_vibrate = 1; @@ -1170,20 +1244,14 @@ int main(int argc, char *argv[]) { int do_broadcast = 0; int do_early_screenshot = 0; int is_remote_mode = 0; + bool telephony_only = false; + std::string version = VERSION_DEFAULT; now = time(NULL); MYLOGI("begin\n"); - if (acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME) < 0) { - MYLOGE("Failed to acquire wake lock: %s \n", strerror(errno)); - } else { - MYLOGD("Wake lock acquired.\n"); - atexit(wake_lock_releaser); - register_sig_handler(); - } - /* gets the sequential id */ char last_id[PROPERTY_VALUE_MAX]; property_get("dumpstate.last_id", last_id, "0"); @@ -1192,6 +1260,11 @@ int main(int argc, char *argv[]) { property_set("dumpstate.last_id", last_id); MYLOGI("dumpstate id: %lu\n", id); + /* clear SIGPIPE handler */ + memset(&sigact, 0, sizeof(sigact)); + sigact.sa_handler = sigpipe_handler; + sigaction(SIGPIPE, &sigact, NULL); + /* set as high priority, and protect from OOM killer */ setpriority(PRIO_PROCESS, 0, -20); @@ -1213,9 +1286,10 @@ int main(int argc, char *argv[]) { format_args(argc, const_cast<const char **>(argv), &args); MYLOGD("Dumpstate command line: %s\n", args.c_str()); int c; - while ((c = getopt(argc, argv, "dho:svqzpPBRSV:")) != -1) { + while ((c = getopt(argc, argv, "dho:svqzptPBRSV:")) != -1) { switch (c) { case 'd': do_add_date = 1; break; + case 't': telephony_only = true; break; case 'z': do_zip_file = 1; break; case 'o': use_outfile = optarg; break; case 's': use_socket = 1; break; @@ -1312,6 +1386,9 @@ int main(int argc, char *argv[]) { char build_id[PROPERTY_VALUE_MAX]; property_get("ro.build.id", build_id, "UNKNOWN_BUILD"); base_name = base_name + "-" + build_id; + if (telephony_only) { + base_name = base_name + "-telephony"; + } if (do_fb) { // TODO: if dumpstate was an object, the paths could be internal variables and then // we could have a function to calculate the derived values, such as: @@ -1421,48 +1498,60 @@ int main(int argc, char *argv[]) { // duration is logged into MYLOG instead. print_header(version); - // Dumps systrace right away, otherwise it will be filled with unnecessary events. - // First try to dump anrd trace if the daemon is running. Otherwise, dump - // the raw trace. - if (!dump_anrd_trace()) { - dump_systrace(); - } - - // TODO: Drop root user and move into dumpstate() once b/28633932 is fixed. - dump_raft(); - - // Invoking the following dumpsys calls before dump_traces() to try and - // keep the system stats as close to its initial state as possible. - run_command_as_shell("DUMPSYS MEMINFO", 30, "dumpsys", "-t", "30", "meminfo", "-a", NULL); - run_command_as_shell("DUMPSYS CPUINFO", 10, "dumpsys", "-t", "10", "cpuinfo", "-a", NULL); + if (telephony_only) { + dump_iptables(); + if (!drop_root_user()) { + return -1; + } + do_dmesg(); + do_logcat(); + do_kmsg(); + dumpstate_board(); + dump_modem_logs(); + } else { + // Dumps systrace right away, otherwise it will be filled with unnecessary events. + // First try to dump anrd trace if the daemon is running. Otherwise, dump + // the raw trace. + if (!dump_anrd_trace()) { + dump_systrace(); + } - /* collect stack traces from Dalvik and native processes (needs root) */ - dump_traces_path = dump_traces(); + // TODO: Drop root user and move into dumpstate() once b/28633932 is fixed. + dump_raft(); + + // Invoking the following dumpsys calls before dump_traces() to try and + // keep the system stats as close to its initial state as possible. + run_command_as_shell("DUMPSYS MEMINFO", 30, "dumpsys", "-t", "30", "meminfo", "-a", NULL); + run_command_as_shell("DUMPSYS CPUINFO", 10, "dumpsys", "-t", "10", "cpuinfo", "-a", NULL); + + /* collect stack traces from Dalvik and native processes (needs root) */ + dump_traces_path = dump_traces(); + + /* Run some operations that require root. */ + get_tombstone_fds(tombstone_data); + add_dir(RECOVERY_DIR, true); + add_dir(RECOVERY_DATA_DIR, true); + add_dir(LOGPERSIST_DATA_DIR, false); + if (!is_user_build()) { + add_dir(PROFILE_DATA_DIR_CUR, true); + add_dir(PROFILE_DATA_DIR_REF, true); + } + add_mountinfo(); + dump_iptables(); - /* Run some operations that require root. */ - get_tombstone_fds(tombstone_data); - add_dir(RECOVERY_DIR, true); - add_dir(RECOVERY_DATA_DIR, true); - add_dir(LOGPERSIST_DATA_DIR, false); - if (!is_user_build()) { - add_dir(PROFILE_DATA_DIR_CUR, true); - add_dir(PROFILE_DATA_DIR_REF, true); - } - 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); - // 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); - // Run ss as root so we can see socket marks. - run_command("DETAILED SOCKET STATE", 10, "ss", "-eionptu", NULL); + if (!drop_root_user()) { + return -1; + } - if (!drop_root_user()) { - return -1; + dumpstate(do_early_screenshot ? "": screenshot_path, version); } - dumpstate(do_early_screenshot ? "": screenshot_path, version); - /* close output if needed */ if (is_redirecting) { fclose(stdout); diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h index 5ed9023899..0b6aaab7ac 100644 --- a/cmds/dumpstate/dumpstate.h +++ b/cmds/dumpstate/dumpstate.h @@ -87,6 +87,9 @@ extern std::string bugreport_dir; /* root dir for all files copied as-is into the bugreport. */ extern const std::string ZIP_ROOT_DIR; +/* Checkes whether dumpstate is generating a zipped bugreport. */ +bool is_zipping(); + /* adds a new entry to the existing zip file. */ bool add_zip_entry(const std::string& entry_name, const std::string& entry_path); diff --git a/cmds/dumpstate/dumpstate.rc b/cmds/dumpstate/dumpstate.rc index 3448e91088..336db9fcd1 100644 --- a/cmds/dumpstate/dumpstate.rc +++ b/cmds/dumpstate/dumpstate.rc @@ -46,3 +46,11 @@ service bugreportwear /system/bin/dumpstate -d -B -P -p -z \ class main disabled oneshot + +# bugreportelefony is a lightweight version of bugreport that only includes a few, urgent +# sections used to report telephony bugs. +service bugreportelefony /system/bin/dumpstate -t -d -B -z \ + -o /data/user_de/0/com.android.shell/files/bugreports/bugreport + class main + disabled + oneshot diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp index bbe48be1ce..6ec636e029 100644 --- a/cmds/dumpstate/utils.cpp +++ b/cmds/dumpstate/utils.cpp @@ -829,8 +829,7 @@ bool drop_root_user() { } gid_t groups[] = { AID_LOG, AID_SDCARD_R, AID_SDCARD_RW, - AID_MOUNT, AID_INET, AID_NET_BW_STATS, AID_READPROC, AID_WAKELOCK, - AID_BLUETOOTH }; + AID_MOUNT, AID_INET, AID_NET_BW_STATS, AID_READPROC, AID_BLUETOOTH }; if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) { MYLOGE("Unable to setgroups, aborting: %s\n", strerror(errno)); return false; @@ -851,10 +850,8 @@ bool drop_root_user() { capheader.version = _LINUX_CAPABILITY_VERSION_3; capheader.pid = 0; - capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted = - (CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_BLOCK_SUSPEND)); - capdata[CAP_TO_INDEX(CAP_SYSLOG)].effective = - (CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_BLOCK_SUSPEND)); + capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted = CAP_TO_MASK(CAP_SYSLOG); + capdata[CAP_TO_INDEX(CAP_SYSLOG)].effective = CAP_TO_MASK(CAP_SYSLOG); capdata[0].inheritable = 0; capdata[1].inheritable = 0; diff --git a/data/etc/android.hardware.sensor.heartrate.fitness.xml b/data/etc/android.hardware.sensor.heartrate.fitness.xml new file mode 100644 index 0000000000..aef77b495e --- /dev/null +++ b/data/etc/android.hardware.sensor.heartrate.fitness.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<!-- Feature for devices supporting a fitness heart rate monitor --> +<permissions> + <feature name="android.hardware.sensor.heartrate.fitness" /> +</permissions> diff --git a/data/etc/handheld_core_hardware.xml b/data/etc/handheld_core_hardware.xml index 9cb4d6d480..f9464e8c55 100644 --- a/data/etc/handheld_core_hardware.xml +++ b/data/etc/handheld_core_hardware.xml @@ -50,8 +50,8 @@ <!-- Feature to specify if the device support managed users. --> <feature name="android.software.managed_users" /> - <!-- Feature to specify if the device supports a VR mode. --> - <feature name="android.software.vr.mode" /> + <!-- Feature to specify if the device supports a VR mode. + feature name="android.software.vr.mode" --> <!-- Devices with all optimizations required to be a "VR Ready" device that pass all CTS tests for this feature must include feature android.hardware.vr.high_performance --> diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index 74e75d74fc..b0d53ef5c8 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h @@ -681,8 +681,16 @@ status_t Parcel::unsafeReadTypedVector( return UNEXPECTED_NULL; } + if (val->max_size() < static_cast<size_t>(size)) { + return NO_MEMORY; + } + val->resize(static_cast<size_t>(size)); + if (val->size() < static_cast<size_t>(size)) { + return NO_MEMORY; + } + for (auto& v: *val) { status = (this->*read_func)(&v); diff --git a/include/gui/GraphicsEnv.h b/include/gui/GraphicsEnv.h new file mode 100644 index 0000000000..4c7366f094 --- /dev/null +++ b/include/gui/GraphicsEnv.h @@ -0,0 +1,59 @@ +/* + * Copyright 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_GUI_GRAPHICS_ENV_H +#define ANDROID_GUI_GRAPHICS_ENV_H 1 + +#include <string> + +struct android_namespace_t; + +namespace android { + +class GraphicsEnv { +public: + static GraphicsEnv& getInstance(); + + // Set a search path for loading graphics drivers. The path is a list of + // directories separated by ':'. A directory can be contained in a zip file + // (drivers must be stored uncompressed and page aligned); such elements + // in the search path must have a '!' after the zip filename, e.g. + // /data/app/com.example.driver/base.apk!/lib/arm64-v8a + void setDriverPath(const std::string path); + android_namespace_t* getDriverNamespace(); + +private: + GraphicsEnv() = default; + std::string mDriverPath; + android_namespace_t* mDriverNamespace = nullptr; +}; + +} // namespace android + +/* FIXME + * Export an un-mangled function that just does + * return android::GraphicsEnv::getInstance().getDriverNamespace(); + * This allows libEGL to get the function pointer via dlsym, since it can't + * directly link against libgui. In a future release, we'll fix this so that + * libgui does not depend on graphics API libraries, and libEGL can link + * against it. The current dependencies from libgui -> libEGL are: + * - the GLConsumer class, which should be moved to its own library + * - the EGLsyncKHR synchronization in BufferQueue, which is deprecated and + * will be removed soon. + */ +extern "C" android_namespace_t* android_getDriverNamespace(); + +#endif // ANDROID_GUI_GRAPHICS_ENV_H diff --git a/include/ui/Fence.h b/include/ui/Fence.h index 2fbc9efb45..1df15f897c 100644 --- a/include/ui/Fence.h +++ b/include/ui/Fence.h @@ -27,6 +27,8 @@ #include <utils/String8.h> #include <utils/Timers.h> +#include <experimental/optional> + struct ANativeWindowBuffer; namespace android { @@ -96,16 +98,26 @@ public: // occurs then -1 is returned. nsecs_t getSignalTime() const; +#if __cplusplus > 201103L // hasSignaled returns whether the fence has signaled yet. Prefer this to // getSignalTime() or wait() if all you care about is whether the fence has - // signaled. - inline bool hasSignaled() { + // signaled. Returns an optional bool, which will have a value if there was + // no error. + inline std::experimental::optional<bool> hasSignaled() { // The sync_wait call underlying wait() has been measured to be // significantly faster than the sync_fence_info call underlying // getSignalTime(), which might otherwise appear to be the more obvious // way to check whether a fence has signaled. - return wait(0) == NO_ERROR; + switch (wait(0)) { + case NO_ERROR: + return true; + case -ETIME: + return false; + default: + return {}; + } } +#endif // Flattenable interface size_t getFlattenedSize() const; diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index 2062b3b509..3aeff2eda3 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -135,10 +135,12 @@ public: { unsigned n; for (n = 0; n < 5; n++){ + if (n > 0) { + ALOGI("Waiting for service %s...", String8(name).string()); + sleep(1); + } sp<IBinder> svc = checkService(name); if (svc != NULL) return svc; - ALOGI("Waiting for service %s...\n", String8(name).string()); - sleep(1); } return NULL; } diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 061cb08fde..d753eb5fa8 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -514,7 +514,7 @@ status_t Parcel::appendFrom(const Parcel *parcel, size_t offset, size_t len) // grow objects if (mObjectsCapacity < mObjectsSize + numObjects) { size_t newSize = ((mObjectsSize + numObjects)*3)/2; - if (newSize < mObjectsSize) return NO_MEMORY; // overflow + if (newSize*sizeof(binder_size_t) < mObjectsSize) return NO_MEMORY; // overflow binder_size_t *objects = (binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t)); if (objects == (binder_size_t*)0) { @@ -1308,7 +1308,7 @@ restart_write: } if (!enoughObjects) { size_t newSize = ((mObjectsSize+2)*3)/2; - if (newSize < mObjectsSize) return NO_MEMORY; // overflow + if (newSize*sizeof(binder_size_t) < mObjectsSize) return NO_MEMORY; // overflow binder_size_t* objects = (binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t)); if (objects == NULL) return NO_MEMORY; mObjects = objects; diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp index 8e8bb802b3..7ac03f19d5 100644 --- a/libs/gui/Android.bp +++ b/libs/gui/Android.bp @@ -73,6 +73,7 @@ cc_library_shared { "DisplayEventReceiver.cpp", "GLConsumer.cpp", "GraphicBufferAlloc.cpp", + "GraphicsEnv.cpp", "GuiConfig.cpp", "IDisplayEventConnection.cpp", "IGraphicBufferAlloc.cpp", @@ -95,6 +96,7 @@ cc_library_shared { ], shared_libs: [ + "libnativeloader", "libbinder", "libcutils", "libEGL", diff --git a/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp index 7fbf312727..ee4c58cfce 100644 --- a/libs/gui/BufferQueueConsumer.cpp +++ b/libs/gui/BufferQueueConsumer.cpp @@ -716,6 +716,7 @@ status_t BufferQueueConsumer::setTransformHint(uint32_t hint) { } sp<NativeHandle> BufferQueueConsumer::getSidebandStream() const { + Mutex::Autolock lock(mCore->mMutex); return mCore->mSidebandStream; } diff --git a/libs/gui/BufferQueueCore.cpp b/libs/gui/BufferQueueCore.cpp index d74d32c06d..6e6cce28eb 100644 --- a/libs/gui/BufferQueueCore.cpp +++ b/libs/gui/BufferQueueCore.cpp @@ -93,6 +93,7 @@ BufferQueueCore::BufferQueueCore(const sp<IGraphicBufferAlloc>& allocator) : mSharedBufferSlot(INVALID_BUFFER_SLOT), mSharedBufferCache(Rect::INVALID_RECT, 0, NATIVE_WINDOW_SCALING_MODE_FREEZE, HAL_DATASPACE_UNKNOWN), + mLastQueuedSlot(INVALID_BUFFER_SLOT), mUniqueId(getUniqueId()) { if (allocator == NULL) { diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index f8f38725b5..13b900c837 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -1358,6 +1358,7 @@ status_t BufferQueueProducer::setGenerationNumber(uint32_t generationNumber) { String8 BufferQueueProducer::getConsumerName() const { ATRACE_CALL(); + Mutex::Autolock lock(mCore->mMutex); BQ_LOGV("getConsumerName: %s", mConsumerName.string()); return mConsumerName; } diff --git a/libs/gui/ConsumerBase.cpp b/libs/gui/ConsumerBase.cpp index 5546d5416c..3cf3078345 100644 --- a/libs/gui/ConsumerBase.cpp +++ b/libs/gui/ConsumerBase.cpp @@ -314,6 +314,18 @@ status_t ConsumerBase::addReleaseFenceLocked(int slot, if (!mSlots[slot].mFence.get()) { mSlots[slot].mFence = fence; + return OK; + } + + auto signaled = mSlots[slot].mFence->hasSignaled(); + + if (!signaled) { + CB_LOGE("fence has invalid state"); + return BAD_VALUE; + } + + if (*signaled) { + mSlots[slot].mFence = fence; } else { char fenceName[32] = {}; snprintf(fenceName, 32, "%.28s:%d", mName.string(), slot); diff --git a/libs/gui/GraphicsEnv.cpp b/libs/gui/GraphicsEnv.cpp new file mode 100644 index 0000000000..68f0f988e2 --- /dev/null +++ b/libs/gui/GraphicsEnv.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//#define LOG_NDEBUG 1 +#define LOG_TAG "GraphicsEnv" +#include <gui/GraphicsEnv.h> + +#include <mutex> + +#include <log/log.h> +#include <nativeloader/dlext_namespaces.h> + +namespace android { + +/*static*/ GraphicsEnv& GraphicsEnv::getInstance() { + static GraphicsEnv env; + return env; +} + +void GraphicsEnv::setDriverPath(const std::string path) { + if (!mDriverPath.empty()) { + ALOGV("ignoring attempt to change driver path from '%s' to '%s'", + mDriverPath.c_str(), path.c_str()); + return; + } + ALOGV("setting driver path to '%s'", path.c_str()); + mDriverPath = path; +} + +android_namespace_t* GraphicsEnv::getDriverNamespace() { + static std::once_flag once; + std::call_once(once, [this]() { + // TODO; In the next version of Android, all graphics drivers will be + // loaded into a custom namespace. To minimize risk for this release, + // only updated drivers use a custom namespace. + // + // Additionally, the custom namespace will be + // ANDROID_NAMESPACE_TYPE_ISOLATED, and will only have access to a + // subset of the system. + if (mDriverPath.empty()) + return; + + char defaultPath[PATH_MAX]; + android_get_LD_LIBRARY_PATH(defaultPath, sizeof(defaultPath)); + size_t defaultPathLen = strlen(defaultPath); + + std::string path; + path.reserve(mDriverPath.size() + 1 + defaultPathLen); + path.append(mDriverPath); + path.push_back(':'); + path.append(defaultPath, defaultPathLen); + + mDriverNamespace = android_create_namespace( + "gfx driver", + nullptr, // ld_library_path + path.c_str(), // default_library_path + ANDROID_NAMESPACE_TYPE_SHARED, + nullptr, // permitted_when_isolated_path + nullptr); // parent + }); + return mDriverNamespace; +} + +} // namespace android + +extern "C" android_namespace_t* android_getDriverNamespace() { + return android::GraphicsEnv::getInstance().getDriverNamespace(); +} diff --git a/libs/gui/SensorManager.cpp b/libs/gui/SensorManager.cpp index 5338034fd6..57c3073bf4 100644 --- a/libs/gui/SensorManager.cpp +++ b/libs/gui/SensorManager.cpp @@ -194,7 +194,8 @@ Sensor const* SensorManager::getDefaultSensor(int type) // a non_wake-up version. if (type == SENSOR_TYPE_PROXIMITY || type == SENSOR_TYPE_SIGNIFICANT_MOTION || type == SENSOR_TYPE_TILT_DETECTOR || type == SENSOR_TYPE_WAKE_GESTURE || - type == SENSOR_TYPE_GLANCE_GESTURE || type == SENSOR_TYPE_PICK_UP_GESTURE) { + type == SENSOR_TYPE_GLANCE_GESTURE || type == SENSOR_TYPE_PICK_UP_GESTURE || + type == SENSOR_TYPE_WRIST_TILT_GESTURE) { wakeUpSensor = true; } // For now we just return the first sensor of that type we find. diff --git a/libs/ui/Gralloc1On0Adapter.cpp b/libs/ui/Gralloc1On0Adapter.cpp index d5b88deb9a..ec7df31f9c 100644 --- a/libs/ui/Gralloc1On0Adapter.cpp +++ b/libs/ui/Gralloc1On0Adapter.cpp @@ -288,6 +288,7 @@ gralloc1_error_t Gralloc1On0Adapter::allocateWithIdHook( gralloc1_error_t Gralloc1On0Adapter::retain( const std::shared_ptr<Buffer>& buffer) { + std::lock_guard<std::mutex> lock(mBufferMutex); buffer->retain(); return GRALLOC1_ERROR_NONE; } @@ -295,6 +296,7 @@ gralloc1_error_t Gralloc1On0Adapter::retain( gralloc1_error_t Gralloc1On0Adapter::release( const std::shared_ptr<Buffer>& buffer) { + std::lock_guard<std::mutex> lock(mBufferMutex); if (!buffer->release()) { return GRALLOC1_ERROR_NONE; } @@ -314,7 +316,6 @@ gralloc1_error_t Gralloc1On0Adapter::release( } } - std::lock_guard<std::mutex> lock(mBufferMutex); mBuffers.erase(handle); return GRALLOC1_ERROR_NONE; } diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp index 218ab35696..69e3c130c7 100644 --- a/opengl/libs/EGL/Loader.cpp +++ b/opengl/libs/EGL/Loader.cpp @@ -14,6 +14,10 @@ ** limitations under the License. */ +//#define LOG_NDEBUG 0 +#define ATRACE_TAG ATRACE_TAG_GRAPHICS + +#include <array> #include <ctype.h> #include <dirent.h> #include <dlfcn.h> @@ -23,8 +27,10 @@ #include <stdlib.h> #include <string.h> +#include <android/dlext.h> #include <cutils/properties.h> #include <log/log.h> +#include <utils/Trace.h> #include <EGL/egl.h> @@ -114,6 +120,11 @@ static char const * getProcessCmdline() { return NULL; } +static void* do_dlopen(const char* path, int mode) { + ATRACE_CALL(); + return dlopen(path, mode); +} + // ---------------------------------------------------------------------------- Loader::driver_t::driver_t(void* gles) @@ -154,14 +165,30 @@ status_t Loader::driver_t::set(void* hnd, int32_t api) // ---------------------------------------------------------------------------- Loader::Loader() - : getProcAddress(NULL) { + : getProcAddress(NULL), + mLibGui(nullptr), + mGetDriverNamespace(nullptr) +{ + // FIXME: See note in GraphicsEnv.h about android_getDriverNamespace(). + // libgui should already be loaded in any process that uses libEGL, but + // if for some reason it isn't, then we're not going to get a driver + // namespace anyway, so don't force it to be loaded. + mLibGui = dlopen("libgui.so", RTLD_NOLOAD | RTLD_LOCAL | RTLD_LAZY); + if (!mLibGui) { + ALOGD("failed to load libgui: %s", dlerror()); + return; + } + mGetDriverNamespace = reinterpret_cast<decltype(mGetDriverNamespace)>( + dlsym(mLibGui, "android_getDriverNamespace")); } Loader::~Loader() { + if (mLibGui) + dlclose(mLibGui); } static void* load_wrapper(const char* path) { - void* so = dlopen(path, RTLD_NOW | RTLD_LOCAL); + void* so = do_dlopen(path, RTLD_NOW | RTLD_LOCAL); ALOGE_IF(!so, "dlopen(\"%s\") failed: %s", path, dlerror()); return so; } @@ -208,6 +235,8 @@ static void setEmulatorGlesValue(void) { void* Loader::open(egl_connection_t* cnx) { + ATRACE_CALL(); + void* dso; driver_t* hnd = 0; @@ -253,6 +282,8 @@ void Loader::init_api(void* dso, __eglMustCastToProperFunctionPointerType* curr, getProcAddressType getProcAddress) { + ATRACE_CALL(); + const ssize_t SIZE = 256; char scrap[SIZE]; while (*api) { @@ -304,9 +335,8 @@ void Loader::init_api(void* dso, } } -void *Loader::load_driver(const char* kind, - egl_connection_t* cnx, uint32_t mask) -{ +static void* load_system_driver(const char* kind) { + ATRACE_CALL(); class MatchFile { public: static String8 find(const char* kind) { @@ -422,7 +452,7 @@ void *Loader::load_driver(const char* kind, } const char* const driver_absolute_path = absolutePath.string(); - void* dso = dlopen(driver_absolute_path, RTLD_NOW | RTLD_LOCAL); + void* dso = do_dlopen(driver_absolute_path, RTLD_NOW | RTLD_LOCAL); if (dso == 0) { const char* err = dlerror(); ALOGE("load_driver(%s): %s", driver_absolute_path, err?err:"unknown"); @@ -431,11 +461,63 @@ void *Loader::load_driver(const char* kind, ALOGD("loaded %s", driver_absolute_path); + return dso; +} + +static void* do_android_dlopen_ext(const char* path, int mode, const android_dlextinfo* info) { + ATRACE_CALL(); + return android_dlopen_ext(path, mode, info); +} + +static const std::array<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{ + "ro.hardware.egl", + "ro.board.platform", +}}; + +static void* load_updated_driver(const char* kind, android_namespace_t* ns) { + ATRACE_CALL(); + const android_dlextinfo dlextinfo = { + .flags = ANDROID_DLEXT_USE_NAMESPACE, + .library_namespace = ns, + }; + void* so = nullptr; + char prop[PROPERTY_VALUE_MAX + 1]; + for (auto key : HAL_SUBNAME_KEY_PROPERTIES) { + if (property_get(key, prop, nullptr) > 0) { + String8 name; + name.appendFormat("lib%s_%s.so", kind, prop); + so = do_android_dlopen_ext(name.string(), RTLD_LOCAL | RTLD_NOW, + &dlextinfo); + if (so) + return so; + } + } + return nullptr; +} + +void *Loader::load_driver(const char* kind, + egl_connection_t* cnx, uint32_t mask) +{ + ATRACE_CALL(); + + void* dso = nullptr; + if (mGetDriverNamespace) { + android_namespace_t* ns = mGetDriverNamespace(); + if (ns) { + dso = load_updated_driver(kind, ns); + } + } + if (!dso) { + dso = load_system_driver(kind); + if (!dso) + return NULL; + } + if (mask & EGL) { getProcAddress = (getProcAddressType)dlsym(dso, "eglGetProcAddress"); ALOGE_IF(!getProcAddress, - "can't find eglGetProcAddress() in %s", driver_absolute_path); + "can't find eglGetProcAddress() in EGL driver library"); egl_t* egl = &cnx->egl; __eglMustCastToProperFunctionPointerType* curr = diff --git a/opengl/libs/EGL/Loader.h b/opengl/libs/EGL/Loader.h index 94f680e9ea..d0435e7ea0 100644 --- a/opengl/libs/EGL/Loader.h +++ b/opengl/libs/EGL/Loader.h @@ -25,6 +25,8 @@ #include <utils/Singleton.h> #include <utils/String8.h> +#include <gui/GraphicsEnv.h> + #include <EGL/egl.h> // ---------------------------------------------------------------------------- @@ -53,7 +55,10 @@ class Loader : public Singleton<Loader> }; getProcAddressType getProcAddress; - + + void* mLibGui; + decltype(android_getDriverNamespace)* mGetDriverNamespace; + public: ~Loader(); diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp index a42b3f1cb0..f8e25b4891 100644 --- a/opengl/libs/EGL/eglApi.cpp +++ b/opengl/libs/EGL/eglApi.cpp @@ -267,6 +267,7 @@ static inline EGLContext getContext() { return egl_tls_t::getContext(); } EGLDisplay eglGetDisplay(EGLNativeDisplayType display) { + ATRACE_CALL(); clearError(); uintptr_t index = reinterpret_cast<uintptr_t>(display); diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp index a32f0378be..d7df40c086 100644 --- a/opengl/libs/EGL/egl_display.cpp +++ b/opengl/libs/EGL/egl_display.cpp @@ -15,6 +15,7 @@ */ #define __STDC_LIMIT_MACROS 1 +#define ATRACE_TAG ATRACE_TAG_GRAPHICS #include <string.h> @@ -26,6 +27,7 @@ #include "egl_tls.h" #include "Loader.h" #include <cutils/properties.h> +#include <utils/Trace.h> // ---------------------------------------------------------------------------- namespace android { @@ -103,6 +105,7 @@ EGLDisplay egl_display_t::getFromNativeDisplay(EGLNativeDisplayType disp) { EGLDisplay egl_display_t::getDisplay(EGLNativeDisplayType display) { Mutex::Autolock _l(lock); + ATRACE_CALL(); // get our driver loader Loader& loader(Loader::getInstance()); diff --git a/services/sensorservice/BatteryService.cpp b/services/sensorservice/BatteryService.cpp index 81f32cdc58..452c8c64b0 100644 --- a/services/sensorservice/BatteryService.cpp +++ b/services/sensorservice/BatteryService.cpp @@ -30,12 +30,7 @@ namespace android { // --------------------------------------------------------------------------- -BatteryService::BatteryService() { - const sp<IServiceManager> sm(defaultServiceManager()); - if (sm != NULL) { - const String16 name("batterystats"); - mBatteryStatService = interface_cast<IBatteryStats>(sm->getService(name)); - } +BatteryService::BatteryService() : mBatteryStatService(nullptr) { } bool BatteryService::addSensor(uid_t uid, int handle) { @@ -61,7 +56,7 @@ bool BatteryService::removeSensor(uid_t uid, int handle) { void BatteryService::enableSensorImpl(uid_t uid, int handle) { - if (mBatteryStatService != 0) { + if (checkService()) { if (addSensor(uid, handle)) { int64_t identity = IPCThreadState::self()->clearCallingIdentity(); mBatteryStatService->noteStartSensor(uid, handle); @@ -70,7 +65,7 @@ void BatteryService::enableSensorImpl(uid_t uid, int handle) { } } void BatteryService::disableSensorImpl(uid_t uid, int handle) { - if (mBatteryStatService != 0) { + if (checkService()) { if (removeSensor(uid, handle)) { int64_t identity = IPCThreadState::self()->clearCallingIdentity(); mBatteryStatService->noteStopSensor(uid, handle); @@ -80,7 +75,7 @@ void BatteryService::disableSensorImpl(uid_t uid, int handle) { } void BatteryService::cleanupImpl(uid_t uid) { - if (mBatteryStatService != 0) { + if (checkService()) { Mutex::Autolock _l(mActivationsLock); int64_t identity = IPCThreadState::self()->clearCallingIdentity(); for (size_t i=0 ; i<mActivations.size() ; i++) { @@ -95,6 +90,17 @@ void BatteryService::cleanupImpl(uid_t uid) { } } +bool BatteryService::checkService() { + if (mBatteryStatService == nullptr) { + const sp<IServiceManager> sm(defaultServiceManager()); + if (sm != NULL) { + const String16 name("batterystats"); + mBatteryStatService = interface_cast<IBatteryStats>(sm->getService(name)); + } + } + return mBatteryStatService != nullptr; +} + ANDROID_SINGLETON_STATIC_INSTANCE(BatteryService) // --------------------------------------------------------------------------- diff --git a/services/sensorservice/BatteryService.h b/services/sensorservice/BatteryService.h index 08ba857518..43a750c6c2 100644 --- a/services/sensorservice/BatteryService.h +++ b/services/sensorservice/BatteryService.h @@ -49,6 +49,7 @@ class BatteryService : public Singleton<BatteryService> { SortedVector<Info> mActivations; bool addSensor(uid_t uid, int handle); bool removeSensor(uid_t uid, int handle); + bool checkService(); public: static void enableSensor(uid_t uid, int handle) { diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index d13b6dbe19..1b9067833e 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -1362,6 +1362,7 @@ void Layer::pushPendingState() { // Wake us up to check if the frame has been received setTransactionFlags(eTransactionNeeded); + mFlinger->setTransactionFlags(eTraversalNeeded); } mPendingStates.push_back(mCurrentState); } diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 5eea3d9750..deeb45649d 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2292,8 +2292,7 @@ void SurfaceFlinger::setTransactionState( if (s.client != NULL) { sp<IBinder> binder = IInterface::asBinder(s.client); if (binder != NULL) { - String16 desc(binder->getInterfaceDescriptor()); - if (desc == ISurfaceComposerClient::descriptor) { + if (binder->queryLocalInterface(ISurfaceComposerClient::descriptor) != NULL) { sp<Client> client( static_cast<Client *>(s.client.get()) ); transactionFlags |= setClientStateLocked(client, s.state); } diff --git a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp index 6710bca34e..2d36b543a2 100644 --- a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp +++ b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp @@ -2203,8 +2203,7 @@ void SurfaceFlinger::setTransactionState( if (s.client != NULL) { sp<IBinder> binder = IInterface::asBinder(s.client); if (binder != NULL) { - String16 desc(binder->getInterfaceDescriptor()); - if (desc == ISurfaceComposerClient::descriptor) { + if (binder->queryLocalInterface(ISurfaceComposerClient::descriptor) != NULL) { sp<Client> client( static_cast<Client *>(s.client.get()) ); transactionFlags |= setClientStateLocked(client, s.state); } diff --git a/vulkan/libvulkan/Android.bp b/vulkan/libvulkan/Android.bp index 147cc56467..70c7e75875 100644 --- a/vulkan/libvulkan/Android.bp +++ b/vulkan/libvulkan/Android.bp @@ -69,6 +69,7 @@ cc_library_shared { "libziparchive", ], shared_libs: [ + "libgui", "libhardware", "libsync", "libbase", diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 56396f467f..f9d3de1e64 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -21,10 +21,15 @@ #include <algorithm> #include <array> +#include <dlfcn.h> #include <new> #include <log/log.h> +#include <android/dlext.h> +#include <cutils/properties.h> +#include <gui/GraphicsEnv.h> + #include "driver.h" #include "stubhal.h" @@ -126,17 +131,74 @@ class CreateInfoWrapper { Hal Hal::hal_; +void* LoadLibrary(const android_dlextinfo& dlextinfo, + const char* subname, + int subname_len) { + const char kLibFormat[] = "vulkan.%*s.so"; + char* name = static_cast<char*>( + alloca(sizeof(kLibFormat) + static_cast<size_t>(subname_len))); + sprintf(name, kLibFormat, subname_len, subname); + return android_dlopen_ext(name, RTLD_LOCAL | RTLD_NOW, &dlextinfo); +} + +const std::array<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{ + "ro.hardware." HWVULKAN_HARDWARE_MODULE_ID, + "ro.board.platform", +}}; + +int LoadUpdatedDriver(const hw_module_t** module) { + const android_dlextinfo dlextinfo = { + .flags = ANDROID_DLEXT_USE_NAMESPACE, + .library_namespace = android::GraphicsEnv::getInstance().getDriverNamespace(), + }; + if (!dlextinfo.library_namespace) + return -ENOENT; + + void* so = nullptr; + char prop[PROPERTY_VALUE_MAX]; + for (auto key : HAL_SUBNAME_KEY_PROPERTIES) { + int prop_len = property_get(key, prop, nullptr); + if (prop_len > 0) { + so = LoadLibrary(dlextinfo, prop, prop_len); + if (so) + break; + } + } + if (!so) + return -ENOENT; + + hw_module_t* hmi = static_cast<hw_module_t*>(dlsym(so, HAL_MODULE_INFO_SYM_AS_STR)); + if (!hmi) { + ALOGE("couldn't find symbol '%s' in HAL library: %s", HAL_MODULE_INFO_SYM_AS_STR, dlerror()); + dlclose(so); + return -EINVAL; + } + if (strcmp(hmi->id, HWVULKAN_HARDWARE_MODULE_ID) != 0) { + ALOGE("HAL id '%s' != '%s'", hmi->id, HWVULKAN_HARDWARE_MODULE_ID); + dlclose(so); + return -EINVAL; + } + hmi->dso = so; + *module = hmi; + ALOGD("loaded updated driver"); + return 0; +} + bool Hal::Open() { ALOG_ASSERT(!hal_.dev_, "OpenHAL called more than once"); // Use a stub device unless we successfully open a real HAL device. hal_.dev_ = &stubhal::kDevice; - const hwvulkan_module_t* module; - int result = - hw_get_module("vulkan", reinterpret_cast<const hw_module_t**>(&module)); + int result; + const hwvulkan_module_t* module = nullptr; + + result = LoadUpdatedDriver(reinterpret_cast<const hw_module_t**>(&module)); + if (result == -ENOENT) { + result = hw_get_module(HWVULKAN_HARDWARE_MODULE_ID, reinterpret_cast<const hw_module_t**>(&module)); + } if (result != 0) { - ALOGI("no Vulkan HAL present, using stub HAL"); + ALOGV("unable to load Vulkan HAL, using stub HAL (result=%d)", result); return true; } |