From a35249569e550bc674d7956073ba7292386c0879 Mon Sep 17 00:00:00 2001 From: Riley Andrews Date: Tue, 15 Jul 2014 20:39:41 -0700 Subject: [PATCH 001/243] Remove the /dev/.booting file before triggering boot. On mako only, there is a race condition such that core + main services must be started after releasing ueventd (by removing /dev/.booting). bug 16304711 bug 16333352 --- rootdir/init.rc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rootdir/init.rc b/rootdir/init.rc index bbce64ff..8eef76b3 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -184,11 +184,12 @@ on late-init # issued fs triggers have completed. trigger load_all_props_action + # Remove a file to wake up anything waiting for firmware. + trigger firmware_mounts_complete + trigger early-boot trigger boot - # Remove a file to wake up anything waiting for firmware - trigger firmware_mounts_complete on post-fs # once everything is setup, no need to modify / From ef3e3a30476417073105ac436811b247a85c8502 Mon Sep 17 00:00:00 2001 From: Riley Andrews Date: Tue, 15 Jul 2014 20:39:41 -0700 Subject: [PATCH 002/243] Remove the /dev/.booting file before triggering boot. On mako only, there is a race condition such that core + main services must be started after releasing ueventd (by removing /dev/.booting). bug 16304711 bug 16333352 --- rootdir/init.rc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rootdir/init.rc b/rootdir/init.rc index bbce64ff..8eef76b3 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -184,11 +184,12 @@ on late-init # issued fs triggers have completed. trigger load_all_props_action + # Remove a file to wake up anything waiting for firmware. + trigger firmware_mounts_complete + trigger early-boot trigger boot - # Remove a file to wake up anything waiting for firmware - trigger firmware_mounts_complete on post-fs # once everything is setup, no need to modify / From 767dee2d39cbd10d13c2abe51f62d5986ca66e43 Mon Sep 17 00:00:00 2001 From: Jon Eklund Date: Fri, 20 Jun 2014 16:03:18 -0500 Subject: [PATCH 003/243] audio.h: Add "safe speaker" device for limited-loudness use cases Bug: 17319721 Change-Id: Ie1af5b73258f8a0009c3bc3cecb3e0e8b2262ed7 --- include/system/audio.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/system/audio.h b/include/system/audio.h index 1c702402..0eb28b00 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -585,6 +585,8 @@ enum { AUDIO_DEVICE_OUT_FM = 0x100000, /* Line out for av devices */ AUDIO_DEVICE_OUT_AUX_LINE = 0x200000, + /* limited-output speaker device for acoustic safety */ + AUDIO_DEVICE_OUT_SPEAKER_SAFE = 0x400000, AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT, AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE | AUDIO_DEVICE_OUT_SPEAKER | @@ -608,6 +610,7 @@ enum { AUDIO_DEVICE_OUT_SPDIF | AUDIO_DEVICE_OUT_FM | AUDIO_DEVICE_OUT_AUX_LINE | + AUDIO_DEVICE_OUT_SPEAKER_SAFE | AUDIO_DEVICE_OUT_DEFAULT), AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | From 66d2f07a0f94055d65b94707646f471df3e74137 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Wed, 15 Oct 2014 23:38:17 -0700 Subject: [PATCH 004/243] Fix toolchain issue for windows build of libziparchive. With mingw 4.8, the new default packed behavior is broken and makes zip archive fails due to unexpected misalignment in CentralDirectoryRecord. This patch uses -mno-ms-bitfields to revert to the old packed behavior. Change-Id: Ic977c841e330e19451db1d31ddb22e570a525062 --- libziparchive/Android.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libziparchive/Android.mk b/libziparchive/Android.mk index 705caa5a..d23a94fd 100644 --- a/libziparchive/Android.mk +++ b/libziparchive/Android.mk @@ -42,6 +42,9 @@ LOCAL_C_INCLUDES += ${includes} LOCAL_STATIC_LIBRARIES := libz libutils LOCAL_MODULE:= libziparchive-host LOCAL_CFLAGS := -Werror +ifneq ($(strip $(USE_MINGW)),) + LOCAL_CFLAGS += -mno-ms-bitfields +endif LOCAL_MULTILIB := both include $(BUILD_HOST_STATIC_LIBRARY) From 784534195536871b623691fa3505f5773b1c79f0 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Thu, 16 Oct 2014 10:14:58 -0700 Subject: [PATCH 005/243] Fix windows specific behavior of FileMap The implementation of the FileMap destructor would close the file, only on Windows, which did not match the behavior on mac/linux. This is because calling munmap does not close the file descriptor. It must be closed separately, before or after munmap. On Windows, the file must also be closed manually, before or after closing the mappingFile. The change basically removes the closing file from the windows-specific part of the destructor, to make behavior more consistent on all platforms where the caller to FileMap is responsible for closing its own file (since FileMap receives an opened file). Change-Id: I5e3cfffbb870d5f3595802ccac57dbc1dbf1ce6e --- libutils/FileMap.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libutils/FileMap.cpp b/libutils/FileMap.cpp index be4b14fe..f8d6bdab 100644 --- a/libutils/FileMap.cpp +++ b/libutils/FileMap.cpp @@ -77,7 +77,6 @@ FileMap::~FileMap(void) if (mFileMapping != INVALID_HANDLE_VALUE) { CloseHandle(mFileMapping); } - CloseHandle(mFileHandle); #endif } From f9dd85bba130eb9d10318e01a7fbd8792846358d Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sat, 14 Jan 2012 17:04:22 -0800 Subject: [PATCH 006/243] adbd: Disable "adb root" by system property (2/3) * Require persist.sys.root_access=1 on non-eng debuggable builds Change-Id: Iedab030e81ffb525fed64aed80cf0014f3e07073 --- adb/services.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/adb/services.c b/adb/services.c index e61371ab..cd5c81ae 100644 --- a/adb/services.c +++ b/adb/services.c @@ -61,6 +61,8 @@ void restart_root_service(int fd, void *cookie) { char buf[100]; char value[PROPERTY_VALUE_MAX]; + char build_type[PROPERTY_VALUE_MAX]; + char cm_version[PROPERTY_VALUE_MAX]; if (getuid() == 0) { snprintf(buf, sizeof(buf), "adbd is already running as root\n"); @@ -75,6 +77,17 @@ void restart_root_service(int fd, void *cookie) return; } + property_get("persist.sys.root_access", value, "1"); + property_get("ro.build.type", build_type, ""); + property_get("ro.cm.version", cm_version, ""); + + if (strlen(cm_version) > 0 && strcmp(build_type, "eng") != 0 && (atoi(value) & 2) != 2) { + snprintf(buf, sizeof(buf), "root access is disabled by system setting - enable in settings -> development options\n"); + writex(fd, buf, strlen(buf)); + adb_close(fd); + return; + } + property_set("service.adb.root", "1"); snprintf(buf, sizeof(buf), "restarting adbd as root\n"); writex(fd, buf, strlen(buf)); From b26a13bc373407fd0a2666d0f866fbd84b1bd74f Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sat, 13 Apr 2013 07:07:11 -0700 Subject: [PATCH 007/243] adb: Add "wait-for-sideload" command * Waits for connected device to enter sideload mode Change-Id: I65b4ad86456c13a3bbc48880e12ab7a034707b88 --- adb/services.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adb/services.c b/adb/services.c index cd5c81ae..1993b82b 100644 --- a/adb/services.c +++ b/adb/services.c @@ -661,6 +661,9 @@ asocket* host_service_to_socket(const char* name, const char *serial) } else if (!strncmp(name, "any", strlen("any"))) { sinfo->transport = kTransportAny; sinfo->state = CS_DEVICE; + } else if (!strncmp(name, "sideload", strlen("sideload"))) { + sinfo->transport = kTransportAny; + sinfo->state = CS_SIDELOAD; } else { free(sinfo); return NULL; From 3c7db90caa9bd45c7b6bbc0eefc105433357cebf Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sat, 13 Apr 2013 13:16:55 -0700 Subject: [PATCH 008/243] adb: Add a few more wait-for commands * wait-for-recovery is obvious. * wait-for-online will wait for recovery || device Change-Id: I70f747bcd201a4157b988d7ed49bcc8e5ff4c85f --- adb/adb.h | 2 ++ adb/services.c | 6 ++++++ adb/transport.c | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/adb/adb.h b/adb/adb.h index 4f068000..1097123e 100644 --- a/adb/adb.h +++ b/adb/adb.h @@ -390,6 +390,8 @@ int connection_state(atransport *t); #define CS_SIDELOAD 6 #define CS_UNAUTHORIZED 7 +#define CS_ONLINE 10 /* recovery or device */ + extern int HOST; extern int SHELL_EXIT_NOTIFY_FD; diff --git a/adb/services.c b/adb/services.c index 1993b82b..57182da0 100644 --- a/adb/services.c +++ b/adb/services.c @@ -664,6 +664,12 @@ asocket* host_service_to_socket(const char* name, const char *serial) } else if (!strncmp(name, "sideload", strlen("sideload"))) { sinfo->transport = kTransportAny; sinfo->state = CS_SIDELOAD; + } else if (!strncmp(name, "recovery", strlen("recovery"))) { + sinfo->transport = kTransportAny; + sinfo->state = CS_RECOVERY; + } else if (!strncmp(name, "online", strlen("online"))) { + sinfo->transport = kTransportAny; + sinfo->state = CS_ONLINE; } else { free(sinfo); return NULL; diff --git a/adb/transport.c b/adb/transport.c index f35880cc..30c068f2 100644 --- a/adb/transport.c +++ b/adb/transport.c @@ -871,8 +871,11 @@ atransport *acquire_one_transport(int state, transport_type ttype, const char* s *error_out = "device offline"; result = NULL; } + /* check for required connection state */ - if (result && state != CS_ANY && result->connection_state != state) { + if (result && state != CS_ANY && ((state != CS_ONLINE && result->connection_state != state) + || (state == CS_ONLINE && !(result->connection_state == CS_DEVICE + || result->connection_state == CS_RECOVERY)))) { if (error_out) *error_out = "invalid device state"; result = NULL; From 1620191960bf194792e60e7b4579581901db2051 Mon Sep 17 00:00:00 2001 From: Pierre Zurek Date: Sun, 17 Oct 2010 22:39:37 +0200 Subject: [PATCH 009/243] ADB Logcat colored output. This patch adds a new '-C' option to logcat so that the output is colored with colors similar to the ones in DDMS. Simply type "adb logcat -C" to use it. Works well with bash in gnome-terminal. Change-Id: Ie72199ecca0e04f2082c993f5763646bb09da61ea --- include/log/logprint.h | 7 ++++ liblog/logprint.c | 83 +++++++++++++++++++++++++++++++++++------- logcat/logcat.cpp | 12 +++++- 3 files changed, 87 insertions(+), 15 deletions(-) diff --git a/include/log/logprint.h b/include/log/logprint.h index 481c96e2..a7a9cd6e 100644 --- a/include/log/logprint.h +++ b/include/log/logprint.h @@ -38,6 +38,11 @@ typedef enum { FORMAT_LONG, } AndroidLogPrintFormat; +typedef enum { + OUTPUT_COLOR_ON = 0, + OUTPUT_COLOR_OFF, +} AndroidLogColoredOutput; + typedef struct AndroidLogFormat_t AndroidLogFormat; typedef struct AndroidLogEntry_t { @@ -58,6 +63,8 @@ void android_log_format_free(AndroidLogFormat *p_format); void android_log_setPrintFormat(AndroidLogFormat *p_format, AndroidLogPrintFormat format); +void android_log_setColoredOutput(AndroidLogFormat *p_format); + /** * Returns FORMAT_OFF on invalid string */ diff --git a/liblog/logprint.c b/liblog/logprint.c index 08e830ac..8851b11a 100644 --- a/liblog/logprint.c +++ b/liblog/logprint.c @@ -17,8 +17,16 @@ #define _GNU_SOURCE /* for asprintf */ +#define COLOR_BLUE 75 +#define COLOR_DEFAULT 231 +#define COLOR_GREEN 40 +#define COLOR_ORANGE 166 +#define COLOR_RED 196 +#define COLOR_YELLOW 226 + #include #include + #include #include #include @@ -39,6 +47,7 @@ struct AndroidLogFormat_t { android_LogPriority global_pri; FilterInfo *filters; AndroidLogPrintFormat format; + AndroidLogColoredOutput colored_output; }; static FilterInfo * filterinfo_new(const char * tag, android_LogPriority pri) @@ -110,6 +119,23 @@ static char filterPriToChar (android_LogPriority pri) } } +static int colorFromPri (android_LogPriority pri) +{ + switch (pri) { + case ANDROID_LOG_VERBOSE: return COLOR_DEFAULT; + case ANDROID_LOG_DEBUG: return COLOR_BLUE; + case ANDROID_LOG_INFO: return COLOR_GREEN; + case ANDROID_LOG_WARN: return COLOR_ORANGE; + case ANDROID_LOG_ERROR: return COLOR_RED; + case ANDROID_LOG_FATAL: return COLOR_RED; + case ANDROID_LOG_SILENT: return COLOR_DEFAULT; + + case ANDROID_LOG_DEFAULT: + case ANDROID_LOG_UNKNOWN: + default: return COLOR_DEFAULT; + } +} + static android_LogPriority filterPriForTag( AndroidLogFormat *p_format, const char *tag) { @@ -149,6 +175,7 @@ AndroidLogFormat *android_log_format_new() p_ret->global_pri = ANDROID_LOG_VERBOSE; p_ret->format = FORMAT_BRIEF; + p_ret->colored_output = OUTPUT_COLOR_OFF; return p_ret; } @@ -177,6 +204,11 @@ void android_log_setPrintFormat(AndroidLogFormat *p_format, p_format->format=format; } +void android_log_setColoredOutput(AndroidLogFormat *p_format) +{ + p_format->colored_output = OUTPUT_COLOR_ON; +} + /** * Returns FORMAT_OFF on invalid string */ @@ -721,20 +753,32 @@ char *android_log_formatLogLine ( */ size_t prefixLen, suffixLen; + size_t prefixColorLen = 0; + char * prefixBufTmp = prefixBuf; + size_t prefixBufTmpRemainLen = sizeof(prefixBuf); + + if (p_format->colored_output == OUTPUT_COLOR_ON) { + prefixColorLen = snprintf(prefixBufTmp, prefixBufTmpRemainLen, "%c[%d;%d;%dm", 0x1B, 38, 5, colorFromPri(entry->priority)); + if(prefixColorLen >= prefixBufTmpRemainLen) + prefixColorLen = prefixBufTmpRemainLen - 1; + prefixBufTmp += prefixColorLen; + prefixBufTmpRemainLen -= prefixColorLen; + } + switch (p_format->format) { case FORMAT_TAG: - prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), + prefixLen = snprintf(prefixBufTmp, prefixBufTmpRemainLen, "%c/%-8s: ", priChar, entry->tag); strcpy(suffixBuf, "\n"); suffixLen = 1; break; case FORMAT_PROCESS: - prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), + prefixLen = snprintf(prefixBufTmp, prefixBufTmpRemainLen, "%c(%5d) ", priChar, entry->pid); suffixLen = snprintf(suffixBuf, sizeof(suffixBuf), " (%s)\n", entry->tag); break; case FORMAT_THREAD: - prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), + prefixLen = snprintf(prefixBufTmp, prefixBufTmpRemainLen, "%c(%5d:%5d) ", priChar, entry->pid, entry->tid); strcpy(suffixBuf, "\n"); suffixLen = 1; @@ -746,21 +790,21 @@ char *android_log_formatLogLine ( suffixLen = 1; break; case FORMAT_TIME: - prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), + prefixLen = snprintf(prefixBufTmp, prefixBufTmpRemainLen, "%s.%03ld %c/%-8s(%5d): ", timeBuf, entry->tv_nsec / 1000000, priChar, entry->tag, entry->pid); strcpy(suffixBuf, "\n"); suffixLen = 1; break; case FORMAT_THREADTIME: - prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), + prefixLen = snprintf(prefixBufTmp, prefixBufTmpRemainLen, "%s.%03ld %5d %5d %c %-8s: ", timeBuf, entry->tv_nsec / 1000000, entry->pid, entry->tid, priChar, entry->tag); strcpy(suffixBuf, "\n"); suffixLen = 1; break; case FORMAT_LONG: - prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), + prefixLen = snprintf(prefixBufTmp, prefixBufTmpRemainLen, "[ %s.%03ld %5d:%5d %c/%-8s ]\n", timeBuf, entry->tv_nsec / 1000000, entry->pid, entry->tid, priChar, entry->tag); @@ -770,7 +814,7 @@ char *android_log_formatLogLine ( break; case FORMAT_BRIEF: default: - prefixLen = snprintf(prefixBuf, sizeof(prefixBuf), + prefixLen = snprintf(prefixBufTmp, prefixBufTmpRemainLen, "%c/%-8s(%5d): ", priChar, entry->tag, entry->pid); strcpy(suffixBuf, "\n"); suffixLen = 1; @@ -782,11 +826,22 @@ char *android_log_formatLogLine ( * possibly causing heap corruption. To avoid this we double check and * set the length at the maximum (size minus null byte) */ - if(prefixLen >= sizeof(prefixBuf)) - prefixLen = sizeof(prefixBuf) - 1; + if(prefixLen >= prefixBufTmpRemainLen) + prefixLen = prefixBufTmpRemainLen - 1; if(suffixLen >= sizeof(suffixBuf)) suffixLen = sizeof(suffixBuf) - 1; + size_t suffixColorLen = 0; + char * suffixBufTmp = suffixBuf + suffixLen; + size_t suffixBufTmpRemainLen = sizeof(suffixBuf) - suffixLen; + + if (p_format->colored_output == OUTPUT_COLOR_ON) { + suffixColorLen = snprintf(suffixBufTmp, suffixBufTmpRemainLen, "%c[%dm", 0x1B, 0); + if(suffixColorLen >= suffixBufTmpRemainLen) + suffixColorLen = suffixBufTmpRemainLen - 1; + } + + /* the following code is tragically unreadable */ size_t numLines; @@ -812,7 +867,7 @@ char *android_log_formatLogLine ( // this is an upper bound--newlines in message may be counted // extraneously - bufferSize = (numLines * (prefixLen + suffixLen)) + entry->messageLen + 1; + bufferSize = (numLines * (prefixColorLen + prefixLen + suffixLen + suffixColorLen)) + entry->messageLen + 1; if (defaultBufferSize >= bufferSize) { ret = defaultBuffer; @@ -831,11 +886,11 @@ char *android_log_formatLogLine ( if (prefixSuffixIsHeaderFooter) { strcat(p, prefixBuf); - p += prefixLen; + p += prefixColorLen + prefixLen; strncat(p, entry->message, entry->messageLen); p += entry->messageLen; strcat(p, suffixBuf); - p += suffixLen; + p += suffixLen + suffixColorLen; } else { while(pm < (entry->message + entry->messageLen)) { const char *lineStart; @@ -848,11 +903,11 @@ char *android_log_formatLogLine ( lineLen = pm - lineStart; strcat(p, prefixBuf); - p += prefixLen; + p += prefixColorLen + prefixLen; strncat(p, lineStart, lineLen); p += lineLen; strcat(p, suffixBuf); - p += suffixLen; + p += suffixLen + suffixColorLen; if (*pm == '\n') pm++; } diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index 858e56c2..14e7ee3b 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -242,6 +242,7 @@ static void show_help(const char *cmd) " other pruning activity is oldest first. Special case ~!\n" " represents an automatic quicker pruning for the noisiest\n" " UID as determined by the current statistics.\n" + " -C colored output\n" " -P ' ...' set prune white and ~black list, using same format as\n" " printed above. Must be quoted.\n"); @@ -308,6 +309,11 @@ static const char *multiplier_of_size(unsigned long value) return multipliers[i]; } +static void setColoredOutput() +{ + android_log_setColoredOutput(g_logformat); +} + int main(int argc, char **argv) { int err; @@ -339,7 +345,7 @@ int main(int argc, char **argv) for (;;) { int ret; - ret = getopt(argc, argv, "cdt:T:gG:sQf:r:n:v:b:BSpP:"); + ret = getopt(argc, argv, "cdt:T:gG:sQf:r:n:v:b:BSpCP:"); if (ret < 0) { break; @@ -441,6 +447,10 @@ int main(int argc, char **argv) setPruneList = optarg; break; + case 'C': + setColoredOutput(); + break; + case 'b': { if (strcmp(optarg, "all") == 0) { while (devices) { From ecf15181dc3ecaceb5682fb96ddff99f5dda6b93 Mon Sep 17 00:00:00 2001 From: "Brint E. Kriebel" Date: Wed, 14 May 2014 18:13:00 -0700 Subject: [PATCH 010/243] init: update recovery when enabled in settings Update the recovery image only if the option is enabled under Developer options This reverts commit 231e0a9e6a1da6fa4a188840f68af649669e417f. Change-Id: I928f7ee8bb3eaf5581bb8225661d253ecca0c4ef Change CM recovery install script filename [2/2] This is part 2/2 to maintain backwards compatibility with CWM's verify_root_and_recovery() function. CWM checks if install-recovery.sh exists and has an executable flag set, then offers to disable the script for the user. CM now controls this with the persist.sys.recovery_update property which is configurable via settings, so we don't need to double-check this. This changes the name of the recovery install script to install-cm-recovery.sh. Change-Id: I275dd358b46c626dfcb8fe02c583a308d5a89c56 --- rootdir/init.rc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rootdir/init.rc b/rootdir/init.rc index 8ba7c10a..9a306dbf 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -594,10 +594,15 @@ service installd /system/bin/installd class main socket installd stream 600 system system -service flash_recovery /system/bin/install-recovery.sh +service flash_recovery /system/etc/install-cm-recovery.sh class main seclabel u:r:install_recovery:s0 oneshot + disabled + +# update recovery if enabled +on property:persist.sys.recovery_update=true + start flash_recovery service racoon /system/bin/racoon class main From bb3c70a9e51f65e7f3d0af869d765ada780a6269 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Fri, 16 Aug 2013 14:29:44 -0700 Subject: [PATCH 011/243] core: Add some static libraries * Add static versions of libdiskconfig and libsysutils for MiniVold Change-Id: I9ea9498dcff3f094bbcbb1e05e6d10bc9b83ac74 Conflicts: libsysutils/Android.mk --- libdiskconfig/Android.mk | 7 +++++++ libsysutils/Android.mk | 20 ++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/libdiskconfig/Android.mk b/libdiskconfig/Android.mk index 624e3852..5e7400e1 100644 --- a/libdiskconfig/Android.mk +++ b/libdiskconfig/Android.mk @@ -15,6 +15,13 @@ LOCAL_SYSTEM_SHARED_LIBRARIES := libcutils liblog libc LOCAL_CFLAGS := -Werror include $(BUILD_SHARED_LIBRARY) +include $(CLEAR_VARS) +LOCAL_SRC_FILES := $(commonSources) +LOCAL_MODULE := libdiskconfig +LOCAL_MODULE_TAGS := optional +#LOCAL_STATIC_LIBRARIES := libcutils liblog libc +include $(BUILD_STATIC_LIBRARY) + ifeq ($(HOST_OS),linux) include $(CLEAR_VARS) LOCAL_SRC_FILES := $(commonSources) diff --git a/libsysutils/Android.mk b/libsysutils/Android.mk index 246f954c..d71f0faf 100644 --- a/libsysutils/Android.mk +++ b/libsysutils/Android.mk @@ -2,9 +2,7 @@ ifneq ($(BUILD_TINY_ANDROID),true) LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= \ +common_src_files := \ src/SocketListener.cpp \ src/FrameworkListener.cpp \ src/NetlinkListener.cpp \ @@ -14,14 +12,20 @@ LOCAL_SRC_FILES:= \ src/ServiceManager.cpp \ EventLogTags.logtags -LOCAL_MODULE:= libsysutils - -LOCAL_C_INCLUDES := +include $(CLEAR_VARS) +LOCAL_SRC_FILES:= $(common_src_files) +LOCAL_MODULE:= libsysutils +LOCAL_C_INCLUDES := $(KERNEL_HEADERS) LOCAL_CFLAGS := -Werror - LOCAL_SHARED_LIBRARIES := libcutils liblog - include $(BUILD_SHARED_LIBRARY) +include $(CLEAR_VARS) +LOCAL_SRC_FILES:= $(common_src_files) +LOCAL_MODULE:= libsysutils +LOCAL_C_INCLUDES := $(KERNEL_HEADERS) +LOCAL_CFLAGS := -Werror +include $(BUILD_STATIC_LIBRARY) + endif From 5f6ca23671addcb3f395351381bd1187fd29d328 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Tue, 5 Nov 2013 03:33:44 +0000 Subject: [PATCH 012/243] Add libminshacrypt static lib This is a sha-only version of libmincrypt, to provide the new SHA_hash implementation to binaries that require libcrypto_static --- libmincrypt/Android.mk | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libmincrypt/Android.mk b/libmincrypt/Android.mk index 79069862..796ce9d1 100644 --- a/libmincrypt/Android.mk +++ b/libmincrypt/Android.mk @@ -8,6 +8,13 @@ LOCAL_SRC_FILES := dsa_sig.c p256.c p256_ec.c p256_ecdsa.c rsa.c sha.c sha256.c LOCAL_CFLAGS := -Wall -Werror include $(BUILD_STATIC_LIBRARY) +## Crippled version without an RSA implementation +## to coexist with libcrypto_static and provide SHA_hash +include $(CLEAR_VARS) +LOCAL_MODULE := libminshacrypt +LOCAL_SRC_FILES := sha.c sha256.c +include $(BUILD_STATIC_LIBRARY) + include $(CLEAR_VARS) LOCAL_MODULE := libmincrypt LOCAL_SRC_FILES := dsa_sig.c p256.c p256_ec.c p256_ecdsa.c rsa.c sha.c sha256.c From 3bd0f34a652713fc4a97f822829ee04de86955fa Mon Sep 17 00:00:00 2001 From: Shashank Mittal Date: Wed, 25 Jul 2012 13:12:21 -0700 Subject: [PATCH 013/243] Add support for exec command in init scripts. Change-Id: Iee523fd75410718f0bd090f5fdcba50825a698c4 --- init/builtins.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/init/builtins.c b/init/builtins.c index c1925514..ffe5bc42 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -254,9 +254,35 @@ int do_enable(int nargs, char **args) return 0; } +#define MAX_PARAMETERS 64 int do_exec(int nargs, char **args) { - return -1; + pid_t pid; + int status, i, j; + char *par[MAX_PARAMETERS]; + + if (nargs > MAX_PARAMETERS) + { + return -1; + } + + for(i=0, j=1; i<(nargs-1) ;i++,j++) + { + par[i] = args[j]; + } + + par[i] = (char*)0; + pid = fork(); + if (!pid) + { + execv(par[0],par); + } + else + { + while(wait(&status)!=pid); + } + + return 0; } int do_export(int nargs, char **args) From 2e43a9fb1f81846fce690cec4342cd654b976896 Mon Sep 17 00:00:00 2001 From: David Ng Date: Thu, 23 Aug 2012 20:40:33 -0700 Subject: [PATCH 014/243] init: Add support for properties expansion in exec command Add Android properties expansion to 'exec' arguments. E.g. exec /system/bin/log ${sys.usb.config} CRs-Fixed: 390942 Change-Id: Ie520396d951e578bd9f591734a45d2f460b8f51d --- init/builtins.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/init/builtins.c b/init/builtins.c index ffe5bc42..acfe6a3f 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -260,6 +260,8 @@ int do_exec(int nargs, char **args) pid_t pid; int status, i, j; char *par[MAX_PARAMETERS]; + char prop_val[PROP_VALUE_MAX]; + int len; if (nargs > MAX_PARAMETERS) { @@ -268,6 +270,23 @@ int do_exec(int nargs, char **args) for(i=0, j=1; i<(nargs-1) ;i++,j++) { + if ((args[j]) + && + (!expand_props(prop_val, args[j], sizeof(prop_val)))) + + { + len = strlen(args[j]); + if (strlen(prop_val) <= len) { + /* Overwrite arg with expansion. + * + * For now, only allow an expansion length that + * can fit within the original arg length to + * avoid extra allocations. + * On failure, use original argument. + */ + strncpy(args[j], prop_val, len + 1); + } + } par[i] = args[j]; } From ea153a1c7404e1598eebaf9b3b9c6e763c93c776 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Tue, 11 Dec 2012 17:53:36 +0700 Subject: [PATCH 015/243] Set ANDROID_PROPERTY_WORKSPACE in exec. Change-Id: Ib827bf14b4463ca6277b79256bcc4cd70f63fc31 --- init/builtins.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/init/builtins.c b/init/builtins.c index acfe6a3f..081759a5 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -294,7 +294,13 @@ int do_exec(int nargs, char **args) pid = fork(); if (!pid) { - execv(par[0],par); + char tmp[32]; + int fd, sz; + get_property_workspace(&fd, &sz); + sprintf(tmp, "%d,%d", dup(fd), sz); + setenv("ANDROID_PROPERTY_WORKSPACE", tmp, 1); + execve(par[0], par, environ); + exit(0); } else { From 04e5e3b697caa1f47c89439415ddd870b3489a8f Mon Sep 17 00:00:00 2001 From: Dave Burke Date: Wed, 24 Oct 2012 17:30:31 -0700 Subject: [PATCH 016/243] Revert "Revert "put back the unused virtuals in Vector<>"" This reverts commit 225c66a48cdc3acef21ee380dc134449749d3cb3 Change-Id: If31a04b81052cbc7dd7bf237c07107c33066d03d Conditionally Revert "put back the unused virtuals in Vector<>" These symbols are needed for MR2 camera.tegra and other blobs, but they conflict with KK blobs so define it for devices that need it by setting COMMON_GLOBAL_CFLAGS += -DNEEDS_VECTORIMPL_SYMBOLS Change-Id: I59e66074526f013918a29c3afc10e52b9812778c --- include/utils/VectorImpl.h | 26 +++++++++++++++++++++++++- libutils/VectorImpl.cpp | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/utils/VectorImpl.h b/include/utils/VectorImpl.h index 21ad71ce..cab95bef 100644 --- a/include/utils/VectorImpl.h +++ b/include/utils/VectorImpl.h @@ -105,7 +105,19 @@ class VectorImpl virtual void do_splat(void* dest, const void* item, size_t num) const = 0; virtual void do_move_forward(void* dest, const void* from, size_t num) const = 0; virtual void do_move_backward(void* dest, const void* from, size_t num) const = 0; - + +#if NEEDS_VECTORIMPL_SYMBOLS + // take care of FBC... + virtual void reservedVectorImpl1(); + virtual void reservedVectorImpl2(); + virtual void reservedVectorImpl3(); + virtual void reservedVectorImpl4(); + virtual void reservedVectorImpl5(); + virtual void reservedVectorImpl6(); + virtual void reservedVectorImpl7(); + virtual void reservedVectorImpl8(); +#endif + private: void* _grow(size_t where, size_t amount); void _shrink(size_t where, size_t amount); @@ -156,6 +168,18 @@ class SortedVectorImpl : public VectorImpl protected: virtual int do_compare(const void* lhs, const void* rhs) const = 0; +#if NEEDS_VECTORIMPL_SYMBOLS + // take care of FBC... + virtual void reservedSortedVectorImpl1(); + virtual void reservedSortedVectorImpl2(); + virtual void reservedSortedVectorImpl3(); + virtual void reservedSortedVectorImpl4(); + virtual void reservedSortedVectorImpl5(); + virtual void reservedSortedVectorImpl6(); + virtual void reservedSortedVectorImpl7(); + virtual void reservedSortedVectorImpl8(); +#endif + private: ssize_t _indexOrderOf(const void* item, size_t* order = 0) const; diff --git a/libutils/VectorImpl.cpp b/libutils/VectorImpl.cpp index 30ca6635..0bfc1f00 100644 --- a/libutils/VectorImpl.cpp +++ b/libutils/VectorImpl.cpp @@ -516,6 +516,17 @@ void VectorImpl::_do_move_backward(void* dest, const void* from, size_t num) con do_move_backward(dest, from, num); } +#if NEEDS_VECTORIMPL_SYMBOLS +void VectorImpl::reservedVectorImpl1() { } +void VectorImpl::reservedVectorImpl2() { } +void VectorImpl::reservedVectorImpl3() { } +void VectorImpl::reservedVectorImpl4() { } +void VectorImpl::reservedVectorImpl5() { } +void VectorImpl::reservedVectorImpl6() { } +void VectorImpl::reservedVectorImpl7() { } +void VectorImpl::reservedVectorImpl8() { } +#endif + /*****************************************************************************/ SortedVectorImpl::SortedVectorImpl(size_t itemSize, uint32_t flags) @@ -631,6 +642,17 @@ ssize_t SortedVectorImpl::remove(const void* item) return i; } +#if NEEDS_VECTORIMPL_SYMBOLS +void SortedVectorImpl::reservedSortedVectorImpl1() { }; +void SortedVectorImpl::reservedSortedVectorImpl2() { }; +void SortedVectorImpl::reservedSortedVectorImpl3() { }; +void SortedVectorImpl::reservedSortedVectorImpl4() { }; +void SortedVectorImpl::reservedSortedVectorImpl5() { }; +void SortedVectorImpl::reservedSortedVectorImpl6() { }; +void SortedVectorImpl::reservedSortedVectorImpl7() { }; +void SortedVectorImpl::reservedSortedVectorImpl8() { }; +#endif + /*****************************************************************************/ }; // namespace android From 2479b675826ef16dedb0c8d56a6c002d55240912 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Sat, 8 Nov 2014 16:33:41 +0000 Subject: [PATCH 017/243] init.rc: Import CM's init rc --- rootdir/init.rc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rootdir/init.rc b/rootdir/init.rc index 9a306dbf..eafc1260 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -9,6 +9,9 @@ import /init.usb.rc import /init.${ro.hardware}.rc import /init.${ro.zygote}.rc import /init.trace.rc +# Include CM's extra init file +import /init.cm.rc + on early-init # Set init and its forked children's oom_adj. From f7ca9dcda75352b9ee07eb23773982bb5691aedf Mon Sep 17 00:00:00 2001 From: David Ng Date: Fri, 27 Jul 2012 17:15:03 -0700 Subject: [PATCH 018/243] mkbootimg: Add --dt parameter to specify DT image New optional --dt parameter to specify a kernel device tree image. Change-Id: Ie29a11cbf4138426bfd19ae486d69a5fcbd8f442 --- mkbootimg/bootimg.h | 7 +++++-- mkbootimg/mkbootimg.c | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/mkbootimg/bootimg.h b/mkbootimg/bootimg.h index 9171d85a..308c537d 100644 --- a/mkbootimg/bootimg.h +++ b/mkbootimg/bootimg.h @@ -41,8 +41,8 @@ struct boot_img_hdr unsigned tags_addr; /* physical addr for kernel tags */ unsigned page_size; /* flash page size we assume */ - unsigned unused[2]; /* future expansion: should be 0 */ - + unsigned dt_size; /* device tree in bytes */ + unsigned unused; /* future expansion: should be 0 */ unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */ unsigned char cmdline[BOOT_ARGS_SIZE]; @@ -64,10 +64,13 @@ struct boot_img_hdr ** +-----------------+ ** | second stage | o pages ** +-----------------+ +** | device tree | p pages +** +-----------------+ ** ** n = (kernel_size + page_size - 1) / page_size ** m = (ramdisk_size + page_size - 1) / page_size ** o = (second_size + page_size - 1) / page_size +** p = (dt_size + page_size - 1) / page_size ** ** 0. all entities are page_size aligned in flash ** 1. kernel and ramdisk are required (size != 0) diff --git a/mkbootimg/mkbootimg.c b/mkbootimg/mkbootimg.c index fc92b4dc..f74c8143 100644 --- a/mkbootimg/mkbootimg.c +++ b/mkbootimg/mkbootimg.c @@ -65,6 +65,7 @@ int usage(void) " [ --board ]\n" " [ --base
]\n" " [ --pagesize ]\n" + " [ --dt ]\n" " -o|--output \n" ); return 1; @@ -105,6 +106,8 @@ int main(int argc, char **argv) char *cmdline = ""; char *bootimg = 0; char *board = ""; + char *dt_fn = 0; + void *dt_data = 0; unsigned pagesize = 2048; int fd; SHA_CTX ctx; @@ -158,6 +161,8 @@ int main(int argc, char **argv) fprintf(stderr,"error: unsupported page size %d\n", pagesize); return -1; } + } else if(!strcmp(arg, "--dt")) { + dt_fn = val; } else { return usage(); } @@ -232,6 +237,14 @@ int main(int argc, char **argv) } } + if(dt_fn) { + dt_data = load_file(dt_fn, &hdr.dt_size); + if (dt_data == 0) { + fprintf(stderr,"error: could not load device tree image '%s'\n", dt_fn); + return 1; + } + } + /* put a hash of the contents in the header so boot images can be * differentiated based on their first 2k. */ @@ -242,6 +255,10 @@ int main(int argc, char **argv) SHA_update(&ctx, &hdr.ramdisk_size, sizeof(hdr.ramdisk_size)); SHA_update(&ctx, second_data, hdr.second_size); SHA_update(&ctx, &hdr.second_size, sizeof(hdr.second_size)); + if(dt_data) { + SHA_update(&ctx, dt_data, hdr.dt_size); + SHA_update(&ctx, &hdr.dt_size, sizeof(hdr.dt_size)); + } sha = SHA_final(&ctx); memcpy(hdr.id, sha, SHA_DIGEST_SIZE > sizeof(hdr.id) ? sizeof(hdr.id) : SHA_DIGEST_SIZE); @@ -266,6 +283,10 @@ int main(int argc, char **argv) if(write_padding(fd, pagesize, hdr.second_size)) goto fail; } + if(dt_data) { + if(write(fd, dt_data, hdr.dt_size) != hdr.dt_size) goto fail; + if(write_padding(fd, pagesize, hdr.dt_size)) goto fail; + } return 0; fail: From 1d8e3bf8d38c05aa4327fd844b602d6e205d94d6 Mon Sep 17 00:00:00 2001 From: Shruthi Krishna Date: Tue, 10 Jun 2014 15:27:39 -0700 Subject: [PATCH 019/243] mkbootimg: fixing the typecast issue Change-Id: Ic375089ecce7aed3f9968e5e0b48e8ae0df66d83 --- mkbootimg/mkbootimg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkbootimg/mkbootimg.c b/mkbootimg/mkbootimg.c index f74c8143..658052cd 100644 --- a/mkbootimg/mkbootimg.c +++ b/mkbootimg/mkbootimg.c @@ -284,7 +284,7 @@ int main(int argc, char **argv) } if(dt_data) { - if(write(fd, dt_data, hdr.dt_size) != hdr.dt_size) goto fail; + if(write(fd, dt_data, hdr.dt_size) != (ssize_t) hdr.dt_size) goto fail; if(write_padding(fd, pagesize, hdr.dt_size)) goto fail; } return 0; From 8964d3defc48322b6dd64cec8c55d5d3c4431913 Mon Sep 17 00:00:00 2001 From: Naveen Kalla Date: Mon, 20 Dec 2010 14:37:49 -0800 Subject: [PATCH 020/243] Add group qcom_oncrpc and give permissions to ril-daemon and /dev/oncrpc Change-Id: I022aae4a81c720a026ea6c1a41bda30acbe60224 diag: Remove world read/write permissions from /dev/diag /dev/diag has world read/write permissions which is considered a security risk. Remove these permissions. Add new qcom_diag group for access to /dev/diag CRs-Fixed: 356415 (cherry picked from commit 14c85ec56fd47c5eb143617a3bd5a6e7ee39cb6e) Change-Id: I536323a97e19a07bbd8eadffa0265d1955590285 --- include/private/android_filesystem_config.h | 4 ++++ rootdir/init.rc | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index 5d9c3ea7..8412bc11 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -93,6 +93,8 @@ #define AID_NET_BW_STATS 3006 /* read bandwidth statistics */ #define AID_NET_BW_ACCT 3007 /* change bandwidth statistics accounting */ #define AID_NET_BT_STACK 3008 /* bluetooth: access config files */ +#define AID_QCOM_ONCRPC 3009 /* can read/write /dev/oncrpc files */ +#define AID_QCOM_DIAG 3010 /* can read/write /dev/diag */ #define AID_EVERYBODY 9997 /* shared between all apps in the same profile */ #define AID_MISC 9998 /* access to misc storage */ @@ -149,6 +151,8 @@ static const struct android_id_info android_ids[] = { { "sdcard_r", AID_SDCARD_R, }, { "clat", AID_CLAT, }, { "loop_radio", AID_LOOP_RADIO, }, + { "qcom_oncrpc", AID_QCOM_ONCRPC, }, + { "qcom_diag", AID_QCOM_DIAG, }, { "mediadrm", AID_MEDIA_DRM, }, { "package_info", AID_PACKAGE_INFO, }, { "sdcard_pics", AID_SDCARD_PICS, }, diff --git a/rootdir/init.rc b/rootdir/init.rc index eafc1260..c5eaebb0 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -553,7 +553,7 @@ service ril-daemon /system/bin/rild socket rild stream 660 root radio socket rild-debug stream 660 radio system user root - group radio cache inet misc audio log + group radio cache inet misc audio sdcard_rw qcom_oncrpc qcom_diag log service surfaceflinger /system/bin/surfaceflinger class core From cbe8ce6d6b436429dc4fc2151843e7ea6ddd3817 Mon Sep 17 00:00:00 2001 From: William Roberts Date: Fri, 8 Feb 2013 09:45:26 +0900 Subject: [PATCH 021/243] Auditd initial commit Initial commit for an audit daemon that writes kernel audit messages to a log file. The daemon runs in uid "audit" or AID_AUDIT. The log files are located at /data/misc/audit/ The daemon maintains two files at this location: audit.log and optionally audit.old. On boot ( if the file is non-zero in size), or when a fixed threshold is hit, the daemon rotates audit.log to audit.old. Optionally, if passed the -k option, the daemon polls dmesg for all lines that contain "audit" and writes them into the log. After that it continues to operate as normal, receiving the messages from the netlink socket. Change-Id: I5b5037a5a8b39a054213848249afb7808f8b0ffa Sync with master auditd. sys/capability.h does not exist in the 4.2 bionic. Reserve AID_AUDIT AID_AUDIT will be used for an audit daemon for gathering and controlling the Linux audit subsystem. Change-Id: I95d597524b5547a60f3a59f692b4b0a6df0a9645 --- auditd/Android.mk | 23 ++ auditd/NOTICE | 190 +++++++++++ auditd/README | 44 +++ auditd/audit_log.c | 353 ++++++++++++++++++++ auditd/audit_log.h | 79 +++++ auditd/auditd.c | 223 +++++++++++++ auditd/libaudit.c | 331 ++++++++++++++++++ auditd/libaudit.h | 111 ++++++ include/private/android_filesystem_config.h | 4 + rootdir/init.rc | 5 + 10 files changed, 1363 insertions(+) create mode 100644 auditd/Android.mk create mode 100644 auditd/NOTICE create mode 100644 auditd/README create mode 100644 auditd/audit_log.c create mode 100644 auditd/audit_log.h create mode 100644 auditd/auditd.c create mode 100644 auditd/libaudit.c create mode 100644 auditd/libaudit.h diff --git a/auditd/Android.mk b/auditd/Android.mk new file mode 100644 index 00000000..c29319a6 --- /dev/null +++ b/auditd/Android.mk @@ -0,0 +1,23 @@ +# Copyright 2005 The Android Open Source Project + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +# Override this in the BoardConfig.mk +# to change the default size +# Note: The value is in Kilobytes +AUDITD_MAX_LOG_FILE_SIZEKB ?= 100 + +LOCAL_SRC_FILES:= \ + auditd.c \ + libaudit.c \ + audit_log.c + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libc + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := auditd +LOCAL_CFLAGS := -DAUDITD_MAX_LOG_FILE_SIZEKB=$(AUDITD_MAX_LOG_FILE_SIZEKB) +include $(BUILD_EXECUTABLE) diff --git a/auditd/NOTICE b/auditd/NOTICE new file mode 100644 index 00000000..80220968 --- /dev/null +++ b/auditd/NOTICE @@ -0,0 +1,190 @@ + + Copyright 2012, Samsung Telecommunications of America + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + + 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. + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/auditd/README b/auditd/README new file mode 100644 index 00000000..9d14c0de --- /dev/null +++ b/auditd/README @@ -0,0 +1,44 @@ +Auditd Daemon + +The audit daemon is a simplified version of its desktop +counterpart designed to gather the audit logs from the +audit kernel subsystem. The audit subsystem of the kernel +includes Linux Security Modules (LSM) messages as well. + +To enable the audit subsystem, you must add this to your +kernel config: +CONFIG_AUDIT=y +CONFIG_AUDITSYSCALL=y + +To enable a LSM, you must consult that LSM's documentation, the +example below is for SELinux: +CONFIG_SECURITY_SELINUX=y + +This does not include possible dependencies that may need to be +satisfied for that particular LSM. + +The daemon maintains two log files audit.log and audit.old +at /data/misc/audit/. On boot, if audit.log exists, and +the size is greater than 0, audit.log is renamed to +audit.old. The log file is also renamed, or rotated, when +a threshold is hit. This threshold is hard-coded to 100KB +but can be adjusted through the AUDITD_MAX_LOG_FILE_SIZEKB +Makefile file variable that can be overridden in the device.mk + +The daemon is not included by default, and must explicitly be +added to PRODUCT_PACKAGES. This could be set in the device.mk + +The daemon also has no external interfaces, but one could +use inotify to start and build a system from this. The log +files are owned by UID audit and readable by system. A +system UID application could conceivably be used to consume +these logs. + +Example configuration in device.mk: + +# 1MB Log file threshold +AUDITD_MAX_LOG_FILE_SIZEKB := 1000 + +PRODUCT_PACKAGES += auditd + + diff --git a/auditd/audit_log.c b/auditd/audit_log.c new file mode 100644 index 00000000..ef77a3f2 --- /dev/null +++ b/auditd/audit_log.c @@ -0,0 +1,353 @@ +/* + * Copyright 2012, Samsung Telecommunications of America + * + * 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. + * + * Written by William Roberts + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOG_TAG "audit_log" +#include + +#include "libaudit.h" +#include "audit_log.h" + +/* + * Note that the flags passed to fcntl and the flags used + * by fopen must be compatible. For instance, specifying + * write only on one and read only on the other will yield + * strange behavior. + */ +/* Mode for fopen */ +#define AUDIT_LOG_FMODE "w+" +/* mode for fchmod*/ +#define AUDIT_LOG_MODE (S_IRUSR | S_IWUSR | S_IRGRP) +/* flags for fcntl */ +#define AUDIT_LOG_FLAGS (O_RDWR | O_CREAT | O_SYNC) + +#define AUDIT_TYPE "type=" +#define AUDIT_MSG "msg=" +#define AUDIT_KEYWORD "audit(" + +struct audit_log +{ + FILE *file; + size_t total_bytes; + size_t threshold; + char *rotatefile; + char *logfile; +}; + +/** + * Wraps open with a fchmod to prevent umask issues from arising in + * permission setting as well as a fcntl to set the underlying + * fds mode. However, the rest of the library relies on stdio file + * access, so a FILE pointer is returned. + * + * You must make sure your mode and fmode are compatible + * + * @param file + * File stream output + * @param path + * The path of the log file + * @param flags + * The flags passed to fcntl + * @param fmode + * The mode passed to fopen + * @param mode + * The mode passed to open and fchmod + * @return + * 0 on success with *file set, or -errno on error + */ +static int open_log(FILE **file, const char *path, int flags, const char *fmode, mode_t mode) +{ + int fd; + int rc; + + if(!file) { + return -EINVAL; + } + + *file = fopen(path, fmode); + if(!*file) { + rc = -errno; + SLOGE("Could not open audit log file %s : %s", path, strerror(errno)); + return rc; + } + + rc = setvbuf(*file, NULL, _IONBF, 0); + if (rc != 0) { + rc = -errno; + SLOGE("Could not setvbuf the log file"); + goto err; + } + + fd = fileno(*file); + rc = fchmod(fd, mode); + if (rc < 0) { + rc = -errno; + SLOGE("Could not fchmod the log file"); + goto err; + } + + rc = fcntl(fd, F_SETFD, flags); + if (rc < 0) { + rc = -errno; + SLOGE("Could not fcntl the log file"); + goto err; + } + + return 0; + +err: + fclose(*file); + return rc; +} + +audit_log *audit_log_open(const char *logfile, const char *rotatefile, size_t threshold) +{ + int rc; + audit_log *l = NULL; + struct stat log_file_stats; + + rc = stat(logfile, &log_file_stats); + if (rc < 0) { + if(errno != ENOENT) { + SLOGE("Could not stat audit logfile %s: %s", logfile, strerror(errno)); + return NULL; + } + else { + SLOGI("Previous audit logfile not detected"); + } + } + + /* The existing log had data */ + if (rc == 0 && log_file_stats.st_size >= 0) { + rc = rename(logfile, rotatefile); + if (rc < 0) { + SLOGE("Could not rename %s to %s: %s", logfile, rotatefile, strerror(errno)); + return NULL; + } + SLOGI("Previous audit logfile detected, rotating\n"); + } + + l = calloc(sizeof(struct audit_log), 1); + if (!l) { + SLOGE("Out of memory while allocating audit log"); + return NULL; + } + + /* Open the output logfile */ + rc = open_log(&(l->file), logfile, AUDIT_LOG_FLAGS, AUDIT_LOG_FMODE, AUDIT_LOG_MODE); + if (rc < 0) { + /* Error message handled by open_log() */ + return NULL; + } + + l->rotatefile = strdup(rotatefile); + if (!l->rotatefile) { + SLOGE("Out of memory while duplicating rotatefile string"); + goto err; + } + + l->logfile = strdup(logfile); + if (!l->logfile) { + SLOGE("Out of memory while duplicating logfile string"); + goto err; + } + + l->threshold = threshold; + + return l; + +err: + audit_log_close(l); + return NULL; +} + +int audit_log_write(audit_log *l, const char *fmt, ...) +{ + int rc; + va_list args; + + if (l == NULL || fmt == NULL) { + return -EINVAL; + } + + va_start(args, fmt); + rc = vfprintf(l->file, fmt, args); + va_end(args); + + if(rc < 0) { + SLOGE("Error writing to log file"); + clearerr(l->file); + rc = -EINVAL; + goto out; + } + + l->total_bytes += rc; + +out: + if(l->total_bytes > l->threshold) { + /* audit_log_rotate() handles error message */ + rc = audit_log_rotate(l); + } + + return rc; +} + +int audit_log_rotate(audit_log *l) +{ + FILE *file; + int rc = 0; + + if (!l) { + return -EINVAL; + } + + rc = rename(l->logfile, l->rotatefile); + if (rc < 0) { + rc = -errno; + SLOGE("Could not rename audit log file \"%s\" to \"%s\", error: %s", + l->logfile, l->rotatefile, strerror(errno)); + return rc; + } + + rc = open_log(&file, l->logfile, AUDIT_LOG_FLAGS, AUDIT_LOG_FMODE, AUDIT_LOG_MODE); + if (rc < 0) { + /* Error message handled by open_log() */ + return rc; + } + + fclose(l->file); + l->total_bytes = 0; + l->file = file; + + return 0; +} + +void audit_log_close(audit_log *l) +{ + if (!l) { + return; + } + + free(l->logfile); + free(l->rotatefile); + if (l->file) { + fclose(l->file); + } + free(l); + return; +} + +int audit_log_put_kmsg(audit_log *l) +{ + char *tok; + char *audit; + char *type; + int rc = 0; + char *buf = NULL; + int len = klogctl(KLOG_SIZE_BUFFER, NULL, 0); + + /* No data to read */ + if (len == 0) { + SLOGI("Empty kmsg"); + return 0; + } + + /* Error */ + if (len < 0) { + rc = -errno; + SLOGE("Could not read kernel log length: %s", strerror(errno)); + return rc; + } + + /* Data to read */ + len++; + buf = malloc(len * sizeof(*buf)); + if (!buf) { + SLOGE("Out of memory wile allocating kmsg buffer"); + return -ENOMEM; + } + + rc = klogctl(KLOG_READ_ALL, buf, len); + if (rc < 0) { + rc = -errno; + SLOGE("Could not read kernel log data: %s", strerror(errno)); + goto err; + } + + buf[len - 1] = '\0'; + tok = buf; + + while ((tok = strtok(tok, "\r\n"))) { + + /* Only print audit messages The SPACE is important!! as we want the + * audit pointer pointing to a space and not the beginning of the message. + * This helps ensure that we don't erroneously going down the wrong path when + * parsing this data. + * XXX Should we include the space in the AUDIT_KEYWORD macro? + */ + audit = strstr(tok, " "AUDIT_KEYWORD); + if (audit) { + + /* Place a null terminator at the space, and advance the pointer past it */ + *audit++ = '\0'; + + /* If it has type field, print that than msg= */ + type = strstr(tok, AUDIT_TYPE); + if (type) { + + /* + * The type should be the the left of the space we replaced with a + * null terminator + * + * type is pointing to type=1400\0 and audit is pointing to audit(....\0 + */ + rc = audit_log_write(l, "%s msg=%s\n", type, audit); + if(rc < 0) { + /* audit_log_write handles error message */ + goto err; + } + } + /* It contined the AUDIT_KEWORD but was not formatted as expected, just dump it */ + else { + SLOGW("Improperly formatted kernel audit message, dumping as is"); + rc = audit_log_write(l, "%s\n", audit); + if(rc < 0) { + /* audit_log_write handles error message */ + goto err; + } + } + } + tok = NULL; + } + +err: + free(buf); + return rc; +} diff --git a/auditd/audit_log.h b/auditd/audit_log.h new file mode 100644 index 00000000..3bb98e8d --- /dev/null +++ b/auditd/audit_log.h @@ -0,0 +1,79 @@ +/* + * Copyright 2012, Samsung Telecommunications of America + * + * 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. + * + * Written by William Roberts + */ + +#ifndef _AUDIT_LOG_H_ +#define _AUDIT_LOG_H_ + +#include +#include "libaudit.h" + +typedef struct audit_log audit_log; + +/** + * Opens an audit logfile for writing + * @param logfile + * The logfile name to use + * @param rotatefile + * The logfile to rotate to when threshold is encountered + * @param threshold + * The threshold, in bytes, the log file should grow to + * until rotation. + * @return + * A valid handle to the audit_log or NULL on failure. + */ +extern audit_log *audit_log_open(const char *logfile, const char *rotatefile, size_t threshold); + +/** + * Writes a formatted message to the audit log + * @param l + * The log to write too + * @param fmt + * The fmt specifier as passed to fprintf/printf family of functions + * @return + * 0 on success or -errno on error + * + */ +extern int audit_log_write(audit_log *l, const char *fmt, ...); + +/** + * Forces a rotation of the audit log. + * @param l + * The log file to use + * @return + * 0 on success, -errno on failure. + */ +extern int audit_log_rotate(audit_log *l); + +/** + * Closes the audit log file. + * @param l + * The log file to close. + */ +extern void audit_log_close(audit_log *l); + +/** + * Searches once through kmsg for type=1400 + * kernel messages and logs them to the audit log + * @param l + * The log to append too + * @return + * 0 on success, -errno on failure. + */ +extern int audit_log_put_kmsg(audit_log *l); + +#endif diff --git a/auditd/auditd.c b/auditd/auditd.c new file mode 100644 index 00000000..875ae646 --- /dev/null +++ b/auditd/auditd.c @@ -0,0 +1,223 @@ +/* + * Copyright 2012, Samsung Telecommunications of America + * + * 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. + * + * Written by William Roberts + */ + +#define LOG_TAG "auditd" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#include "libaudit.h" +#include "audit_log.h" + +/* + * TODO: + * Just Ideas: + * 1. Add a socket interface for sending events + */ + +#ifndef AUDITD_MAX_LOG_FILE_SIZEKB +#error "AUDITD_MAX_LOG_FILE_SIZEKB not defined by makefile!" +#endif + +#define AUDITD_LOG_DIR "/data/misc/audit" +#define AUDITD_LOG_FILE AUDITD_LOG_DIR "/audit.log" +#define AUDITD_OLD_LOG_FILE AUDITD_LOG_DIR "/audit.old" + +#define AUDITD_MAX_LOG_FILE_SIZE (1024 * AUDITD_MAX_LOG_FILE_SIZEKB) + +static volatile int quit = 0; + +static void signal_handler(int sig) +{ + switch (sig) { + case SIGINT: + case SIGTERM: + quit = 1; + break; + } + return; +} + +static void usage(char *cmd) +{ + printf("%s - log audit events from the kernel\n" + "OPTIONS\n" + "-k - search dmesg on startup for audit events\n" + "\n", cmd); +} + +#define RAISE(ary, c) ary[CAP_TO_INDEX(c)].permitted |= CAP_TO_MASK(c); + +static void drop_privileges_or_die(void) +{ + + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[2]; + + if (prctl(PR_SET_KEEPCAPS, 1) < 0) { + SLOGE("Failed on prctl KEEPCAPS: %s", strerror(errno)); + exit(1); + } + + if (setgid(AID_AUDIT) < 0) { + SLOGE("Failed on setgid: %s", strerror(errno)); + exit(1); + } + + if (setuid(AID_AUDIT) < 0) { + SLOGE("Failed on setuid: %s", strerror(errno)); + exit(1); + } + + memset(&capheader, 0, sizeof(capheader)); + memset(&capdata, 0, sizeof(capdata)); + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capheader.pid = 0; + + RAISE(capdata, CAP_AUDIT_CONTROL); + RAISE(capdata, CAP_SYSLOG); + + capdata[0].effective = capdata[0].permitted; + capdata[1].effective = capdata[1].permitted; + capdata[0].inheritable = 0; + capdata[1].inheritable = 0; + + if (capset(&capheader, &capdata[0]) < 0) { + SLOGE("Failed on capset: %s", strerror(errno)); + exit(1); + } +} + +int main(int argc, char *argv[]) +{ + int c; + int rc; + int audit_fd = -1; + int check_kernel_log = 0; + + struct pollfd pfds; + struct audit_reply rep; + struct sigaction action; + audit_log *l = NULL; + + SLOGI("Starting up"); + + drop_privileges_or_die(); + + /* register the signal handler */ + action.sa_handler = signal_handler; + sigemptyset(&action.sa_mask); + action.sa_flags = 0; + rc = sigaction(SIGINT, &action, NULL); + if (rc < 0) { + rc = errno; + SLOGE("Failed on set signal handler: %s", strerror(errno)); + goto err; + } + + while ((c = getopt(argc, argv, "k")) != -1) { + switch (c) { + case 'k': + check_kernel_log = 1; + break; + default: + usage(argv[0]); + goto err; + } + } + + /* Open the netlink socket for audit events */ + audit_fd = audit_open(); + if (audit_fd < 0) { + rc = errno; + SLOGE("Failed on audit_set_pid with error: %s", strerror(errno)); + goto err; + } + + l = audit_log_open(AUDITD_LOG_FILE, AUDITD_OLD_LOG_FILE, AUDITD_MAX_LOG_FILE_SIZE); + if (!l) { + SLOGE("Failed on audit_log_open"); + goto err; + } + + if (audit_set_pid(audit_fd, getpid(), WAIT_YES) < 0) { + rc = errno; + SLOGE("Failed on audit_set_pid with error: %s", strerror(errno)); + goto err; + } + + pfds.fd = audit_fd; + pfds.events = POLLIN; + + if (check_kernel_log) { + audit_log_put_kmsg(l); + } + + while (!quit) { + + /* Start reading for events */ + rc = poll(&pfds, 1, -1); + if (rc == 0) { + continue; + } else if (rc < 0) { + if (errno != EINTR) { + SLOGE("Failed to poll audit log socket: %d : %s", errno, strerror(errno)); + } + continue; + } + + if (audit_get_reply(audit_fd, &rep, GET_REPLY_BLOCKING, 0) < 0) { + SLOGE("Failed on audit_get_reply with error: %s", strerror(errno)); + continue; + } + + audit_log_write(l, "type=%d msg=%.*s\n", rep.type, rep.len, rep.msg.data); + /* Keep reading for events */ + } + +err: + SLOGI("Exiting"); + if (audit_fd >= 0) { + audit_set_pid(audit_fd, 0, WAIT_NO); + audit_close(audit_fd); + } + audit_log_close(l); + return rc; +} diff --git a/auditd/libaudit.c b/auditd/libaudit.c new file mode 100644 index 00000000..06e55570 --- /dev/null +++ b/auditd/libaudit.c @@ -0,0 +1,331 @@ +/* + * Copyright 2012, Samsung Telecommunications of America + * + * 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. + * + * Written by William Roberts + * + */ + +#include +#include +#include +#include +#include + +#define LOG_TAG "libaudit" +#include +#include + +#include "libaudit.h" + +/** + * Copies the netlink message data to the reply structure. + * + * When the kernel sends a response back, we must adjust the response from the + * netlink message header. + * All the data is in rep->msg but belongs in the type enforced fields in the struct. + * + * @param rep + * The response + * @param len + * The length of the message, len must never be less than 0! + * @return + * This function returns 0 on success, else -error. + */ +static int set_internal_fields(struct audit_reply *rep, ssize_t len) +{ + int rc; + + /* + * We end up setting a specific field in the union, but since it + * is a union and they are all of type pointer, we can just clear + * one. + */ + rep->status = NULL; + + /* Set the response from the netlink message */ + rep->nlh = &rep->msg.nlh; + rep->len = rep->msg.nlh.nlmsg_len; + rep->type = rep->msg.nlh.nlmsg_type; + + /* Check if the reply from the kernel was ok */ + if (!NLMSG_OK(rep->nlh, (size_t)len)) { + rc = (len == sizeof(rep->msg)) ? -EFBIG : -EBADE; + SLOGE("Bad kernel response %s", strerror(-rc)); + return rc; + } + + /* Next we'll set the data structure to point to msg.data. This is + * to avoid having to use casts later. */ + if (rep->type == NLMSG_ERROR) { + rep->error = NLMSG_DATA(rep->nlh); + } else if (rep->type == AUDIT_GET) { + rep->status = NLMSG_DATA(rep->nlh); + } else if (rep->type == AUDIT_LIST_RULES) { + rep->ruledata = NLMSG_DATA(rep->nlh); + } else if (rep->type == AUDIT_SIGNAL_INFO) { + rep->signal_info = NLMSG_DATA(rep->nlh); + } + /* If it is not any of the above specific events, it must be a generic message */ + else { + rep->message = NLMSG_DATA(rep->nlh); + } + + return 0; +} + +/** + * Waits for an ack from the kernel + * @param fd + * The netlink socket fd + * @param seq + * The current sequence number were acking on + * @return + * This function returns 0 on success, else -errno. + */ +static int get_ack(int fd, int16_t seq) +{ + int rc; + struct audit_reply rep; + + /* Sanity check the input, this is an internal interface this shouldn't happen */ + if (fd < 0) { + return -EINVAL; + } + + rc = audit_get_reply(fd, &rep, GET_REPLY_BLOCKING, MSG_PEEK); + if (rc < 0) { + return rc; + } + + if (rep.type == NLMSG_ERROR) { + audit_get_reply(fd, &rep, GET_REPLY_BLOCKING, 0); + if (rep.error->error) { + return -rep.error->error; + } + } + + if ((int16_t)rep.nlh->nlmsg_seq != seq) { + SLOGW("Expected sequence number between user space and kernel space is out of skew, " + "expected %u got %u", seq, rep.nlh->nlmsg_seq); + } + + return 0; +} + +/** + * + * @param fd + * The netlink socket fd + * @param type + * The type of netlink message + * @param data + * The data to send + * @param size + * The length of the data in bytes + * @return + * This function returns a positive sequence number on success, else -errno. + */ +static int audit_send(int fd, int type, const void *data, unsigned int size) +{ + int rc; + static int16_t sequence = 0; + struct audit_message req; + struct sockaddr_nl addr; + + memset(&req, 0, sizeof(req)); + memset(&addr, 0, sizeof(addr)); + + /* We always send netlink messaged */ + addr.nl_family = AF_NETLINK; + + /* Set up the netlink headers */ + req.nlh.nlmsg_type = type; + req.nlh.nlmsg_len = NLMSG_SPACE(size); + req.nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; + + /* + * Check for a valid fd, even though sendto would catch this, its easier to always + * blindly increment the sequence number + */ + if (fd < 0) { + return -EBADF; + } + + /* Ensure the message is not too big */ + if (NLMSG_SPACE(size) > MAX_AUDIT_MESSAGE_LENGTH) { + SLOGE("netlink message is too large"); + return -EINVAL; + } + + /* Only memcpy in the data if it was specified */ + if (size && data) + memcpy(NLMSG_DATA(&req.nlh), data, size); + + /* + * Only increment the sequence number on a guarantee + * you will send it to the kernel. + * + * Also, the sequence is defined as a u32 in the kernel + * struct. Using an int here might not work on 32/64 bit splits. A + * signed 64 bit value can overflow a u32..but a u32 + * might not fit in the response, so we need to use s32. + * Which is still kind of hackish since int could be 16 bits + * in size. The only safe type to use here is a signed 16 + * bit value. + */ + req.nlh.nlmsg_seq = ++sequence; + + /* While failing and its due to interrupts */ + do { + /* Try and send the netlink message */ + rc = sendto(fd, &req, req.nlh.nlmsg_len, 0, (struct sockaddr*) &addr, sizeof(addr)); + + } while (rc < 0 && errno == EINTR); + + /* Not all the bytes were sent */ + if ((uint32_t) rc != req.nlh.nlmsg_len) { + rc = -EPROTO; + goto out; + } else if (rc < 0) { + rc = -errno; + SLOGE("Error sending data over the netlink socket: %s", strerror(-errno)); + goto out; + } + + /* We sent all the bytes, get the ack */ + rc = get_ack(fd, sequence); + + /* If the ack failed, return the error, else return the sequence number */ + rc = (rc == 0) ? (int) sequence : rc; + +out: + /* Don't let sequence roll to negative */ + if (sequence < 0) { + SLOGW("Auditd to Kernel sequence number has rolled over"); + sequence = 0; + } + + return rc; +} + +int audit_set_pid(int fd, uint32_t pid, rep_wait_t wmode) +{ + int rc; + struct audit_reply rep; + struct audit_status status; + + memset(&status, 0, sizeof(status)); + + /* + * In order to set the auditd PID we send an audit message over the netlink socket + * with the pid field of the status struct set to our current pid, and the + * the mask set to AUDIT_STATUS_PID + */ + status.pid = pid; + status.mask = AUDIT_STATUS_PID; + + /* Let the kernel know this pid will be registering for audit events */ + rc = audit_send(fd, AUDIT_SET, &status, sizeof(status)); + if (rc < 0) { + SLOGE("Could net set pid for audit events, error: %s", strerror(-rc)); + return rc; + } + + /* + * In a request where we need to wait for a response, wait for the message + * and discard it. This message confirms and sync's us with the kernel. + * This daemon is now registered as the audit logger. Only wait if the + * wmode is != WAIT_NO + */ + if (wmode != WAIT_NO) { + /* TODO + * If the daemon dies and restarts the message didn't come back, + * so I went to non-blocking and it seemed to fix the bug. + * Need to investigate further. + */ + audit_get_reply(fd, &rep, GET_REPLY_NONBLOCKING, 0); + } + + return 0; +} + +int audit_open() +{ + return socket(PF_NETLINK, SOCK_RAW, NETLINK_AUDIT); +} + +int audit_get_reply(int fd, struct audit_reply *rep, reply_t block, int peek) +{ + ssize_t len; + int flags; + + struct sockaddr_nl nladdr; + socklen_t nladdrlen = sizeof(nladdr); + + if (fd < 0) { + return -EBADF; + } + + /* Set up the flags for recv from */ + flags = (block == GET_REPLY_NONBLOCKING) ? MSG_DONTWAIT : 0; + flags |= peek; + + /* + * Get the data from the netlink socket but on error we need to be carefull, + * the interface shows that EINTR can never be returned, other errors, however, + * can be returned. + */ + do { + len = recvfrom(fd, &rep->msg, sizeof(rep->msg), flags, (struct sockaddr*) &nladdr, + &nladdrlen); + + /* + * EAGAIN and EINTR should be re-tried until success or + * another error manifests. + */ + if (len < 0 && errno != EINTR) { + if (block == GET_REPLY_NONBLOCKING && errno == EAGAIN) { + /* If the request is non blocking and the errno is EAGAIN, just return 0 */ + return 0; + } + SLOGE("Error receiving from netlink socket, error: %s", strerror(errno)); + return -errno; + } + + /* 0 or greater indicates success */ + } while (len < 0); + + if (nladdrlen != sizeof(nladdr)) { + SLOGE("Protocol fault, error: %s", strerror(EPROTO)); + return -EPROTO; + } + + /* Make sure the netlink message was not spoof'd */ + if (nladdr.nl_pid) { + SLOGE("Invalid netlink pid received, expected 0 got: %d", nladdr.nl_pid); + return -EINVAL; + } + + return set_internal_fields(rep, len); +} + +void audit_close(int fd) +{ + int rc = close(fd); + if (rc < 0) { + SLOGE("Attempting to close invalid fd %d, error: %s", fd, strerror(errno)); + } + return; +} diff --git a/auditd/libaudit.h b/auditd/libaudit.h new file mode 100644 index 00000000..fbaa7b96 --- /dev/null +++ b/auditd/libaudit.h @@ -0,0 +1,111 @@ +/* + * Copyright 2012, Samsung Telecommunications of America + * + * 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. + * + * Written by William Roberts + */ + +#ifndef _LIBAUDIT_H_ +#define _LIBAUDIT_H_ + +#include +#include +#include +#include +#include + +#define MAX_AUDIT_MESSAGE_LENGTH 8970 + +typedef enum { + GET_REPLY_BLOCKING=0, + GET_REPLY_NONBLOCKING +} reply_t; + +typedef enum { + WAIT_NO, + WAIT_YES +} rep_wait_t; + +struct audit_sig_info { + uid_t uid; + pid_t pid; + char ctx[0]; +}; + +struct audit_message { + struct nlmsghdr nlh; + char data[MAX_AUDIT_MESSAGE_LENGTH]; +}; + +struct audit_reply { + int type; + int len; + struct nlmsghdr *nlh; + struct audit_message msg; + + union { + struct audit_status *status; + struct audit_rule_data *ruledata; + const char *message; + struct nlmsgerr *error; + struct audit_sig_info *signal_info; + }; +}; + +/** + * Opens a connection to the Audit netlink socket + * @return + * A valid fd on success or < 0 on error with errno set. + * Returns the same errors as man 2 socket. + */ +extern int audit_open(void); + +/** + * Closes the fd returned from audit_open() + * @param fd + * The fd to close + */ +extern void audit_close(int fd); + +/** + * + * @param fd + * The fd returned by a call to audit_open() + * @param rep + * The response struct to store the response in. + * @param block + * Whether or not to block on IO + * @param peek + * Whether or not we are to remove the message from + * the queue when we do a read on the netlink socket. + * @return + * This function returns 0 on success, else -errno. + */ +extern int audit_get_reply(int fd, struct audit_reply *rep, reply_t block, + int peek); + +/** + * Sets a pid to recieve audit netlink events from the kernel + * @param fd + * The fd returned by a call to audit_open() + * @param pid + * The pid whom to set as the reciever of audit messages + * @param wmode + * Whether or not to block on the underlying socket io calls. + * @return + * This function returns 0 on success, -errno on error. + */ +extern int audit_set_pid(int fd, uint32_t pid, rep_wait_t wmode); + +#endif diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index 8412bc11..97f5ecf4 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -79,6 +79,8 @@ #define AID_LOGD 1036 /* log daemon */ #define AID_SHARED_RELRO 1037 /* creator of shared GNU RELRO files */ +#define AID_AUDIT 1049 /* audit daemon */ + #define AID_SHELL 2000 /* adb and debug shell user */ #define AID_CACHE 2001 /* cache access */ #define AID_DIAG 2002 /* access to diagnostic resources */ @@ -161,6 +163,8 @@ static const struct android_id_info android_ids[] = { { "logd", AID_LOGD, }, { "shared_relro", AID_SHARED_RELRO, }, + { "audit", AID_AUDIT, }, + { "shell", AID_SHELL, }, { "cache", AID_CACHE, }, { "diag", AID_DIAG, }, diff --git a/rootdir/init.rc b/rootdir/init.rc index c5eaebb0..8e3d70b0 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -260,6 +260,7 @@ on post-fs-data # create basic filesystem structure mkdir /data/misc 01771 system misc mkdir /data/misc/adb 02750 system shell + mkdir /data/misc/audit 02750 audit system mkdir /data/misc/bluedroid 0770 bluetooth net_bt_stack mkdir /data/misc/bluetooth 0770 system system mkdir /data/misc/keystore 0700 keystore keystore @@ -500,6 +501,10 @@ service console /system/bin/sh group shell log seclabel u:r:shell:s0 +service auditd /system/bin/auditd -k + seclabel u:r:logd:s0 + class main + on property:ro.debuggable=1 start console From c8667c76af464228ec284491413cac59a0c29af4 Mon Sep 17 00:00:00 2001 From: Sridhar Gujje Date: Thu, 12 Sep 2013 18:04:08 +0530 Subject: [PATCH 022/243] Initial bringup system-core Change-Id: Ic61f4b46b3d833b3ce893d9b4dd250a77e8c5ec9 --- include/private/android_filesystem_config.h | 2 ++ include/system/graphics.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index 97f5ecf4..c45e0ff4 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -99,6 +99,7 @@ #define AID_QCOM_DIAG 3010 /* can read/write /dev/diag */ #define AID_EVERYBODY 9997 /* shared between all apps in the same profile */ + #define AID_MISC 9998 /* access to misc storage */ #define AID_NOBODY 9999 @@ -177,6 +178,7 @@ static const struct android_id_info android_ids[] = { { "net_bw_stats", AID_NET_BW_STATS, }, { "net_bw_acct", AID_NET_BW_ACCT, }, { "net_bt_stack", AID_NET_BT_STACK, }, + { "qcom_diag", AID_QCOM_DIAG, }, { "everybody", AID_EVERYBODY, }, { "misc", AID_MISC, }, diff --git a/include/system/graphics.h b/include/system/graphics.h index c3fca97b..b207ee82 100644 --- a/include/system/graphics.h +++ b/include/system/graphics.h @@ -54,7 +54,8 @@ enum { HAL_PIXEL_FORMAT_RGB_888 = 3, HAL_PIXEL_FORMAT_RGB_565 = 4, HAL_PIXEL_FORMAT_BGRA_8888 = 5, - + HAL_PIXEL_FORMAT_RGBA_5551 = 6, + HAL_PIXEL_FORMAT_RGBA_4444 = 7, /* * sRGB color pixel formats: * From 45ee97e7c572005d1807b99ee2618d3211d1afe7 Mon Sep 17 00:00:00 2001 From: David Ng Date: Mon, 30 Sep 2013 12:15:26 -0700 Subject: [PATCH 023/243] ueventd: Add bootdevice symlink Create the /dev/block/bootdevice symlink to point to the boot device information based on kernel command line. This decouples references to the boot device from the actual device nodes (e.g. eMMC, UFS). Change-Id: I5e5e3e07ff38c8002ac3f188df80284f1f47892b --- init/devices.c | 5 +++++ init/ueventd.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/init/devices.c b/init/devices.c index 1012fee4..78495e1b 100644 --- a/init/devices.c +++ b/init/devices.c @@ -56,6 +56,7 @@ #define FIRMWARE_DIR3 "/firmware/image" extern struct selabel_handle *sehandle; +extern char bootdevice[32]; static int device_fd = -1; @@ -552,6 +553,10 @@ static char **get_block_device_symlinks(struct uevent *uevent) else links[link_num] = NULL; + if (!strncmp(device, bootdevice, sizeof(bootdevice))) { + make_link(link_path, "/dev/block/bootdevice"); + } + return links; } diff --git a/init/ueventd.c b/init/ueventd.c index 833e4fd0..1e580525 100644 --- a/init/ueventd.c +++ b/init/ueventd.c @@ -33,6 +33,7 @@ static char hardware[32]; static unsigned revision = 0; +char bootdevice[32]; static void import_kernel_nv(char *name, int in_qemu) { @@ -44,6 +45,10 @@ static void import_kernel_nv(char *name, int in_qemu) { strlcpy(hardware, value, sizeof(hardware)); } + else if (!strcmp(name,"androidboot.bootdevice")) + { + strlcpy(bootdevice, value, sizeof(bootdevice)); + } } } } From 750666c192826b99892d189ea8bd476a6bd68daa Mon Sep 17 00:00:00 2001 From: David Ng Date: Mon, 23 Sep 2013 18:50:24 -0700 Subject: [PATCH 024/243] init: Add vendor-specific initialization hooks. Allow optional vendor-specific initializations within init. This can be used for runtime initialization setup that init rc scripts do not support. Change-Id: I7623a0d59b18f9ec8e3623958e2f7ccd72b877bf Conflicts: init/init.c --- init/Android.mk | 6 +++++- init/NOTICE | 27 +++++++++++++++++++++++++++ init/init.c | 5 +++++ init/vendor_init.c | 37 +++++++++++++++++++++++++++++++++++++ init/vendor_init.h | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 init/vendor_init.c create mode 100644 init/vendor_init.h diff --git a/init/Android.mk b/init/Android.mk index 489dc93e..502ddff8 100644 --- a/init/Android.mk +++ b/init/Android.mk @@ -15,7 +15,8 @@ LOCAL_SRC_FILES:= \ init_parser.c \ ueventd.c \ ueventd_parser.c \ - watchdogd.c + watchdogd.c \ + vendor_init.c LOCAL_CFLAGS += -Wno-unused-parameter @@ -48,6 +49,9 @@ LOCAL_STATIC_LIBRARIES := \ libext4_utils_static LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk +ifneq ($(strip $(TARGET_INIT_VENDOR_LIB)),) +LOCAL_WHOLE_STATIC_LIBRARIES += $(TARGET_INIT_VENDOR_LIB) +endif include $(BUILD_EXECUTABLE) diff --git a/init/NOTICE b/init/NOTICE index c5b1efa7..d93146db 100644 --- a/init/NOTICE +++ b/init/NOTICE @@ -188,3 +188,30 @@ END OF TERMS AND CONDITIONS + +Copyright (c) 2013, The Linux Foundation. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/init/init.c b/init/init.c index bd1db7a5..67794099 100644 --- a/init/init.c +++ b/init/init.c @@ -57,6 +57,7 @@ #include "util.h" #include "ueventd.h" #include "watchdogd.h" +#include "vendor_init.h" struct selabel_handle *sehandle; struct selabel_handle *sehandle_prop; @@ -822,6 +823,10 @@ static int property_service_init_action(int nargs, char **args) exit(1); } + /* update with vendor-specific property runtime + * overrides + */ + vendor_load_properties(); return 0; } diff --git a/init/vendor_init.c b/init/vendor_init.c new file mode 100644 index 00000000..d3fd5ffe --- /dev/null +++ b/init/vendor_init.c @@ -0,0 +1,37 @@ +/* +Copyright (c) 2013, The Linux Foundation. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "vendor_init.h" + +/* init vendor override stubs */ + +__attribute__ ((weak)) +void vendor_load_properties() +{ +} diff --git a/init/vendor_init.h b/init/vendor_init.h new file mode 100644 index 00000000..9afb449b --- /dev/null +++ b/init/vendor_init.h @@ -0,0 +1,33 @@ +/* +Copyright (c) 2013, The Linux Foundation. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __INIT_VENDOR__H__ +#define __INIT_VENDOR__H__ +extern void vendor_load_properties(void); +#endif /* __INIT_VENDOR__H__ */ From e54d8484729e5a08b8c19559cc864eb2edd0ef2a Mon Sep 17 00:00:00 2001 From: David Ng Date: Wed, 11 Dec 2013 19:40:09 -0800 Subject: [PATCH 025/243] init: Allow target-specific platform device base to be specified. Add optional build-time flag, TARGET_PLATFORM_DEVICE_BASE, to specify the base sysfs path (without the /sys prefix) where the platform device resides. This provides support for targets where platform devices are all under a master level platform device (e.g. soc-bus). Change-Id: I1196fddaddbd03bd472db95ed4d67f818e3af0cb --- init/Android.mk | 3 +++ init/devices.c | 7 +++++++ 2 files changed, 10 insertions(+) mode change 100644 => 100755 init/Android.mk diff --git a/init/Android.mk b/init/Android.mk old mode 100644 new mode 100755 index 502ddff8..7e4527bd --- a/init/Android.mk +++ b/init/Android.mk @@ -49,6 +49,9 @@ LOCAL_STATIC_LIBRARIES := \ libext4_utils_static LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk +ifneq ($(strip $(TARGET_PLATFORM_DEVICE_BASE)),) +LOCAL_CFLAGS += -D_PLATFORM_BASE="\"$(TARGET_PLATFORM_DEVICE_BASE)\"" +endif ifneq ($(strip $(TARGET_INIT_VENDOR_LIB)),) LOCAL_WHOLE_STATIC_LIBRARIES += $(TARGET_INIT_VENDOR_LIB) endif diff --git a/init/devices.c b/init/devices.c index 78495e1b..57281606 100644 --- a/init/devices.c +++ b/init/devices.c @@ -274,11 +274,18 @@ static void add_platform_device(const char *path) struct platform_node *bus; const char *name = path; +#ifdef _PLATFORM_BASE + if (!strncmp(path, _PLATFORM_BASE, strlen(_PLATFORM_BASE))) + name += strlen(_PLATFORM_BASE); + else + return; +#else if (!strncmp(path, "/devices/", 9)) { name += 9; if (!strncmp(name, "platform/", 9)) name += 9; } +#endif list_for_each_reverse(node, &platform_names) { bus = node_to_item(node, struct platform_node, list); From abe1d680417681027ba1ecc2043d01efc78d7c54 Mon Sep 17 00:00:00 2001 From: Sridhar Gujje Date: Fri, 13 Sep 2013 19:54:11 +0530 Subject: [PATCH 026/243] Camera bringup changes system-core Change-Id: I1cf98641eca9096bd27645e07ea802646ea1fb96 --- include/system/camera.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/system/camera.h b/include/system/camera.h index 7a4dd534..827cd122 100644 --- a/include/system/camera.h +++ b/include/system/camera.h @@ -88,6 +88,8 @@ enum { // Notify on autofocus start and stop. This is useful in continuous // autofocus - FOCUS_MODE_CONTINUOUS_VIDEO and FOCUS_MODE_CONTINUOUS_PICTURE. CAMERA_MSG_FOCUS_MOVE = 0x0800, // notifyCallback + CAMERA_MSG_STATS_DATA = 0x1000, + CAMERA_MSG_META_DATA = 0x2000, CAMERA_MSG_ALL_MSGS = 0xFFFF }; @@ -174,6 +176,13 @@ enum { * count is non-positive or too big to be realized. */ CAMERA_CMD_SET_VIDEO_BUFFER_COUNT = 10, + CAMERA_CMD_HISTOGRAM_ON = 11, + CAMERA_CMD_HISTOGRAM_OFF = 12, + CAMERA_CMD_HISTOGRAM_SEND_DATA = 13, + CAMERA_CMD_LONGSHOT_ON = 14, + CAMERA_CMD_LONGSHOT_OFF = 15, + CAMERA_CMD_METADATA_ON = 100, + CAMERA_CMD_METADATA_OFF = 101, }; /** camera fatal errors */ @@ -254,6 +263,18 @@ typedef struct camera_face { * -2000, -2000 if this is not supported. */ int32_t mouth[2]; + int32_t smile_degree; + int32_t smile_score; + int32_t blink_detected; + int32_t face_recognised; + int32_t gaze_angle; + int32_t updown_dir; + int32_t leftright_dir; + int32_t roll_dir; + int32_t left_right_gaze; + int32_t top_bottom_gaze; + int32_t leye_blink; + int32_t reye_blink; } camera_face_t; From cdb31562798dc180d65fc56313657ec291bcee9c Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Thu, 19 Sep 2013 01:20:05 -0700 Subject: [PATCH 027/243] system/core: Fix for HAL compilation issues while integrating HAL 1.0 Change-Id: Iead9c1ade279b64c5cbdf4d2de1a8b695939c52a --- include/system/camera.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/system/camera.h b/include/system/camera.h index 827cd122..fb379a61 100644 --- a/include/system/camera.h +++ b/include/system/camera.h @@ -93,6 +93,13 @@ enum { CAMERA_MSG_ALL_MSGS = 0xFFFF }; +/** meta data type in CameraMetaDataCallback */ +enum { + CAMERA_META_DATA_ASD = 0x001, //ASD data + CAMERA_META_DATA_FD = 0x002, //FD/FP data + CAMERA_META_DATA_HDR = 0x003, //Auto HDR data +}; + /** cmdType in sendCommand functions */ enum { CAMERA_CMD_START_SMOOTH_ZOOM = 1, @@ -176,6 +183,14 @@ enum { * count is non-positive or too big to be realized. */ CAMERA_CMD_SET_VIDEO_BUFFER_COUNT = 10, + + /** + * Commands to enable/disable preview histogram + * + * Based on user's input to enable/disable histogram from the camera + * UI, send the appropriate command to the HAL to turn on/off the histogram + * stats and start sending the data to the application. + */ CAMERA_CMD_HISTOGRAM_ON = 11, CAMERA_CMD_HISTOGRAM_OFF = 12, CAMERA_CMD_HISTOGRAM_SEND_DATA = 13, From 7386988ed3ffb4024f6dbafb54e78cfe56c00899 Mon Sep 17 00:00:00 2001 From: Susmitha Gummalla Date: Mon, 28 Apr 2014 18:05:21 -0700 Subject: [PATCH 028/243] Camera: Add enum to specify the frame type -Added enum to specify the frame type of either fd/data buffer CRs-fixed: 654901 Change-Id: I1c0b1a2c6a1425cdb6650cdfc20ca65835a1b81f --- include/system/camera.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/system/camera.h b/include/system/camera.h index fb379a61..0ed69262 100644 --- a/include/system/camera.h +++ b/include/system/camera.h @@ -293,6 +293,16 @@ typedef struct camera_face { } camera_face_t; +/** + * The information of a data type received in a camera frame. + */ +typedef enum { + /** Data buffer */ + CAMERA_FRAME_DATA_BUF = 0x000, + /** File descriptor */ + CAMERA_FRAME_DATA_FD = 0x100 +} camera_frame_data_type_t; + /** * The metadata of the frame data. */ From a14ae6d5ef3585a2f9f0930ffd7637885afe5d36 Mon Sep 17 00:00:00 2001 From: Sreelakshmi Gownipalli Date: Fri, 29 Jun 2012 17:19:17 -0700 Subject: [PATCH 029/243] diag: Remove world read/write permissions from /dev/diag /dev/diag has world read/write permissions which is considered a security risk. Remove these permissions. Add new qcom_diag group for access to /dev/diag CRs-Fixed: 356415 Change-Id: I0bf3c5903dd854c605740861733c44dc299ec70a --- include/private/android_filesystem_config.h | 1 + rootdir/ueventd.rc | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index c45e0ff4..932f81de 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -176,6 +176,7 @@ static const struct android_id_info android_ids[] = { { "net_raw", AID_NET_RAW, }, { "net_admin", AID_NET_ADMIN, }, { "net_bw_stats", AID_NET_BW_STATS, }, + { "qcom_diag", AID_QCOM_DIAG, }, { "net_bw_acct", AID_NET_BW_ACCT, }, { "net_bt_stack", AID_NET_BT_STACK, }, { "qcom_diag", AID_QCOM_DIAG, }, diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc index eff24c30..3fb1c6ef 100644 --- a/rootdir/ueventd.rc +++ b/rootdir/ueventd.rc @@ -20,6 +20,9 @@ subsystem adf # the msm hw3d client device node is world writable/readable. /dev/msm_hw3dc 0666 root root +# the DIAG device node is not world writable/readable. +/dev/diag 0660 system qcom_diag + # gpu driver for adreno200 is globally accessible /dev/kgsl 0666 root root @@ -27,7 +30,6 @@ subsystem adf /dev/dri/* 0666 root graphics # these should not be world writable -/dev/diag 0660 radio radio /dev/diag_arm9 0660 radio radio /dev/android_adb 0660 adb adb /dev/android_adb_enable 0660 adb adb From 102d1978eae34ba337cbc393dfe1ea65003b0519 Mon Sep 17 00:00:00 2001 From: pramod kotreshappa Date: Tue, 10 Jun 2014 20:31:50 -0700 Subject: [PATCH 030/243] Bluetooth: Introduce new property type and permission Introduce new property type and allow system and bluetooth processes to set these properties so that transport layer of ANT and BT stack can set these properties for chip initialization part Change-Id: I7735d4743d8b43ea935584901d5aa330df965868 --- init/property_service.c | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/init/property_service.c b/init/property_service.c index 1902b776..3f28a99a 100644 --- a/init/property_service.c +++ b/init/property_service.c @@ -56,6 +56,68 @@ static int property_area_inited = 0; static int property_set_fd = -1; +/* White list of permissions for setting property services. */ +struct { + const char *prefix; + unsigned int uid; + unsigned int gid; +} property_perms[] = { + { "net.rmnet0.", AID_RADIO, 0 }, + { "net.gprs.", AID_RADIO, 0 }, + { "net.ppp", AID_RADIO, 0 }, + { "net.qmi", AID_RADIO, 0 }, + { "net.lte", AID_RADIO, 0 }, + { "net.cdma", AID_RADIO, 0 }, + { "ril.", AID_RADIO, 0 }, + { "gsm.", AID_RADIO, 0 }, + { "persist.radio", AID_RADIO, 0 }, + { "net.dns", AID_RADIO, 0 }, + { "sys.usb.config", AID_RADIO, 0 }, + { "net.", AID_SYSTEM, 0 }, + { "dev.", AID_SYSTEM, 0 }, + { "runtime.", AID_SYSTEM, 0 }, + { "hw.", AID_SYSTEM, 0 }, + { "sys.", AID_SYSTEM, 0 }, + { "sys.powerctl", AID_SHELL, 0 }, + { "service.", AID_SYSTEM, 0 }, + { "wlan.", AID_SYSTEM, 0 }, + { "gps.", AID_GPS, 0 }, + { "bluetooth.", AID_BLUETOOTH, 0 }, + { "dhcp.", AID_SYSTEM, 0 }, + { "dhcp.", AID_DHCP, 0 }, + { "debug.", AID_SYSTEM, 0 }, + { "debug.", AID_SHELL, 0 }, + { "log.", AID_SHELL, 0 }, + { "service.adb.root", AID_SHELL, 0 }, + { "service.adb.tcp.port", AID_SHELL, 0 }, + { "persist.logd.size",AID_SYSTEM, 0 }, + { "persist.sys.", AID_SYSTEM, 0 }, + { "persist.service.", AID_SYSTEM, 0 }, + { "persist.security.", AID_SYSTEM, 0 }, + { "persist.gps.", AID_GPS, 0 }, + { "persist.service.bdroid.", AID_BLUETOOTH, 0 }, + { "selinux." , AID_SYSTEM, 0 }, + { "wc_transport.", AID_BLUETOOTH, AID_SYSTEM }, + { "build.fingerprint", AID_SYSTEM, 0 }, + { "partition." , AID_SYSTEM, 0}, + { NULL, 0, 0 } +}; + +/* + * White list of UID that are allowed to start/stop services. + * Currently there are no user apps that require. + */ +struct { + const char *service; + unsigned int uid; + unsigned int gid; +} control_perms[] = { + { "dumpstate",AID_SHELL, AID_LOG }, + { "ril-daemon",AID_RADIO, AID_RADIO }, + { "pre-recovery", AID_SYSTEM, AID_SYSTEM }, + {NULL, 0, 0 } +}; + typedef struct { size_t size; int fd; From 20193858c3ad36898854c11b978ece3bb8028198 Mon Sep 17 00:00:00 2001 From: Sachin Shah Date: Tue, 26 Mar 2013 17:02:36 -0700 Subject: [PATCH 031/243] init: uevent: Add msm video symbolic link handling Create meaningful symbolic links for video encode/decode devices based on link_name sysfs node so that video client doesn't have to rely on dynamic dev node names like device32, device33 etc. Change-Id: Id308a10d3e601616b63ecd1373809c96f0d04435 --- init/devices.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/init/devices.c b/init/devices.c index 57281606..49207c10 100644 --- a/init/devices.c +++ b/init/devices.c @@ -446,6 +446,41 @@ static void parse_event(const char *msg, struct uevent *uevent) uevent->firmware, uevent->major, uevent->minor); } +static char **get_v4l_device_symlinks(struct uevent *uevent) +{ + char **links; + int fd = -1; + int nr; + char link_name_path[256]; + char link_name[64]; + + if (strncmp(uevent->path, "/devices/virtual/video4linux/video", 34)) + return NULL; + + links = malloc(sizeof(char *) * 2); + if (!links) + return NULL; + memset(links, 0, sizeof(char *) * 2); + + snprintf(link_name_path, sizeof(link_name_path), "%s%s%s", + SYSFS_PREFIX, uevent->path, "/link_name"); + fd = open(link_name_path, O_RDONLY); + if (fd < 0) + goto err; + nr = read(fd, link_name, sizeof(link_name) - 1); + close(fd); + if (nr <= 0) + goto err; + link_name[nr] = '\0'; + if (asprintf(&links[0], "/dev/video/%s", link_name) <= 0) + links[0] = NULL; + + return links; +err: + free(links); + return NULL; +} + static char **get_character_device_symlinks(struct uevent *uevent) { const char *parent; @@ -777,6 +812,8 @@ static void handle_generic_device_event(struct uevent *uevent) } else base = "/dev/"; links = get_character_device_symlinks(uevent); + if (!links) + links = get_v4l_device_symlinks(uevent); if (!devpath[0]) snprintf(devpath, sizeof(devpath), "%s%s", base, name); From 52d02fc743fac7bae2890818ab2d364f229b3891 Mon Sep 17 00:00:00 2001 From: Ben Romberger Date: Fri, 11 Oct 2013 12:36:22 -0700 Subject: [PATCH 032/243] init.rc: Add qcom_diag permissions to mediaserver Qcom_diag permissions are needed in mediaserver to enable the QACT tool which allows users to calibrate audio. Change-Id: I3cb8fe807426b9f68669f34d214b7f6d089acb30 --- rootdir/init.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootdir/init.rc b/rootdir/init.rc index 8e3d70b0..5a27aec2 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -574,7 +574,7 @@ service drm /system/bin/drmserver service media /system/bin/mediaserver class main user media - group audio camera inet net_bt net_bt_admin net_bw_acct drmrpc mediadrm + group audio camera inet net_bt net_bt_admin net_bw_acct drmrpc mediadrm qcom_diag ioprio rt 4 # One shot invocation to deal with encrypted volume. From 6dd12c366d519f0831056da19528f7c1d141057c Mon Sep 17 00:00:00 2001 From: David Ng Date: Thu, 17 Jul 2014 12:22:40 -0700 Subject: [PATCH 033/243] init: Change vendor-specific initialization hooks loaded order. To read the vendor-specific initialization hooks after loading properties from default system properties and before loading override properties. Change-Id: Ic2bf6974c9752f49059fd3126ae8fb550dc1fa6b --- init/init.c | 5 ----- init/property_service.c | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/init/init.c b/init/init.c index 67794099..bd1db7a5 100644 --- a/init/init.c +++ b/init/init.c @@ -57,7 +57,6 @@ #include "util.h" #include "ueventd.h" #include "watchdogd.h" -#include "vendor_init.h" struct selabel_handle *sehandle; struct selabel_handle *sehandle_prop; @@ -823,10 +822,6 @@ static int property_service_init_action(int nargs, char **args) exit(1); } - /* update with vendor-specific property runtime - * overrides - */ - vendor_load_properties(); return 0; } diff --git a/init/property_service.c b/init/property_service.c index 3f28a99a..37907799 100644 --- a/init/property_service.c +++ b/init/property_service.c @@ -48,6 +48,7 @@ #include "init.h" #include "util.h" #include "log.h" +#include "vendor_init.h" #define PERSISTENT_PROPERTY_DIR "/data/property" @@ -604,6 +605,9 @@ void load_all_props(void) load_properties_from_file(PROP_PATH_SYSTEM_DEFAULT, NULL); load_properties_from_file(PROP_PATH_FACTORY, "ro.*"); + /* Read vendor-specific property runtime overrides. */ + vendor_load_properties(); + load_override_properties(); /* Read persistent properties after all default values have been loaded. */ From 754d2efa873efab0be84b6fda8295583adf5e772 Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Thu, 10 Oct 2013 13:15:04 -0700 Subject: [PATCH 034/243] adbd: Use sanitized kernel headers for compilation Build adbd using the headers generated from the kernel directly. This requires adding re-definitions for __FD_* macros as they have been removed from the kernel. Change-Id: Ia511465211463df129ce60738ec6be85025b85a1 --- adb/Android.mk | 5 +++++ adb/sysdeps.h | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/adb/Android.mk b/adb/Android.mk index af7d7e58..a815c77d 100644 --- a/adb/Android.mk +++ b/adb/Android.mk @@ -113,6 +113,11 @@ LOCAL_SRC_FILES := \ remount_service.c \ usb_linux_client.c +ifeq ($(call is-vendor-board-platform,QCOM),true) +LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include +LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr +endif + LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter -Werror LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE diff --git a/adb/sysdeps.h b/adb/sysdeps.h index cc1f839e..12ab1820 100644 --- a/adb/sysdeps.h +++ b/adb/sysdeps.h @@ -519,6 +519,26 @@ static __inline__ char* adb_strtok_r(char *str, const char *delim, char **savep #undef strtok_r #define strtok_r ___xxx_strtok_r +#ifndef __FD_SET +#define __FD_SET(fd, fdsetp) \ + (((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] |= (1<<((fd) & 31))) +#endif + +#ifndef __FD_CLR +#define __FD_CLR(fd, fdsetp) \ + (((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] &= ~(1<<((fd) & 31))) +#endif + +#ifndef __FD_ISSET +#define __FD_ISSET(fd, fdsetp) \ + ((((fd_set *)(fdsetp))->fds_bits[(fd) >> 5] & (1<<((fd) & 31))) != 0) +#endif + +#ifndef __FD_ZERO +#define __FD_ZERO(fdsetp) \ + (memset (fdsetp, 0, sizeof (*(fd_set *)(fdsetp)))) +#endif + #endif /* !_WIN32 */ #endif /* _ADB_SYSDEPS_H */ From 3fd264c1be919ba47ba22bd824cbab141d30f964 Mon Sep 17 00:00:00 2001 From: Manu Gautam Date: Thu, 10 Oct 2013 13:15:26 -0700 Subject: [PATCH 035/243] adbd: Add USB Super Speed (3.0) support When using FunctionFS, adbd is required to specify USB descriptors as well for ADB function. If underlying host and device support USB3.0 then USB communication works if all interface drivers provide SS descriptors as well. Since, ADBD currently doesn't pass SS descriptors to the function_fs driver, it results in USB enumeration failure in SuperSpeed mode when ADB is enabled in USB composition. Change-Id: I1ae44feaba0615db3f341b3d622a3d64922dbad8 --- adb/usb_linux_client.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/adb/usb_linux_client.c b/adb/usb_linux_client.c index 8426e0ea..be7eb2be 100644 --- a/adb/usb_linux_client.c +++ b/adb/usb_linux_client.c @@ -62,6 +62,17 @@ static const struct { struct usb_endpoint_descriptor_no_audio source; struct usb_endpoint_descriptor_no_audio sink; } __attribute__((packed)) fs_descs, hs_descs; +#ifdef FUNCTIONFS_SS_DESC_MAGIC + __le32 ss_magic; + __le32 ss_count; + struct { + struct usb_interface_descriptor intf; + struct usb_endpoint_descriptor_no_audio source; + struct usb_ss_ep_comp_descriptor source_comp; + struct usb_endpoint_descriptor_no_audio sink; + struct usb_ss_ep_comp_descriptor sink_comp; + } __attribute__((packed)) ss_descs; +#endif } __attribute__((packed)) descriptors = { .header = { .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC), @@ -121,6 +132,44 @@ static const struct { .wMaxPacketSize = MAX_PACKET_SIZE_HS, }, }, +#ifdef FUNCTIONFS_SS_DESC_MAGIC + .ss_magic = FUNCTIONFS_SS_DESC_MAGIC, + .ss_count = 5, + .ss_descs = { + .intf = { + .bLength = sizeof(descriptors.ss_descs.intf), + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 0, + .bNumEndpoints = 2, + .bInterfaceClass = ADB_CLASS, + .bInterfaceSubClass = ADB_SUBCLASS, + .bInterfaceProtocol = ADB_PROTOCOL, + .iInterface = 1, /* first string from the provided table */ + }, + .source = { + .bLength = sizeof(descriptors.ss_descs.source), + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 1 | USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = 1024, + }, + .source_comp = { + .bLength = sizeof(descriptors.ss_descs.source_comp), + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, + }, + .sink = { + .bLength = sizeof(descriptors.ss_descs.sink), + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 2 | USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = 1024, + }, + .sink_comp = { + .bLength = sizeof(descriptors.ss_descs.sink_comp), + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, + }, + }, +#endif }; #define STR_INTERFACE_ "ADB Interface" From 9181ed3d18cb06e926a91d873f093ea91a8221e5 Mon Sep 17 00:00:00 2001 From: Piyush Gupta Date: Fri, 18 Jul 2014 17:31:51 -0700 Subject: [PATCH 036/243] ueventd.rc: Change owner of graphics drivers to system iWifi Display service needs permission to open these drivers. Change-Id: I862660a4924671b5d420eda20155a964238ce280 --- rootdir/ueventd.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc index 3fb1c6ef..bc9a8143 100644 --- a/rootdir/ueventd.rc +++ b/rootdir/ueventd.rc @@ -39,7 +39,7 @@ subsystem adf /dev/alarm 0664 system radio /dev/rtc0 0640 system system /dev/tty0 0660 root system -/dev/graphics/* 0660 root graphics +/dev/graphics/* 0660 system graphics /dev/msm_hw3dm 0660 system graphics /dev/input/* 0660 root input /dev/eac 0660 root audio From cca61081448196f2f86c55bff2abc818b12dca28 Mon Sep 17 00:00:00 2001 From: Sachin Shah Date: Thu, 2 Aug 2012 18:26:02 -0700 Subject: [PATCH 037/243] ueventd.rc: Change owner of graphics drivers to system iWifi Display service needs permission to open these drivers. Change-Id: I1d9e4ae372f09ecf4104888a9910d09903d892d1 --- rootdir/ueventd.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc index bc9a8143..5d0d1bf2 100644 --- a/rootdir/ueventd.rc +++ b/rootdir/ueventd.rc @@ -17,7 +17,7 @@ subsystem adf # group, then they'll only see log entries for their UID. /dev/log/* 0666 root log -# the msm hw3d client device node is world writable/readable. +# the msm hw3d client device node is world writable/readable /dev/msm_hw3dc 0666 root root # the DIAG device node is not world writable/readable. From ed4c29789d6f5ee344ae768109ca35db50cf5f61 Mon Sep 17 00:00:00 2001 From: Pradosh Das Date: Wed, 30 Jul 2014 21:19:20 +0530 Subject: [PATCH 038/243] system: core: Add Sensors group Defining group for sensors. CRs-Fixed: 431081 Change-Id: I58151f2fd727bded1b16adb3caeac85e27e44036 --- include/private/android_filesystem_config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index 932f81de..c984c30e 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -97,6 +97,7 @@ #define AID_NET_BT_STACK 3008 /* bluetooth: access config files */ #define AID_QCOM_ONCRPC 3009 /* can read/write /dev/oncrpc files */ #define AID_QCOM_DIAG 3010 /* can read/write /dev/diag */ +#define AID_SENSORS 3011 /* access to /dev/socket/sensor_ctl_socket & QCCI/QCSI */ #define AID_EVERYBODY 9997 /* shared between all apps in the same profile */ @@ -180,7 +181,7 @@ static const struct android_id_info android_ids[] = { { "net_bw_acct", AID_NET_BW_ACCT, }, { "net_bt_stack", AID_NET_BT_STACK, }, { "qcom_diag", AID_QCOM_DIAG, }, - + { "sensors", AID_SENSORS, }, { "everybody", AID_EVERYBODY, }, { "misc", AID_MISC, }, { "nobody", AID_NOBODY, }, From 799e65fa84de0e37508b57b913c0ccd130ee013d Mon Sep 17 00:00:00 2001 From: Basudev Achary Konderpu Date: Thu, 31 Jul 2014 19:55:32 +0530 Subject: [PATCH 039/243] IMS-VT: Define IMS group. Define IMS group. Change-Id: I94a41a52b6d5bc1127aff866b6f36dbb1173dc4f --- include/private/android_filesystem_config.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index c984c30e..e5782ef4 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -95,9 +95,14 @@ #define AID_NET_BW_STATS 3006 /* read bandwidth statistics */ #define AID_NET_BW_ACCT 3007 /* change bandwidth statistics accounting */ #define AID_NET_BT_STACK 3008 /* bluetooth: access config files */ +#if defined(QCOM_LEGACY_UIDS) #define AID_QCOM_ONCRPC 3009 /* can read/write /dev/oncrpc files */ #define AID_QCOM_DIAG 3010 /* can read/write /dev/diag */ +#else +#define AID_QCOM_DIAG 3009 /* can read/write /dev/diag */ +#define AID_IMS 3010 /* can read/write /dev/socket/imsrtp */ #define AID_SENSORS 3011 /* access to /dev/socket/sensor_ctl_socket & QCCI/QCSI */ +#endif #define AID_EVERYBODY 9997 /* shared between all apps in the same profile */ @@ -178,6 +183,7 @@ static const struct android_id_info android_ids[] = { { "net_admin", AID_NET_ADMIN, }, { "net_bw_stats", AID_NET_BW_STATS, }, { "qcom_diag", AID_QCOM_DIAG, }, + { "ims", AID_IMS, }, { "net_bw_acct", AID_NET_BW_ACCT, }, { "net_bt_stack", AID_NET_BT_STACK, }, { "qcom_diag", AID_QCOM_DIAG, }, From 3a53b4c9cbb47ae0b558a2d3bc1eb029802046a2 Mon Sep 17 00:00:00 2001 From: Mingming Yin Date: Wed, 16 Jul 2014 12:00:04 -0700 Subject: [PATCH 040/243] audio: add support for incall music - Define AUDIO_STREAM_INCALL_MUSIC to support incall music Change-Id: I11319f3120a4243803ec2f8b8fc024f696a8a7da --- include/system/audio.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/system/audio.h b/include/system/audio.h index 9a25cfb5..39ea0992 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -58,6 +58,7 @@ typedef enum { */ AUDIO_STREAM_DTMF = 8, AUDIO_STREAM_TTS = 9, + AUDIO_STREAM_INCALL_MUSIC = 10, AUDIO_STREAM_CNT, AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1, From dce971845a00e1ab5fe3408fb78eb1d81ec9f279 Mon Sep 17 00:00:00 2001 From: David Ng Date: Wed, 30 Jul 2014 12:22:03 -0700 Subject: [PATCH 041/243] Add optional target-specific LD_PRELOAD to environment Append additional libraries defined in TARGET_LDPRELOAD to the LD_PRELOAD environment if it is defined. Conflicts: rootdir/Android.mk rootdir/init.environ.rc.in Change-Id: I6bbf35caa71e80f635214259668a13d6efae9cce --- rootdir/Android.mk | 11 ++++++++--- rootdir/init.environ.rc.in | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/rootdir/Android.mk b/rootdir/Android.mk index 3ecb1db8..38f1b56e 100644 --- a/rootdir/Android.mk +++ b/rootdir/Android.mk @@ -30,16 +30,21 @@ LOCAL_POST_INSTALL_CMD := mkdir -p $(addprefix $(TARGET_ROOT_OUT)/, \ include $(BUILD_SYSTEM)/base_rules.mk -# Regenerate init.environ.rc if PRODUCT_BOOTCLASSPATH has changed. -bcp_md5 := $(word 1, $(shell echo $(PRODUCT_BOOTCLASSPATH) $(PRODUCT_SYSTEM_SERVER_CLASSPATH) | $(MD5SUM))) +# Regenerate init.environ.rc if PRODUCT_BOOTCLASSPATH or TARGET_LDPRELOAD has changed. +bcp_md5 := $(word 1, $(shell echo $(PRODUCT_BOOTCLASSPATH) $(PRODUCT_SYSTEM_SERVER_CLASSPATH) $(TARGET_LDPRELOAD) | $(MD5SUM))) bcp_dep := $(intermediates)/$(bcp_md5).bcp.dep $(bcp_dep) : $(hide) mkdir -p $(dir $@) && rm -rf $(dir $@)*.bcp.dep && touch $@ +ifneq ($(strip $(TARGET_LDPRELOAD)),) + TARGET_LDPRELOAD_STR := :$(TARGET_LDPRELOAD) +endif + $(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/init.environ.rc.in $(bcp_dep) @echo "Generate: $< -> $@" @mkdir -p $(dir $@) - $(hide) sed -e 's?%BOOTCLASSPATH%?$(PRODUCT_BOOTCLASSPATH)?g' $< >$@ + $(hide) sed -e 's?%BOOTCLASSPATH%?$(PRODUCT_BOOTCLASSPATH)?g'\ + -e 's?%TARGET_LDPRELOAD%?$(TARGET_LDPRELOAD_STR)?g' $< >$@ $(hide) sed -i -e 's?%SYSTEMSERVERCLASSPATH%?$(PRODUCT_SYSTEM_SERVER_CLASSPATH)?g' $@ bcp_md5 := diff --git a/rootdir/init.environ.rc.in b/rootdir/init.environ.rc.in index 67222d77..c32337a6 100644 --- a/rootdir/init.environ.rc.in +++ b/rootdir/init.environ.rc.in @@ -10,4 +10,4 @@ on init export LOOP_MOUNTPOINT /mnt/obb export BOOTCLASSPATH %BOOTCLASSPATH% export SYSTEMSERVERCLASSPATH %SYSTEMSERVERCLASSPATH% - export LD_PRELOAD libsigchain.so + export LD_PRELOAD libsigchain.so%TARGET_LDPRELOAD% From c7402c0f37f2027c0f4e6442f022e8c1366f9d02 Mon Sep 17 00:00:00 2001 From: Maunik Shah Date: Wed, 3 Sep 2014 19:08:26 +0530 Subject: [PATCH 042/243] Copy the ETB dumps and maps file to /data/core On enabling the persist.debug.trace, ETB maps and dumps will be copied to /data/core only for the first crash. Change-Id: I521ee02e30ce1b4ebaca2c6b398c828286a5115d --- debuggerd/debuggerd.cpp | 80 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/debuggerd/debuggerd.cpp b/debuggerd/debuggerd.cpp index 61805c93..8151eee1 100644 --- a/debuggerd/debuggerd.cpp +++ b/debuggerd/debuggerd.cpp @@ -1,5 +1,6 @@ /* * Copyright 2006, The Android Open Source Project + * Copyright (c) 2013, The Linux Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -124,6 +125,84 @@ static int get_process_info(pid_t tid, pid_t* out_pid, uid_t* out_uid, uid_t* ou return fields == 7 ? 0 : -1; } +static bool copy_file(const char* src, char* dest) +{ + #define BUF_SIZE 64 + ssize_t bytes; + int source_fh, dest_fh; + int total_size = 0; + char buffer[BUF_SIZE]; + + if ((source_fh = open(src, O_RDONLY, O_NOFOLLOW)) == -1) { + ALOGE("Unable to open source file %s\n", src); + } else { + if((dest_fh = open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0640)) == -1) { + ALOGE("Unable to write destination file %s\n", dest); + } else { + while ((bytes = read(source_fh, buffer, BUF_SIZE)) > 0) { + if (write(dest_fh, buffer, bytes) < 0) { + ALOGE("Write failed for destination file %s. Copied %d bytes\n", + dest, total_size); + break; + } + total_size += bytes; + } + ALOGI("Copied %s to %s - size: %d\n", src, dest, total_size); + fsync(dest_fh); + close(dest_fh); + } + close(source_fh); + if (total_size > 0) { + return true; + } + } + return false; +} + +static void collect_etb_map(int cr_pid) +{ + struct stat s; + char src_buf[64]; + char dest_buf[64]; + + snprintf(dest_buf, sizeof dest_buf, "/data/core/etb.%d", cr_pid); + if (!copy_file("/dev/coresight-tmc-etf", dest_buf)) { + ALOGE("Unable to copy ETB buffer file /dev/coresight-tmc-etf\n"); + } else { + memset(src_buf, 0, sizeof(src_buf)); + snprintf(src_buf, sizeof(src_buf), "/proc/%d/maps", cr_pid); + if(stat(src_buf, &s)) { + ALOGE("map file /proc/%d/maps does not exist for pid %d\n", + cr_pid, cr_pid); + } else { + snprintf(dest_buf, sizeof dest_buf, "/data/core/maps.%d", cr_pid); + if (!copy_file(src_buf, dest_buf)) { + ALOGE("Unable to copy map file /proc/%d/maps", cr_pid); + } + } + } +} + +static void enable_etb_trace(struct ucred cr) { + char value[PROPERTY_VALUE_MAX]; + property_get("persist.debug.trace", value, ""); + if ((strcmp(value,"1") == 0)) { + /* Allow ETB collection only once; Note: in future this behavior can be changed + * To allow this, use a property to indicate whether the ETB has been collected */ + property_get("debug.etb.collected", value, ""); + if(strcmp(value,"1")) { + ALOGI("Collecting ETB dumps (from pid=%d uid=%d)\n", + cr.pid, cr.uid); + property_set("debug.etb.collected", "1"); + collect_etb_map(cr.pid); + } + else { + ALOGI("ETB already collected once, skipping (from pid=%d uid=%d)\n", + cr.pid, cr.uid); + } + } +} + static int read_request(int fd, debugger_request_t* out_request) { ucred cr; socklen_t len = sizeof(cr); @@ -170,6 +249,7 @@ static int read_request(int fd, debugger_request_t* out_request) { // Ensure that the tid reported by the crashing process is valid. char buf[64]; struct stat s; + enable_etb_trace(cr); snprintf(buf, sizeof buf, "/proc/%d/task/%d", out_request->pid, out_request->tid); if (stat(buf, &s)) { ALOGE("tid %d does not exist in pid %d. ignoring debug request\n", From 850a0bd7146e819cac577ebd49451b9e0427c10b Mon Sep 17 00:00:00 2001 From: Mingming Yin Date: Wed, 21 May 2014 16:02:53 -0700 Subject: [PATCH 043/243] audio: add support for extended audio features - Add extended enums for audio stream, audio source, audio format, audio channel, audio device, and audio flag. - Update audio API's to support extended features. - Add new API's for compress offload playback, capture, and VOIP features. Change-Id: I8dfd64ac39ee392993e2b977907cd8280952460f Conflicts: include/system/audio.h Conflicts: include/system/audio.h --- include/system/audio.h | 149 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 1 deletion(-) diff --git a/include/system/audio.h b/include/system/audio.h index 39ea0992..c5f37774 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -36,6 +36,13 @@ __BEGIN_DECLS #define AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS "0" /* AudioFlinger and AudioPolicy services use I/O handles to identify audio sources and sinks */ + +#define AMR_FRAMESIZE 32 +#define QCELP_FRAMESIZE 35 +#define EVRC_FRAMESIZE 23 +#define AMR_WB_FRAMESIZE 61 +#define AAC_FRAMESIZE 2048 + typedef int audio_io_handle_t; #define AUDIO_IO_HANDLE_NONE 0 @@ -134,6 +141,8 @@ typedef enum { /* An example of remote presentation is Wifi Display */ /* where a dongle attached to a TV can be used to */ /* play the mix captured by this audio source. */ + AUDIO_SOURCE_FM_RX = 10, + AUDIO_SOURCE_FM_RX_A2DP = 11, AUDIO_SOURCE_CNT, AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1, AUDIO_SOURCE_HOTWORD = 1999, /* A low-priority, preemptible audio source for @@ -229,6 +238,12 @@ typedef enum { AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0, } audio_format_vorbis_sub_fmt_t; +/* DOLBY (AC3/EAC3) sub format field definition: specify dual-mono acmod... */ +typedef enum { + AUDIO_FORMAT_DOLBY_SUB_NONE = 0x0, + AUDIO_FORMAT_DOLBY_SUB_DM = 0x1, /* Clips with the Dual Mono content*/ +} audio_format_dolby_sub_fmt_t; + /* Audio format consists of a main format field (upper 8 bits) and a sub format * field (lower 24 bits). * @@ -252,6 +267,22 @@ typedef enum { AUDIO_FORMAT_OPUS = 0x08000000UL, AUDIO_FORMAT_AC3 = 0x09000000UL, AUDIO_FORMAT_E_AC3 = 0x0A000000UL, + + AUDIO_FORMAT_EVRC = 0x10000000UL, + AUDIO_FORMAT_QCELP = 0x11000000UL, + AUDIO_FORMAT_DTS = 0x120000000UL, + AUDIO_FORMAT_WMA = 0x13000000UL, + AUDIO_FORMAT_WMA_PRO = 0x14000000UL, + AUDIO_FORMAT_AAC_ADIF = 0x15000000UL, + AUDIO_FORMAT_EVRCB = 0x16000000UL, + AUDIO_FORMAT_EVRCWB = 0x17000000UL, + AUDIO_FORMAT_DTS_LBR = 0x18000000UL, + AUDIO_FORMAT_AMR_WB_PLUS = 0x19000000UL, + AUDIO_FORMAT_MP2 = 0x1A000000UL, + AUDIO_FORMAT_EVRCNW = 0x1B000000UL, + AUDIO_FORMAT_PCM_OFFLOAD = 0x1C000000UL, + AUDIO_FORMAT_FLAC = 0x1D000000UL, + AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL, AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL, @@ -268,6 +299,10 @@ typedef enum { AUDIO_FORMAT_PCM_SUB_8_24_BIT), AUDIO_FORMAT_PCM_FLOAT = (AUDIO_FORMAT_PCM | AUDIO_FORMAT_PCM_SUB_FLOAT), + AUDIO_FORMAT_AC3_DM = (AUDIO_FORMAT_AC3 | + AUDIO_FORMAT_DOLBY_SUB_DM), + AUDIO_FORMAT_E_AC3_DM = (AUDIO_FORMAT_E_AC3 | + AUDIO_FORMAT_DOLBY_SUB_DM), AUDIO_FORMAT_PCM_24_BIT_PACKED = (AUDIO_FORMAT_PCM | AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED), AUDIO_FORMAT_AAC_MAIN = (AUDIO_FORMAT_AAC | @@ -290,6 +325,12 @@ typedef enum { AUDIO_FORMAT_AAC_SUB_HE_V2), AUDIO_FORMAT_AAC_ELD = (AUDIO_FORMAT_AAC | AUDIO_FORMAT_AAC_SUB_ELD), + /*Offload PCM formats*/ + AUDIO_FORMAT_PCM_16_BIT_OFFLOAD = (AUDIO_FORMAT_PCM_OFFLOAD | + AUDIO_FORMAT_PCM_SUB_16_BIT), + AUDIO_FORMAT_PCM_24_BIT_OFFLOAD = (AUDIO_FORMAT_PCM_OFFLOAD | + AUDIO_FORMAT_PCM_SUB_8_24_BIT), + } audio_format_t; /* For the channel mask for position assignment representation */ @@ -330,6 +371,9 @@ enum { AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT, AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT | AUDIO_CHANNEL_OUT_FRONT_RIGHT), + AUDIO_CHANNEL_OUT_2POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | + AUDIO_CHANNEL_OUT_FRONT_RIGHT | + AUDIO_CHANNEL_OUT_FRONT_CENTER), AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT | AUDIO_CHANNEL_OUT_FRONT_RIGHT | AUDIO_CHANNEL_OUT_BACK_LEFT | @@ -340,6 +384,12 @@ enum { AUDIO_CHANNEL_OUT_FRONT_RIGHT | AUDIO_CHANNEL_OUT_SIDE_LEFT | AUDIO_CHANNEL_OUT_SIDE_RIGHT), + AUDIO_CHANNEL_OUT_SURROUND = (AUDIO_CHANNEL_OUT_FRONT_LEFT | + AUDIO_CHANNEL_OUT_FRONT_RIGHT | + AUDIO_CHANNEL_OUT_FRONT_CENTER | + AUDIO_CHANNEL_OUT_BACK_CENTER), + AUDIO_CHANNEL_OUT_PENTA = (AUDIO_CHANNEL_OUT_QUAD | + AUDIO_CHANNEL_OUT_FRONT_CENTER), AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | AUDIO_CHANNEL_OUT_FRONT_RIGHT | AUDIO_CHANNEL_OUT_FRONT_CENTER | @@ -354,6 +404,13 @@ enum { AUDIO_CHANNEL_OUT_LOW_FREQUENCY | AUDIO_CHANNEL_OUT_SIDE_LEFT | AUDIO_CHANNEL_OUT_SIDE_RIGHT), + AUDIO_CHANNEL_OUT_6POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | + AUDIO_CHANNEL_OUT_FRONT_RIGHT | + AUDIO_CHANNEL_OUT_FRONT_CENTER | + AUDIO_CHANNEL_OUT_LOW_FREQUENCY | + AUDIO_CHANNEL_OUT_BACK_LEFT | + AUDIO_CHANNEL_OUT_BACK_RIGHT | + AUDIO_CHANNEL_OUT_BACK_CENTER), // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1 AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | AUDIO_CHANNEL_OUT_FRONT_RIGHT | @@ -405,6 +462,15 @@ enum { AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT, AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT), AUDIO_CHANNEL_IN_FRONT_BACK = (AUDIO_CHANNEL_IN_FRONT | AUDIO_CHANNEL_IN_BACK), + AUDIO_CHANNEL_IN_5POINT1 = (AUDIO_CHANNEL_IN_LEFT | + AUDIO_CHANNEL_IN_RIGHT | + AUDIO_CHANNEL_IN_FRONT | + AUDIO_CHANNEL_IN_BACK | + AUDIO_CHANNEL_IN_LEFT_PROCESSED | + AUDIO_CHANNEL_IN_RIGHT_PROCESSED), + AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO = (AUDIO_CHANNEL_IN_VOICE_UPLINK | AUDIO_CHANNEL_IN_MONO), + AUDIO_CHANNEL_IN_VOICE_DNLINK_MONO = (AUDIO_CHANNEL_IN_VOICE_DNLINK | AUDIO_CHANNEL_IN_MONO), + AUDIO_CHANNEL_IN_VOICE_CALL_MONO = (AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO | AUDIO_CHANNEL_IN_VOICE_DNLINK_MONO), AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT | AUDIO_CHANNEL_IN_FRONT | @@ -589,6 +655,8 @@ enum { AUDIO_DEVICE_OUT_AUX_LINE = 0x200000, /* limited-output speaker device for acoustic safety */ AUDIO_DEVICE_OUT_SPEAKER_SAFE = 0x400000, + AUDIO_DEVICE_OUT_FM_TX = 0x1000000, + AUDIO_DEVICE_OUT_PROXY = 0x2000000, AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT, AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE | AUDIO_DEVICE_OUT_SPEAKER | @@ -613,6 +681,8 @@ enum { AUDIO_DEVICE_OUT_FM | AUDIO_DEVICE_OUT_AUX_LINE | AUDIO_DEVICE_OUT_SPEAKER_SAFE | + AUDIO_DEVICE_OUT_FM_TX | + AUDIO_DEVICE_OUT_PROXY | AUDIO_DEVICE_OUT_DEFAULT), AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | @@ -650,6 +720,9 @@ enum { AUDIO_DEVICE_IN_SPDIF = AUDIO_DEVICE_BIT_IN | 0x10000, AUDIO_DEVICE_IN_BLUETOOTH_A2DP = AUDIO_DEVICE_BIT_IN | 0x20000, AUDIO_DEVICE_IN_LOOPBACK = AUDIO_DEVICE_BIT_IN | 0x40000, + AUDIO_DEVICE_IN_PROXY = AUDIO_DEVICE_BIT_IN | 0x100000, + AUDIO_DEVICE_IN_FM_RX = AUDIO_DEVICE_BIT_IN | 0x200000, + AUDIO_DEVICE_IN_FM_RX_A2DP = AUDIO_DEVICE_BIT_IN | 0x400000, AUDIO_DEVICE_IN_DEFAULT = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT, AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION | @@ -671,6 +744,9 @@ enum { AUDIO_DEVICE_IN_SPDIF | AUDIO_DEVICE_IN_BLUETOOTH_A2DP | AUDIO_DEVICE_IN_LOOPBACK | + AUDIO_DEVICE_IN_FM_RX | + AUDIO_DEVICE_IN_FM_RX_A2DP | + AUDIO_DEVICE_IN_PROXY | AUDIO_DEVICE_IN_DEFAULT), AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, AUDIO_DEVICE_IN_ALL_USB = (AUDIO_DEVICE_IN_USB_ACCESSORY | @@ -703,7 +779,11 @@ typedef enum { AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD = 0x10, // offload playback of compressed // streams to hardware codec AUDIO_OUTPUT_FLAG_NON_BLOCKING = 0x20, // use non-blocking write - AUDIO_OUTPUT_FLAG_HW_AV_SYNC = 0x40 // output uses a hardware A/V synchronization source + AUDIO_OUTPUT_FLAG_HW_AV_SYNC = 0x40, // output uses a hardware A/V synchronization source + AUDIO_OUTPUT_FLAG_VOIP_RX = 0x1000, // use this flag in combination with DIRECT to + // indicate HAL to activate EC & NS + // path for VOIP calls + AUDIO_OUTPUT_FLAG_INCALL_MUSIC = 0x2000 //use this flag for incall music delivery } audio_output_flags_t; /* The audio input flags are analogous to audio output flags. @@ -733,6 +813,7 @@ typedef struct { int64_t duration_us; // duration in microseconds, -1 if unknown bool has_video; // true if stream is tied to a video stream bool is_streaming; // true if streaming, false if local playback + uint16_t bit_width; // bits per sample } audio_offload_info_t; #define AUDIO_MAKE_OFFLOAD_INFO_VERSION(maj,min) \ @@ -1244,6 +1325,7 @@ static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t ch * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the * configurations for which a default input channel mask is defined. */ +/* Similar to above, but for input. Currently handles mono, stereo and 5.1 input. */ static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count) { uint32_t bits; @@ -1256,6 +1338,9 @@ static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t cha case 2: bits = AUDIO_CHANNEL_IN_STEREO; break; + case 6: + bits = AUDIO_CHANNEL_IN_5POINT1; + break; default: return AUDIO_CHANNEL_INVALID; } @@ -1308,6 +1393,25 @@ static inline bool audio_is_valid_format(audio_format_t format) case AUDIO_FORMAT_OPUS: case AUDIO_FORMAT_AC3: case AUDIO_FORMAT_E_AC3: + case AUDIO_FORMAT_QCELP: + case AUDIO_FORMAT_EVRC: + case AUDIO_FORMAT_EVRCB: + case AUDIO_FORMAT_EVRCWB: + case AUDIO_FORMAT_AAC_ADIF: + case AUDIO_FORMAT_WMA: + case AUDIO_FORMAT_WMA_PRO: + case AUDIO_FORMAT_DTS: + case AUDIO_FORMAT_DTS_LBR: + case AUDIO_FORMAT_AMR_WB_PLUS: + case AUDIO_FORMAT_MP2: + case AUDIO_FORMAT_EVRCNW: + case AUDIO_FORMAT_FLAC: + return true; + case AUDIO_FORMAT_PCM_OFFLOAD: + if (format != AUDIO_FORMAT_PCM_16_BIT_OFFLOAD && + format != AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) { + return false; + } return true; default: return false; @@ -1319,6 +1423,33 @@ static inline bool audio_is_linear_pcm(audio_format_t format) return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM); } +static inline bool audio_is_offload_pcm(audio_format_t format) +{ + return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM_OFFLOAD); +} + +static inline bool audio_is_compress_capture_format(audio_format_t format) +{ + if (format == AUDIO_FORMAT_AMR_WB) + return true; + else + return false; +} + +static inline bool audio_is_compress_voip_format(audio_format_t format) +{ + + if (format == AUDIO_FORMAT_AMR_NB || + format == AUDIO_FORMAT_AMR_WB || + format == AUDIO_FORMAT_EVRC || + format == AUDIO_FORMAT_EVRCB || + format == AUDIO_FORMAT_EVRCWB || + format == AUDIO_FORMAT_EVRCNW) + return true; + else + return false; +} + static inline size_t audio_bytes_per_sample(audio_format_t format) { size_t size = 0; @@ -1340,7 +1471,23 @@ static inline size_t audio_bytes_per_sample(audio_format_t format) case AUDIO_FORMAT_PCM_FLOAT: size = sizeof(float); break; + case AUDIO_FORMAT_AMR_NB: + size = 32; + break; + case AUDIO_FORMAT_EVRC: + size = 23; + break; + case AUDIO_FORMAT_QCELP: + size = 35; + break; + case AUDIO_FORMAT_AAC: + size = 2048; + break; + case AUDIO_FORMAT_AMR_WB: + size = 61; + break; default: + size = sizeof(uint8_t); break; } return size; From e6e602f78b474dd3e310b2e416bd008a41932b9c Mon Sep 17 00:00:00 2001 From: Mingming Yin Date: Mon, 11 Aug 2014 20:15:48 -0700 Subject: [PATCH 044/243] audio: update enum for AUDIO_FORMAT_DTS - update enum for AUDIO_FORMAT_DTS Change-Id: Id8173c43090f514b673264f0b42c3bb65c051c50 --- include/system/audio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/system/audio.h b/include/system/audio.h index c5f37774..d3b31ee9 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -270,7 +270,7 @@ typedef enum { AUDIO_FORMAT_EVRC = 0x10000000UL, AUDIO_FORMAT_QCELP = 0x11000000UL, - AUDIO_FORMAT_DTS = 0x120000000UL, + AUDIO_FORMAT_DTS = 0x12000000UL, AUDIO_FORMAT_WMA = 0x13000000UL, AUDIO_FORMAT_WMA_PRO = 0x14000000UL, AUDIO_FORMAT_AAC_ADIF = 0x15000000UL, From 20cf83cb12d13762837f7345aa4ac3cc947758d0 Mon Sep 17 00:00:00 2001 From: Piyush Gupta Date: Wed, 23 Jul 2014 18:18:55 -0700 Subject: [PATCH 045/243] Adding use_small_bufs boolean -apq8084 HAL expects use_small_bufs to be present -variable is not being assigned to anything as this is needed for fix compilation Change-Id: I59430dffe84e20ed965cb8053cfe7f03626171d8 --- include/system/audio.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/system/audio.h b/include/system/audio.h index d3b31ee9..788917ea 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -814,6 +814,7 @@ typedef struct { bool has_video; // true if stream is tied to a video stream bool is_streaming; // true if streaming, false if local playback uint16_t bit_width; // bits per sample + bool use_small_bufs; // true if offloading audio track } audio_offload_info_t; #define AUDIO_MAKE_OFFLOAD_INFO_VERSION(maj,min) \ From 17b11af1712dfdf398c6a7d29fdf21ec656f1221 Mon Sep 17 00:00:00 2001 From: Manu Gautam Date: Thu, 10 Jul 2014 15:46:00 +0530 Subject: [PATCH 046/243] Revert "adbd: Don't close/reopen FFS ep0 on disconnect" This reverts commit b5d385f1ef38ad0c163598c3a4e167d4ae9df3c6. Commit b5d385f "adbd: Don't close/reopen FFS ep0 on disconnect" fixes USBCV chapter 9 failures due to re-enumeration as part of reopening FFS ep0 handle. This was done from usb_kick function which gets invoked whenever adb read/write fails. But, not allowing USB re-enumeration on real IO failures results in adb to go offline and only way to recover is by re-connecting USB cable. As ADB function is used for debugging and USBCV tests are not mandatory, hence, revert original change to allow USB enumeration on any read/write failures. CRs-fixed: 689512 Change-Id: Ic0b38223761b7c0eb3e2c54328e88010297318fb --- adb/usb_linux_client.c | 43 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/adb/usb_linux_client.c b/adb/usb_linux_client.c index be7eb2be..e3e1057f 100644 --- a/adb/usb_linux_client.c +++ b/adb/usb_linux_client.c @@ -313,25 +313,23 @@ static void init_functionfs(struct usb_handle *h) { ssize_t ret; - if (h->control < 0) { // might have already done this before - D("OPENING %s\n", USB_FFS_ADB_EP0); - h->control = adb_open(USB_FFS_ADB_EP0, O_RDWR); - if (h->control < 0) { - D("[ %s: cannot open control endpoint: errno=%d]\n", USB_FFS_ADB_EP0, errno); - goto err; - } + D("OPENING %s\n", USB_FFS_ADB_EP0); + h->control = adb_open(USB_FFS_ADB_EP0, O_RDWR); + if (h->control < 0) { + D("[ %s: cannot open control endpoint: errno=%d]\n", USB_FFS_ADB_EP0, errno); + goto err; + } - ret = adb_write(h->control, &descriptors, sizeof(descriptors)); - if (ret < 0) { - D("[ %s: write descriptors failed: errno=%d ]\n", USB_FFS_ADB_EP0, errno); - goto err; - } + ret = adb_write(h->control, &descriptors, sizeof(descriptors)); + if (ret < 0) { + D("[ %s: write descriptors failed: errno=%d ]\n", USB_FFS_ADB_EP0, errno); + goto err; + } - ret = adb_write(h->control, &strings, sizeof(strings)); - if (ret < 0) { - D("[ %s: writing strings failed: errno=%d]\n", USB_FFS_ADB_EP0, errno); - goto err; - } + ret = adb_write(h->control, &strings, sizeof(strings)); + if (ret < 0) { + D("[ %s: writing strings failed: errno=%d]\n", USB_FFS_ADB_EP0, errno); + goto err; } h->bulk_out = adb_open(USB_FFS_ADB_OUT, O_RDWR); @@ -371,14 +369,14 @@ static void *usb_ffs_open_thread(void *x) while (1) { // wait until the USB device needs opening adb_mutex_lock(&usb->lock); - while (usb->control != -1 && usb->bulk_in != -1 && usb->bulk_out != -1) + while (usb->control != -1) adb_cond_wait(&usb->notify, &usb->lock); adb_mutex_unlock(&usb->lock); while (1) { init_functionfs(usb); - if (usb->control >= 0 && usb->bulk_in >= 0 && usb->bulk_out >= 0) + if (usb->control >= 0) break; adb_sleep_ms(1000); @@ -475,13 +473,10 @@ static void usb_ffs_kick(usb_handle *h) D("[ kick: sink (fd=%d) clear halt failed (%d) ]", h->bulk_out, errno); adb_mutex_lock(&h->lock); - - // don't close ep0 here, since we may not need to reinitialize it with - // the same descriptors again. if however ep1/ep2 fail to re-open in - // init_functionfs, only then would we close and open ep0 again. + adb_close(h->control); adb_close(h->bulk_out); adb_close(h->bulk_in); - h->bulk_out = h->bulk_in = -1; + h->control = h->bulk_out = h->bulk_in = -1; // notify usb_ffs_open_thread that we are disconnected adb_cond_signal(&h->notify); From 16b08549d4d25936641ec3e57500bcc7c4a438f7 Mon Sep 17 00:00:00 2001 From: David Brown Date: Mon, 8 Sep 2014 13:25:36 -0700 Subject: [PATCH 047/243] fs_mgr: wait for device-mapper control file When setting up a verified mountpoint, wait for the /dev/device-mapper control node to appear. Change-Id: I50bb64213fe08ba7b552055045d35915903fb532 --- fs_mgr/fs_mgr.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index 91e6c332..cb881548 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -352,6 +352,7 @@ int fs_mgr_mount_all(struct fstab *fstab) if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && !device_is_debuggable()) { + wait_for_file("/dev/device-mapper", WAIT_TIMEOUT); if (fs_mgr_setup_verity(&fstab->recs[i]) < 0) { ERROR("Could not set up verified partition, skipping!\n"); continue; From b5c316edebda0ed22c99ef3503f0b73b8a6a4ce9 Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Wed, 10 Sep 2014 17:34:22 +0800 Subject: [PATCH 048/243] healthd: Update battery status before the mainloop If the alarm is the first event to trigger, the charging animation won't be seen before that when healthd working at off mode charging. Do the periodic chores and heartbeat before the mainloop, this makes battery status be updated immediately and charging animation shows timely in off mode charging. Change-Id: I48268930469069882b8e4efafa6d063f8e8e8dd2 --- healthd/healthd.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/healthd/healthd.cpp b/healthd/healthd.cpp index 30a4b426..6f0c4b7d 100644 --- a/healthd/healthd.cpp +++ b/healthd/healthd.cpp @@ -356,6 +356,9 @@ int main(int argc, char **argv) { exit(2); } + periodic_chores(); + healthd_mode_ops->heartbeat(); + healthd_mainloop(); KLOG_ERROR("Main loop terminated, exiting\n"); return 3; From 0fa9518969a6dacd5437cf1472a9313b10299747 Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Thu, 11 Sep 2014 10:15:03 +0800 Subject: [PATCH 049/243] healthd: charger: Add tricolor led to indicate battery capacity Add led to indicate battery capacity when doing off mode charging. The led behavior is design as below: i. Shows red led if capacity is lower than 15%. ii. Shows yellow (red + green) led if capacity is lower than 90% but higher than 15%. iii. Shows green led if capacity is higher than 90%. Change-Id: If637defec8a04e859b00a6492ec1f95d6bff2200 --- healthd/healthd_mode_charger.cpp | 87 ++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 394feb81..710f2bfa 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -73,6 +73,9 @@ char *locale; #define LAST_KMSG_PATH "/proc/last_kmsg" #define LAST_KMSG_PSTORE_PATH "/sys/fs/pstore/console-ramoops" #define LAST_KMSG_MAX_SZ (32 * 1024) +#define RED_LED_PATH "/sys/class/leds/red/brightness" +#define GREEN_LED_PATH "/sys/class/leds/green/brightness" +#define BLUE_LED_PATH "/sys/class/leds/blue/brightness" #define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0) #define LOGI(x...) do { KLOG_INFO("charger", x); } while (0) @@ -169,12 +172,87 @@ static struct animation battery_animation = { .capacity = 0, }; +enum { + RED_LED = 0x01 << 0, + GREEN_LED = 0x01 << 1, + BLUE_LED = 0x01 << 2, +}; + +struct led_ctl { + int color; + const char *path; +}; + +struct led_ctl leds[3] = + {{RED_LED, RED_LED_PATH}, + {GREEN_LED, GREEN_LED_PATH}, + {BLUE_LED, BLUE_LED_PATH}}; + +struct soc_led_color_mapping { + int soc; + int color; +}; + +struct soc_led_color_mapping soc_leds[3] = { + {15, RED_LED}, + {90, RED_LED | GREEN_LED}, + {100, GREEN_LED}, +}; + static struct charger charger_state; static int char_width; static int char_height; static bool minui_inited; +static int set_tricolor_led(int on, int color) +{ + int fd, i; + char buffer[10]; + + for (i = 0; i < (int)ARRAY_SIZE(leds); i++) { + if ((color & leds[i].color) && (access(leds[i].path, R_OK | W_OK) == 0)) { + fd = open(leds[i].path, O_RDWR); + if (fd < 0) { + LOGE("Could not open red led node\n"); + goto cleanup; + } + if (on) + snprintf(buffer, sizeof(int), "%d\n", 255); + else + snprintf(buffer, sizeof(int), "%d\n", 0); + + if (write(fd, buffer, strlen(buffer)) < 0) + LOGE("Could not write to led node\n"); +cleanup: + if (fd >= 0) + close(fd); + } + } + + return 0; +} + +static int set_battery_soc_leds(int soc) +{ + int i, color; + static int old_color = 0; + + for (i = 0; i < (int)ARRAY_SIZE(soc_leds); i++) { + if (soc < soc_leds[i].soc) + break; + } + color = soc_leds[i].color; + if (old_color != color) { + set_tricolor_led(0, old_color); + set_tricolor_led(1, color); + old_color = color; + LOGV("soc = %d, set led color 0x%x\n", soc, soc_leds[i].color); + } + + return 0; +} + /* current time in milliseconds */ static int64_t curr_time_ms(void) { @@ -561,9 +639,18 @@ static void handle_input_state(struct charger *charger, int64_t now) static void handle_power_supply_state(struct charger *charger, int64_t now) { + static int old_soc = 0; + int soc; + if (!charger->have_battery_state) return; + soc = get_battery_capacity(); + if (old_soc != soc) { + old_soc = soc; + set_battery_soc_leds(soc); + } + if (!charger->charger_connected) { request_suspend(false); if (charger->next_pwr_check == -1) { From 7c7f9195de1caba3f97a7962669c5c235f112bbf Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Wed, 10 Sep 2014 18:15:56 +0800 Subject: [PATCH 050/243] healthd: charger: Turn off charging animation by power key event Currently, the charging animation can be turned on by power key event. Add support to make charging animation can be turned off by power key event. Change-Id: Icc8101ae3d4fd777efedeff10ca535a9e6e7a57d --- healthd/healthd_mode_charger.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 710f2bfa..9258c698 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -594,6 +594,7 @@ static void set_next_key_check(struct charger *charger, static void process_key(struct charger *charger, int code, int64_t now) { + struct animation *batt_anim = charger->batt_anim; struct key_state *key = &charger->keys[code]; int64_t next_key_check; @@ -620,8 +621,16 @@ static void process_key(struct charger *charger, int code, int64_t now) } else { /* if the power key got released, force screen state cycle */ if (key->pending) { - request_suspend(false); - kick_animation(charger->batt_anim); + if (!batt_anim->run) { + request_suspend(false); + kick_animation(batt_anim); + } else { + reset_animation(batt_anim); + charger->next_screen_transition = -1; + gr_fb_blank(true); + if (charger->charger_connected) + request_suspend(true); + } } } } From 6f2c414d69fc1f4edbcc4f055213573ab90381b6 Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Fri, 12 Sep 2014 11:07:28 +0800 Subject: [PATCH 051/243] healthd: charger: Draw battery capacity in charging animation Draw a text to show the battery capacity value in charging animation. Change-Id: I0117fb0aee69181ce0d608ba4b1644fa42cd1a0d --- healthd/healthd_mode_charger.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 9258c698..b9ba22b7 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -399,6 +399,21 @@ static void draw_battery(struct charger *charger) } } +#define STR_LEN 64 +static void draw_capacity(struct charger *charger) +{ + char cap_str[STR_LEN]; + int x, y; + int str_len_px; + + snprintf(cap_str, (STR_LEN - 1), "%d%%", charger->batt_anim->capacity); + str_len_px = gr_measure(cap_str); + x = (gr_fb_width() - str_len_px) / 2; + y = (gr_fb_height() + char_height) / 2; + android_green(); + gr_text(x, y, cap_str, 0); +} + static void redraw_screen(struct charger *charger) { struct animation *batt_anim = charger->batt_anim; @@ -406,10 +421,12 @@ static void redraw_screen(struct charger *charger) clear_screen(); /* try to display *something* */ - if (batt_anim->capacity < 0 || batt_anim->num_frames == 0) + if (batt_anim->capacity < 0 || batt_anim->num_frames == 0) { draw_unknown(charger); - else + } else { draw_battery(charger); + draw_capacity(charger); + } gr_flip(); } From 2e8628e9685c62b2cf881ba9f5aef406713f0175 Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Fri, 12 Sep 2014 14:21:08 +0800 Subject: [PATCH 052/243] healthd: charger: Modify charger unplug shutdown time to 1s Modify UNPLUGGED_SHUTDOWN_TIME from 10 seconds to 1 second to make sure device can shutdown quickly after charger is plugged out. Change-Id: I73f149295ca73756a210e7cb3dd61f955aa18165 --- healthd/healthd_mode_charger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index b9ba22b7..c7e6ef90 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -65,7 +65,7 @@ char *locale; #define BATTERY_UNKNOWN_TIME (2 * MSEC_PER_SEC) #define POWER_ON_KEY_TIME (2 * MSEC_PER_SEC) -#define UNPLUGGED_SHUTDOWN_TIME (10 * MSEC_PER_SEC) +#define UNPLUGGED_SHUTDOWN_TIME (1 * MSEC_PER_SEC) #define BATTERY_FULL_THRESH 95 #define SCREEN_ON_BATTERY_THRESH 0 From 68737e6d108eb3a476a38b6bdbea2eb99a736216 Mon Sep 17 00:00:00 2001 From: Ameya Thakur Date: Thu, 21 Feb 2013 11:27:43 -0800 Subject: [PATCH 053/243] init: add 'ffbm' action trigger when booting in factory mode Android init process was extedned to recognize new boot mode and start only required services for this mode. Init process will add new action trigger 'ffbm', which will take care of rest of the initialization process. 'ffbm' action trigger is defined in Qualcomm's private init.rc file. It's functionality is identical with main Android's 'boot' action triger except it doesnt add trigger actions 'core' and 'main'. Action trigger will start only minimal set of services (media, adb, qcom-post-boot, rmt_storage) required for test environment to operate correctly . Change-Id: If74201f83d663e2f2932720cc3ecb494a61a854e --- init/builtins.c | 9 ++++++--- init/init.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/init/builtins.c b/init/builtins.c index 081759a5..3957a769 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -551,6 +551,7 @@ int do_mount_all(int nargs, char **args) int ret = -1; int child_ret = -1; int status; + char boot_mode[PROP_VALUE_MAX]; const char *prop; struct fstab *fstab; @@ -600,10 +601,12 @@ int do_mount_all(int nargs, char **args) property_set("vold.decrypt", "trigger_default_encryption"); } else if (ret == FS_MGR_MNTALL_DEV_NOT_ENCRYPTED) { property_set("ro.crypto.state", "unencrypted"); - /* If fs_mgr determined this is an unencrypted device, then trigger - * that action. + /* If fs_mgr determined this is an unencrypted device and we are + * not booting into ffbm then trigger that action. */ - action_for_each_trigger("nonencrypted", action_add_queue_tail); + property_get("ro.bootmode", boot_mode); + if (strncmp(boot_mode, "ffbm", 4)) + action_for_each_trigger("nonencrypted", action_add_queue_tail); } else if (ret == FS_MGR_MNTALL_DEV_NEEDS_RECOVERY) { /* Setup a wipe via recovery, and reboot into recovery */ ERROR("fs_mgr_mount_all suggested recovery, so wiping data via recovery.\n"); diff --git a/init/init.c b/init/init.c index bd1db7a5..90a217ce 100644 --- a/init/init.c +++ b/init/init.c @@ -1009,6 +1009,7 @@ int main(int argc, char **argv) int signal_fd_init = 0; int keychord_fd_init = 0; bool is_charger = false; + bool is_ffbm = false; if (!strcmp(basename(argv[0]), "ueventd")) return ueventd_main(argc, argv); @@ -1068,7 +1069,9 @@ int main(int argc, char **argv) restorecon("/dev/__properties__"); restorecon_recursive("/sys"); - is_charger = !strcmp(bootmode, "charger"); + is_ffbm = !strncmp(bootmode, "ffbm", 4); + if (!is_ffbm) + is_charger = !strcmp(bootmode, "charger"); INFO("property init\n"); property_load_boot_defaults(); @@ -1097,9 +1100,12 @@ int main(int argc, char **argv) if (is_charger) { action_for_each_trigger("charger", action_add_queue_tail); } else { - action_for_each_trigger("late-init", action_add_queue_tail); + if (is_ffbm) { + action_for_each_trigger("ffbm", action_add_queue_tail); + } else { + action_for_each_trigger("late-init", action_add_queue_tail); + } } - /* run all property triggers based on current state of the properties */ queue_builtin_action(queue_property_triggers_action, "queue_property_triggers"); From 1d4d251256e996931d29595a80e60fb527035e03 Mon Sep 17 00:00:00 2001 From: Biswajit Paul Date: Tue, 30 Sep 2014 14:16:59 -0700 Subject: [PATCH 054/243] Added No Follow symlink option to chmod. Enable symlink to not follow target file if "-h" option is provided. Change-Id: If6423ceb8474fe6c48229a16568dc07ea4754b6c --- toolbox/chmod.c | 86 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 19 deletions(-) diff --git a/toolbox/chmod.c b/toolbox/chmod.c index 2a524e99..96d1fda4 100644 --- a/toolbox/chmod.c +++ b/toolbox/chmod.c @@ -9,16 +9,20 @@ #include #include +#include +#include -void recurse_chmod(char* path, int mode) +void recurse_chmod(char* path, int mode, unsigned int flag) { struct dirent *dp; DIR *dir = opendir(path); + int fd = 0; if (dir == NULL) { // not a directory, carry on return; } - char *subpath = malloc(sizeof(char)*PATH_MAX); + int maxpathlen = sizeof(char)*PATH_MAX; + char *subpath = malloc(maxpathlen); int pathlen = strlen(path); while ((dp = readdir(dir)) != NULL) { @@ -30,16 +34,23 @@ void recurse_chmod(char* path, int mode) exit(1); } - strcpy(subpath, path); - strcat(subpath, "/"); - strcat(subpath, dp->d_name); - - if (chmod(subpath, mode) < 0) { - fprintf(stderr, "Unable to chmod %s: %s\n", subpath, strerror(errno)); + strlcpy(subpath, path, maxpathlen); + strlcat(subpath, "/", maxpathlen); + strlcat(subpath, dp->d_name, maxpathlen); + + if(((fd = open(subpath, flag|O_RDONLY)) != -1) || ((fd = open(subpath, flag|O_WRONLY)) != -1)) { + if (fchmod(fd, mode) < 0){ + fprintf(stderr, "Unable to chmod %s: %s\n", subpath, strerror(errno)); + close(fd); + exit(1); + } + close(fd); + } else { + fprintf(stderr, "Unable to open %s: %s\n", subpath, strerror(errno)); exit(1); } - recurse_chmod(subpath, mode); + recurse_chmod(subpath, mode, flag); } free(subpath); closedir(dir); @@ -49,6 +60,7 @@ static int usage() { fprintf(stderr, "Usage: chmod [OPTION] \n"); fprintf(stderr, " -R, --recursive change files and directories recursively\n"); + fprintf(stderr, " -h, --no-dereference do not follow symlink\n"); fprintf(stderr, " --help display this help and exit\n"); return 10; @@ -57,15 +69,37 @@ static int usage() int chmod_main(int argc, char **argv) { int i; + int noFollow = 0; + int fd = 0; + int ch = 0; + int recursive = 0; + unsigned int flag =0; + int help = 0; + static struct option long_options[] = + { + {"help", no_argument, 0, 'H'}, + {"recursive", no_argument, 0, 'R'}, + {"no-dereference", no_argument, 0, 'h'} + }; + /* getopt_long stores the option index here. */ + int option_index = 0; + while((ch = getopt_long(argc, argv, "HhR",long_options,&option_index)) != -1) + switch(ch){ + case 'H': + help = 1; + break; + case 'R': + recursive = 1; + break; + case 'h': + noFollow = 1; + break; + default: + break; - if (argc < 3 || strcmp(argv[1], "--help") == 0) { - return usage(); } - int recursive = (strcmp(argv[1], "-R") == 0 || - strcmp(argv[1], "--recursive") == 0) ? 1 : 0; - - if (recursive && argc < 4) { + if (argc < 3 || help || (recursive && argc < 4)) { return usage(); } @@ -73,7 +107,15 @@ int chmod_main(int argc, char **argv) argc--; argv++; } + if (noFollow && argc < 4) { + return usage(); + } + if(noFollow) { + flag = O_NOFOLLOW; + argc--; + argv++; + } int mode = 0; const char* s = argv[1]; while (*s) { @@ -88,14 +130,20 @@ int chmod_main(int argc, char **argv) } for (i = 2; i < argc; i++) { - if (chmod(argv[i], mode) < 0) { - fprintf(stderr, "Unable to chmod %s: %s\n", argv[i], strerror(errno)); + if(((fd = open(argv[i], flag|O_RDONLY )) != -1)||((fd = open(argv[i], flag|O_WRONLY )) != -1)) { + if (fchmod(fd, mode) < 0){ + fprintf(stderr, "Unable to chmod %s: %s\n", argv[i], strerror(errno)); + close(fd); + return 10; + } + close(fd); + } else { + fprintf(stderr, "Unable to open %s: %s\n", argv[i], strerror(errno)); return 10; } if (recursive) { - recurse_chmod(argv[i], mode); + recurse_chmod(argv[i], mode, flag); } } return 0; } - From 19cc4a3e0d42d2039d598723120de7fac62b6a69 Mon Sep 17 00:00:00 2001 From: Matthew Qin Date: Mon, 29 Sep 2014 15:13:32 +0800 Subject: [PATCH 055/243] healthd: charger: Support alarm in power off charging mode To implement this feature need to let the phone reboot some time earlier than the alarm time. CRs-fixed: 727939 Change-Id: I67832ec089eddd436a4daee7c6808ab2eaa69213 --- healthd/healthd_mode_charger.cpp | 179 +++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index c7e6ef90..4eef867c 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -40,6 +40,10 @@ #include #include +#include +#include +#include + #ifdef CHARGER_ENABLE_SUSPEND #include #endif @@ -205,6 +209,17 @@ static int char_width; static int char_height; static bool minui_inited; +enum alarm_time_type { + ALARM_TIME, + RTC_TIME, +}; + +/* + * shouldn't be changed after + * reading from alarm register + */ +static time_t alm_secs; + static int set_tricolor_led(int on, int color) { int fd, i; @@ -782,6 +797,168 @@ static void charger_event_handler(uint32_t /*epevents*/) ev_dispatch(); } +static int alarm_get_time(enum alarm_time_type time_type, + time_t *secs) +{ + struct tm tm; + unsigned int cmd; + int rc, fd = -1; + + if (!secs) + goto err; + + fd = open("/dev/rtc0", O_RDWR); + if (fd < 0) { + LOGE("Can't open rtc devfs node\n"); + goto err; + } + + switch (time_type) { + case ALARM_TIME: + cmd = RTC_ALM_READ; + break; + case RTC_TIME: + cmd = RTC_RD_TIME; + break; + default: + LOGE("Invalid time type\n"); + goto err; + } + + rc = ioctl(fd, cmd, &tm); + if (rc < 0) { + LOGE("Unable to get time\n"); + goto err; + } + + close(fd); + + *secs = mktime(&tm) + tm.tm_gmtoff; + if (*secs < 0) { + LOGE("Invalid seconds = %ld\n", *secs); + goto err; + } + + return 0; + +err: + if (fd >= 0) + close(fd); + return -1; +} + +#define ERR_SECS 2 +static int alarm_is_alm_expired() +{ + int rc; + time_t rtc_secs; + + rc = alarm_get_time(RTC_TIME, &rtc_secs); + if (rc < 0) + return 0; + + return (alm_secs >= rtc_secs - ERR_SECS && + alm_secs <= rtc_secs + ERR_SECS) ? 1 : 0; +} + +static int alarm_set_reboot_time_and_wait(time_t secs) +{ + int rc, fd; + struct timespec ts; + + fd = open("/dev/alarm", O_RDWR); + if (fd < 0) { + LOGE("Can't open alarm devfs node\n"); + goto err; + } + + /* get the elapsed realtime from boot time to now */ + rc = ioctl(fd, ANDROID_ALARM_GET_TIME( + ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP), &ts); + if (rc < 0) { + LOGE("Unable to get elapsed realtime\n"); + goto err; + } + + /* calculate the elapsed time from boot time to reboot time */ + ts.tv_sec += secs; + ts.tv_nsec = 0; + + rc = ioctl(fd, ANDROID_ALARM_SET( + ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP), &ts); + if (rc < 0) { + LOGE("Unable to set reboot time to %ld\n", secs); + goto err; + } + + do { + rc = ioctl(fd, ANDROID_ALARM_WAIT); + } while ((rc < 0 && errno == EINTR) || !alarm_is_alm_expired()); + + if (rc <= 0) { + LOGE("Unable to wait on alarm\n"); + goto err; + } + + close(fd); + return 0; + +err: + if (fd >= 0) + close(fd); + return -1; +} + +void *alarm_thread(void *) +{ + time_t rtc_secs, rb_secs; + int rc; + + /* + * to support power off alarm, the time + * stored in alarm register at latest + * shutdown time should be some time + * earlier than the actual alarm time + * set by user + */ + rc = alarm_get_time(ALARM_TIME, &alm_secs); + if (rc < 0 || !alm_secs) + goto err; + + rc = alarm_get_time(RTC_TIME, &rtc_secs); + if (rc < 0) + goto err; + + /* + * calculate the reboot time after which + * the phone will reboot + */ + rb_secs = alm_secs - rtc_secs; + if (rb_secs <= 0) + goto err; + + rc = alarm_set_reboot_time_and_wait(rb_secs); + if (rc < 0) + goto err; + + LOGI("Exit from power off charging, reboot the phone!\n"); + android_reboot(ANDROID_RB_RESTART2, 0, (char *)"rtc"); + +err: + LOGE("Exit from alarm thread\n"); + return NULL; +} + +void alarm_thread_create() +{ + pthread_t tid; + int rc; + + rc = pthread_create(&tid, NULL, alarm_thread, NULL); + if (rc < 0) + LOGE("Create alarm thread failed\n"); +} + void healthd_mode_charger_init(struct healthd_config* /*config*/) { int ret; @@ -791,6 +968,8 @@ void healthd_mode_charger_init(struct healthd_config* /*config*/) dump_last_kmsg(); + alarm_thread_create(); + LOGI("--------------- STARTING CHARGER MODE ---------------\n"); ret = ev_init(input_callback, charger); From 1e961c044c13b25f7d7918f0259662b7bcafe8ff Mon Sep 17 00:00:00 2001 From: Fenglin Wu Date: Wed, 10 Sep 2014 17:37:14 +0800 Subject: [PATCH 056/243] healthd: charger: Add backlight control in charging animation On some targets the FBIOBLANK does not control the backlight. Add the backlight control in charging animation to make sure the backlight will be turned on/off successfully. Change-Id: I3bba3b58daba6cffa4eb1314a6da1542f43e8e47 --- healthd/healthd_mode_charger.cpp | 38 ++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 4eef867c..912d9d6e 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -80,6 +80,7 @@ char *locale; #define RED_LED_PATH "/sys/class/leds/red/brightness" #define GREEN_LED_PATH "/sys/class/leds/green/brightness" #define BLUE_LED_PATH "/sys/class/leds/blue/brightness" +#define BACKLIGHT_PATH "/sys/class/leds/lcd-backlight/brightness" #define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0) #define LOGI(x...) do { KLOG_INFO("charger", x); } while (0) @@ -268,6 +269,37 @@ static int set_battery_soc_leds(int soc) return 0; } +#define BACKLIGHT_ON_LEVEL 100 +static int set_backlight_on(void) +{ + int fd; + char buffer[10]; + + if (access(BACKLIGHT_PATH, R_OK | W_OK) != 0) + { + LOGI("Backlight control not support\n"); + return 0; + } + + memset(buffer, '\0', sizeof(buffer)); + fd = open(BACKLIGHT_PATH, O_RDWR); + if (fd < 0) { + LOGE("Could not open backlight node : %s\n", strerror(errno)); + goto cleanup; + } + LOGV("Enabling backlight\n"); + snprintf(buffer, sizeof(buffer), "%d\n", BACKLIGHT_ON_LEVEL); + if (write(fd, buffer,strlen(buffer)) < 0) { + LOGE("Could not write to backlight node : %s\n", strerror(errno)); + goto cleanup; + } +cleanup: + if (fd >= 0) + close(fd); + + return 0; +} + /* current time in milliseconds */ static int64_t curr_time_ms(void) { @@ -524,9 +556,11 @@ static void update_screen_state(struct charger *charger, int64_t now) batt_anim->capacity = batt_cap; } - /* unblank the screen on first cycle */ - if (batt_anim->cur_cycle == 0) + /* unblank the screen on first cycle */ + if (batt_anim->cur_cycle == 0) { + set_backlight_on(); gr_fb_blank(false); + } /* draw the new frame (@ cur_frame) */ redraw_screen(charger); From 402ff9fd8a89bbaeb7da1136d1b1ec2272effa9e Mon Sep 17 00:00:00 2001 From: Biswajit Paul Date: Thu, 2 Oct 2014 18:40:35 -0700 Subject: [PATCH 057/243] ueventd: Add bootdevice links support for selinux Adding bootdevice support to define context on common symlink. Change-Id: I25d7239614539d1ef2c9920e2c321824ee2c664b --- init/devices.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/init/devices.c b/init/devices.c index 49207c10..faefae3c 100644 --- a/init/devices.c +++ b/init/devices.c @@ -561,10 +561,10 @@ static char **get_block_device_symlinks(struct uevent *uevent) return NULL; } - char **links = malloc(sizeof(char *) * 4); + char **links = malloc(sizeof(char *) * 6); if (!links) return NULL; - memset(links, 0, sizeof(char *) * 4); + memset(links, 0, sizeof(char *) * 6); INFO("found %s device %s\n", type, device); @@ -579,6 +579,11 @@ static char **get_block_device_symlinks(struct uevent *uevent) link_num++; else links[link_num] = NULL; + if (asprintf(&links[link_num], "/dev/block/bootdevice/by-name/%s", p) > 0) + link_num++; + else + links[link_num] = NULL; + free(p); } @@ -587,6 +592,11 @@ static char **get_block_device_symlinks(struct uevent *uevent) link_num++; else links[link_num] = NULL; + + if (asprintf(&links[link_num], "/dev/block/bootdevice/by-num/p%d", uevent->partition_num) > 0) + link_num++; + else + links[link_num] = NULL; } slash = strrchr(uevent->path, '/'); From 65745d12fd0af9c0ffc7ef8c94bcdbc25788b9ce Mon Sep 17 00:00:00 2001 From: haiyangl Date: Wed, 10 Sep 2014 10:48:39 +0800 Subject: [PATCH 058/243] Init: Modify user/group option for bootanim Change the user to media and add audio group for bootanimation to support both audio and graphics. Conflicts: rootdir/init.rc Change-Id: Ia716c24a413a161e2995543ca503e0175aa1d041 --- rootdir/init.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootdir/init.rc b/rootdir/init.rc index 5a27aec2..5c49f438 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -593,7 +593,7 @@ service encrypt /system/bin/vdc --wait cryptfs enablecrypto inplace default service bootanim /system/bin/bootanimation class core - user graphics + user media group graphics audio disabled oneshot From 3dce64802e93ef24e34250b128a565fbf3c6221e Mon Sep 17 00:00:00 2001 From: Krishnankutty Kolathappilly Date: Sun, 30 Mar 2014 14:56:09 -0700 Subject: [PATCH 059/243] system/core: Add flag for HDMI compressed passthrough Add audio output flags to support compressed passthrough over HDMI for DD/DDP contents. Change-Id: I308eca2c250591e3e3d6d6d28b6f67440ae3310d --- include/system/audio.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/system/audio.h b/include/system/audio.h index 788917ea..1d904652 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -783,7 +783,9 @@ typedef enum { AUDIO_OUTPUT_FLAG_VOIP_RX = 0x1000, // use this flag in combination with DIRECT to // indicate HAL to activate EC & NS // path for VOIP calls - AUDIO_OUTPUT_FLAG_INCALL_MUSIC = 0x2000 //use this flag for incall music delivery + AUDIO_OUTPUT_FLAG_INCALL_MUSIC = 0x2000, //use this flag for incall music delivery + // flag for HDMI compressed passthrough + AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH = 0x4000 } audio_output_flags_t; /* The audio input flags are analogous to audio output flags. From 79c4a778b6dfd124d51bfec575e22d876daa4cfb Mon Sep 17 00:00:00 2001 From: Krishnankutty Kolathappilly Date: Tue, 8 Jul 2014 16:39:44 -0700 Subject: [PATCH 060/243] system/core: Add support for JOC format Add support for EAC3 JOC format to core. Add EAC3 JOC format as a valid format. Change-Id: I2a396a570421c66df84a874cde6f3616392c6ba1 --- include/system/audio.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/system/audio.h b/include/system/audio.h index 1d904652..891ecc0c 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -282,7 +282,7 @@ typedef enum { AUDIO_FORMAT_EVRCNW = 0x1B000000UL, AUDIO_FORMAT_PCM_OFFLOAD = 0x1C000000UL, AUDIO_FORMAT_FLAC = 0x1D000000UL, - + AUDIO_FORMAT_E_AC3_JOC = 0x1E000000UL, AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL, AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL, @@ -1409,6 +1409,7 @@ static inline bool audio_is_valid_format(audio_format_t format) case AUDIO_FORMAT_MP2: case AUDIO_FORMAT_EVRCNW: case AUDIO_FORMAT_FLAC: + case AUDIO_FORMAT_E_AC3_JOC: return true; case AUDIO_FORMAT_PCM_OFFLOAD: if (format != AUDIO_FORMAT_PCM_16_BIT_OFFLOAD && From 159fef7daa712aeb3cf3fc64b109a4e8d49f11da Mon Sep 17 00:00:00 2001 From: Jie Cheng Date: Thu, 23 Oct 2014 16:05:14 +0800 Subject: [PATCH 061/243] charger: check the charging_enabled at the beginning of power off charging Check charging_enabled flag in power off charging process, reboot the device if charging is disabled to exit power off charging mode. Change-Id: I11208acb1dd82a06b42911fdbcc7e58f6f97e96c --- healthd/healthd_mode_charger.cpp | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 912d9d6e..d8a364fd 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -81,6 +81,7 @@ char *locale; #define GREEN_LED_PATH "/sys/class/leds/green/brightness" #define BLUE_LED_PATH "/sys/class/leds/blue/brightness" #define BACKLIGHT_PATH "/sys/class/leds/lcd-backlight/brightness" +#define CHARGING_ENABLED_PATH "/sys/class/power_supply/battery/charging_enabled" #define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0) #define LOGI(x...) do { KLOG_INFO("charger", x); } while (0) @@ -365,6 +366,56 @@ static void dump_last_kmsg(void) LOGI("\n"); } +static int read_file(const char *path, char *buf, size_t sz) +{ + int fd; + size_t cnt; + + fd = open(path, O_RDONLY, 0); + if (fd < 0) + goto err; + + cnt = read(fd, buf, sz - 1); + if (cnt <= 0) + goto err; + buf[cnt] = '\0'; + if (buf[cnt - 1] == '\n') { + cnt--; + buf[cnt] = '\0'; + } + + close(fd); + return cnt; + +err: + if (fd >= 0) + close(fd); + return -1; +} + +static int read_file_int(const char *path, int *val) +{ + char buf[32]; + int ret; + int tmp; + char *end; + + ret = read_file(path, buf, sizeof(buf)); + if (ret < 0) + return -1; + + tmp = strtol(buf, &end, 0); + if (end == buf || + ((end < buf+sizeof(buf)) && (*end != '\n' && *end != '\0'))) + goto err; + + *val = tmp; + return 0; + +err: + return -1; +} + static int get_battery_capacity() { return charger_state.capacity; @@ -996,6 +1047,7 @@ void alarm_thread_create() void healthd_mode_charger_init(struct healthd_config* /*config*/) { int ret; + int charging_enabled = 1; struct charger *charger = &charger_state; int i; int epollfd; @@ -1006,6 +1058,14 @@ void healthd_mode_charger_init(struct healthd_config* /*config*/) LOGI("--------------- STARTING CHARGER MODE ---------------\n"); + /* check the charging is enabled or not */ + ret = read_file_int(CHARGING_ENABLED_PATH, &charging_enabled); + if (!ret && !charging_enabled) { + /* if charging is disabled, reboot and exit power off charging */ + LOGI("android charging is disabled, exit!\n"); + android_reboot(ANDROID_RB_RESTART, 0, 0); + } + ret = ev_init(input_callback, charger); if (!ret) { epollfd = ev_get_epollfd(); From 8c4a7ec82bc107bc2992e4340bad5b1460290025 Mon Sep 17 00:00:00 2001 From: Kun Liang Date: Mon, 6 Oct 2014 17:21:39 +0800 Subject: [PATCH 062/243] QuickBoot: Charger: support poweroff charging under QuickBoot mode Add mode support in healthd charger options to support poweroff charging under QuickBoot mode. Change-Id: I0f7b83baecb8ee68d7a9a83259a0f4a0d10848bf --- healthd/healthd.cpp | 20 ++++++++++++++++++++ healthd/healthd.h | 5 +++++ healthd/healthd_mode_charger.cpp | 12 +++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/healthd/healthd.cpp b/healthd/healthd.cpp index 6f0c4b7d..dcb95c88 100644 --- a/healthd/healthd.cpp +++ b/healthd/healthd.cpp @@ -32,6 +32,7 @@ #include #include #include +#include using namespace android; @@ -90,6 +91,13 @@ extern void healthd_mode_charger_heartbeat(void); extern void healthd_mode_charger_battery_update( struct android::BatteryProperties *props); +static const struct option OPTIONS[] = { + { "mode", required_argument, NULL, 'm' }, + { NULL, 0, NULL, 0 }, +}; + +int mode = NORMAL; + // NOPs for modes that need no special action static void healthd_mode_nop_init(struct healthd_config *config); @@ -332,6 +340,18 @@ int main(int argc, char **argv) { if (!strcmp(basename(argv[0]), "charger")) { healthd_mode_ops = &charger_ops; + int arg; + while ((arg=getopt_long(argc, argv,"m:" , OPTIONS, NULL))!=-1) { + switch (arg) { + case 'm': + mode = atoi(optarg); + break; + case '?': + default: + KLOG_ERROR(LOG_TAG, "Unrecognized charger option\n"); + continue; + } + } } else { while ((ch = getopt(argc, argv, "cr")) != -1) { switch (ch) { diff --git a/healthd/healthd.h b/healthd/healthd.h index 972e728d..0477d9f9 100644 --- a/healthd/healthd.h +++ b/healthd/healthd.h @@ -86,6 +86,11 @@ struct healthd_mode_ops { extern struct healthd_mode_ops *healthd_mode_ops; +enum MODE { + NORMAL = 0, + QUICKBOOT, +}; + // Charger mode void healthd_mode_charger_init(struct healthd_config *config); diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index d8a364fd..247fd260 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -87,6 +87,8 @@ char *locale; #define LOGI(x...) do { KLOG_INFO("charger", x); } while (0) #define LOGV(x...) do { KLOG_DEBUG("charger", x); } while (0) +extern int mode; + struct key_state { bool pending; bool down; @@ -609,8 +611,8 @@ static void update_screen_state(struct charger *charger, int64_t now) /* unblank the screen on first cycle */ if (batt_anim->cur_cycle == 0) { - set_backlight_on(); gr_fb_blank(false); + set_backlight_on(); } /* draw the new frame (@ cur_frame) */ @@ -780,6 +782,14 @@ static void handle_power_supply_state(struct charger *charger, int64_t now) if (!charger->charger_connected) { request_suspend(false); if (charger->next_pwr_check == -1) { + if (mode == QUICKBOOT) { + gr_fb_blank(true); + request_suspend(true); + /* exit here. There is no need to keep running when charger + * unplugged under QuickBoot mode + */ + exit(0); + } charger->next_pwr_check = now + UNPLUGGED_SHUTDOWN_TIME; LOGI("[%" PRId64 "] device unplugged: shutting down in %" PRId64 " (@ %" PRId64 ")\n", now, (int64_t)UNPLUGGED_SHUTDOWN_TIME, charger->next_pwr_check); From c905821017d3400a96ce38e70e81ebb389df35e8 Mon Sep 17 00:00:00 2001 From: David Ng Date: Mon, 2 Jun 2014 18:06:25 -0700 Subject: [PATCH 063/243] libusbhost: Skip /dev inotify if /dev/bus/usb already exists Skip watching /dev changes if the final /dev/bus/usb already exists. Register only for /dev/bus in this scenario on systems where the last "/usb" path may be deleted (currently handled by libusbhost). Removal of inotify watch on /dev reduces runtime overhead as /dev nodes are modified frequently. Change-Id: I6823a68c3977ae01832808ae5f8c32fa913b02cf --- libusbhost/usbhost.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/libusbhost/usbhost.c b/libusbhost/usbhost.c index 684f4013..f625198d 100644 --- a/libusbhost/usbhost.c +++ b/libusbhost/usbhost.c @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -189,6 +190,7 @@ int usb_host_load(struct usb_host_context *context, { int done = 0; int i; + struct stat usbfsdir; context->cb_added = added_cb; context->cb_removed = removed_cb; @@ -197,17 +199,23 @@ int usb_host_load(struct usb_host_context *context, D("Created device discovery thread\n"); /* watch for files added and deleted within USB_FS_DIR */ + context->wdd = -1; context->wddbus = -1; for (i = 0; i < MAX_USBFS_WD_COUNT; i++) context->wds[i] = -1; - /* watch the root for new subdirectories */ - context->wdd = inotify_add_watch(context->fd, DEV_DIR, IN_CREATE | IN_DELETE); - if (context->wdd < 0) { - fprintf(stderr, "inotify_add_watch failed\n"); - if (discovery_done_cb) - discovery_done_cb(client_data); - return done; + /* watch the root for new subdirectories; skip if final USB_FS_DIR + path already exist + */ + if (stat(USB_FS_DIR, &usbfsdir) == -1) { + context->wdd = inotify_add_watch(context->fd, DEV_DIR, IN_CREATE | IN_DELETE); + if (context->wdd < 0) + goto failed; + } else { + /* Final USB_FS_DIR already exists; watch base bus dir in case of bus/usb removal */ + context->wddbus = inotify_add_watch(context->fd, DEV_BUS_DIR, IN_CREATE | IN_DELETE); + if (context->wddbus < 0) + goto failed; } watch_existing_subdirs(context, context->wds, MAX_USBFS_WD_COUNT); @@ -218,6 +226,12 @@ int usb_host_load(struct usb_host_context *context, done |= discovery_done_cb(client_data); return done; + +failed: + fprintf(stderr, "inotify_add_watch failed\n"); + if (discovery_done_cb) + discovery_done_cb(client_data); + return done; } /* usb_host_load() */ int usb_host_read_event(struct usb_host_context *context) From aa77236464627f6781b26368abfe7bda70eba26f Mon Sep 17 00:00:00 2001 From: Sudhir Sharma Date: Fri, 31 Oct 2014 18:23:30 -0700 Subject: [PATCH 064/243] system/core: Remove AID_GRAPHICS from adb groups . Remove AID_GRAPHICS from adb access groups so that framebuffer access is restricted. Change-Id: I9ff4318b55555bd9370192707d1344423b14c976 --- adb/adb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adb/adb.c b/adb/adb.c index 10a1e0da..4300754b 100644 --- a/adb/adb.c +++ b/adb/adb.c @@ -1349,13 +1349,12 @@ int adb_main(int is_daemon, int server_port) ** AID_LOG to read system logs (adb logcat) ** AID_INPUT to diagnose input issues (getevent) ** AID_INET to diagnose network issues (netcfg, ping) - ** AID_GRAPHICS to access the frame buffer ** AID_NET_BT and AID_NET_BT_ADMIN to diagnose bluetooth (hcidump) ** AID_SDCARD_R to allow reading from the SD card ** AID_SDCARD_RW to allow writing to the SD card ** AID_NET_BW_STATS to read out qtaguid statistics */ - gid_t groups[] = { AID_ADB, AID_LOG, AID_INPUT, AID_INET, AID_GRAPHICS, + gid_t groups[] = { AID_ADB, AID_LOG, AID_INPUT, AID_INET, AID_NET_BT, AID_NET_BT_ADMIN, AID_SDCARD_R, AID_SDCARD_RW, AID_NET_BW_STATS }; if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) { From 425d3e3a470cb1370bdcbe81ba303df012744c18 Mon Sep 17 00:00:00 2001 From: Hamad Kadmany Date: Thu, 31 Oct 2013 11:58:37 +0200 Subject: [PATCH 065/243] system: core: Add uevent support for dvb devices Broadcast applications expects dvb devices to exist in specific location. Change-Id: I521f2957147428b7812ca1fb8fb6c49f44cdb8d1 --- init/devices.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/init/devices.c b/init/devices.c index faefae3c..91a0dd73 100644 --- a/init/devices.c +++ b/init/devices.c @@ -819,6 +819,27 @@ static void handle_generic_device_event(struct uevent *uevent) base = "/dev/log/"; make_dir(base, 0755); name += 4; + } else if (!strncmp(uevent->subsystem, "dvb", 3)) { + /* This imitates the file system that would be created + * if we were using devfs instead to preserve backward compatibility + * for users of dvb devices + */ + int adapter_id; + char dev_name[20] = {0}; + + sscanf(name, "dvb%d.%s", &adapter_id, dev_name); + + /* build dvb directory */ + base = "/dev/dvb"; + mkdir(base, 0755); + + /* build adapter directory */ + snprintf(devpath, sizeof(devpath), "/dev/dvb/adapter%d", adapter_id); + mkdir(devpath, 0755); + + /* build actual device directory */ + snprintf(devpath, sizeof(devpath), "/dev/dvb/adapter%d/%s", + adapter_id, dev_name); } else base = "/dev/"; links = get_character_device_symlinks(uevent); From abbd437bfd65d0511cf7d19998e07d93850c565f Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sun, 9 Nov 2014 11:33:03 -0800 Subject: [PATCH 066/243] camera: Add ifdefs for extended face detection fields Change-Id: Iab51c3f269a83e626cfa613ffc73d4fbac62deaa --- include/system/camera.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/system/camera.h b/include/system/camera.h index 0ed69262..5f2a9efb 100644 --- a/include/system/camera.h +++ b/include/system/camera.h @@ -278,6 +278,7 @@ typedef struct camera_face { * -2000, -2000 if this is not supported. */ int32_t mouth[2]; +#ifdef QCOM_BSP int32_t smile_degree; int32_t smile_score; int32_t blink_detected; @@ -290,6 +291,7 @@ typedef struct camera_face { int32_t top_bottom_gaze; int32_t leye_blink; int32_t reye_blink; +#endif } camera_face_t; From bc64c79cb80c2dace3d7abbb70d69b1a5bd5c635 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sun, 9 Nov 2014 12:00:11 -0800 Subject: [PATCH 067/243] core: Add QCOM_LEGACY_UIDS ifdef * qcom_oncrpc user is deprecated. We should align with upstream. * Define this if you still need the legacy behavior. * Also remove extra definition of qcom_diag Change-Id: I802434899b99b652ed1c1111c983edae052250da --- include/private/android_filesystem_config.h | 3 ++- rootdir/init.rc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index e5782ef4..e61e66ec 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -160,8 +160,9 @@ static const struct android_id_info android_ids[] = { { "sdcard_r", AID_SDCARD_R, }, { "clat", AID_CLAT, }, { "loop_radio", AID_LOOP_RADIO, }, +#if defined(QCOM_LEGACY_UIDS) { "qcom_oncrpc", AID_QCOM_ONCRPC, }, - { "qcom_diag", AID_QCOM_DIAG, }, +#endif { "mediadrm", AID_MEDIA_DRM, }, { "package_info", AID_PACKAGE_INFO, }, { "sdcard_pics", AID_SDCARD_PICS, }, diff --git a/rootdir/init.rc b/rootdir/init.rc index 5c49f438..a772e9af 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -558,7 +558,7 @@ service ril-daemon /system/bin/rild socket rild stream 660 root radio socket rild-debug stream 660 radio system user root - group radio cache inet misc audio sdcard_rw qcom_oncrpc qcom_diag log + group radio cache inet misc audio sdcard_rw qcom_diag log service surfaceflinger /system/bin/surfaceflinger class core From b6131b0aa078685c9840a96b9bfab4ca29a72e65 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sun, 9 Nov 2014 12:17:23 -0800 Subject: [PATCH 068/243] audio: Add ifdefs for QCOM audio features Change-Id: I5380d12539bead947a79683335aca1ed0d0408ed --- include/system/audio.h | 46 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/include/system/audio.h b/include/system/audio.h index 891ecc0c..f45d67eb 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -65,8 +65,9 @@ typedef enum { */ AUDIO_STREAM_DTMF = 8, AUDIO_STREAM_TTS = 9, +#ifdef QCOM_HARDWARE AUDIO_STREAM_INCALL_MUSIC = 10, - +#endif AUDIO_STREAM_CNT, AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1, } audio_stream_type_t; @@ -141,8 +142,10 @@ typedef enum { /* An example of remote presentation is Wifi Display */ /* where a dongle attached to a TV can be used to */ /* play the mix captured by this audio source. */ +#ifdef QCOM_HARDWARE AUDIO_SOURCE_FM_RX = 10, AUDIO_SOURCE_FM_RX_A2DP = 11, +#endif AUDIO_SOURCE_CNT, AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1, AUDIO_SOURCE_HOTWORD = 1999, /* A low-priority, preemptible audio source for @@ -238,11 +241,13 @@ typedef enum { AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0, } audio_format_vorbis_sub_fmt_t; +#ifdef QCOM_HARDWARE /* DOLBY (AC3/EAC3) sub format field definition: specify dual-mono acmod... */ typedef enum { AUDIO_FORMAT_DOLBY_SUB_NONE = 0x0, AUDIO_FORMAT_DOLBY_SUB_DM = 0x1, /* Clips with the Dual Mono content*/ } audio_format_dolby_sub_fmt_t; +#endif /* Audio format consists of a main format field (upper 8 bits) and a sub format * field (lower 24 bits). @@ -268,6 +273,7 @@ typedef enum { AUDIO_FORMAT_AC3 = 0x09000000UL, AUDIO_FORMAT_E_AC3 = 0x0A000000UL, +#ifdef QCOM_HARDWARE AUDIO_FORMAT_EVRC = 0x10000000UL, AUDIO_FORMAT_QCELP = 0x11000000UL, AUDIO_FORMAT_DTS = 0x12000000UL, @@ -280,6 +286,7 @@ typedef enum { AUDIO_FORMAT_AMR_WB_PLUS = 0x19000000UL, AUDIO_FORMAT_MP2 = 0x1A000000UL, AUDIO_FORMAT_EVRCNW = 0x1B000000UL, +#endif AUDIO_FORMAT_PCM_OFFLOAD = 0x1C000000UL, AUDIO_FORMAT_FLAC = 0x1D000000UL, AUDIO_FORMAT_E_AC3_JOC = 0x1E000000UL, @@ -299,10 +306,12 @@ typedef enum { AUDIO_FORMAT_PCM_SUB_8_24_BIT), AUDIO_FORMAT_PCM_FLOAT = (AUDIO_FORMAT_PCM | AUDIO_FORMAT_PCM_SUB_FLOAT), +#ifdef QCOM_HARDWARE AUDIO_FORMAT_AC3_DM = (AUDIO_FORMAT_AC3 | AUDIO_FORMAT_DOLBY_SUB_DM), AUDIO_FORMAT_E_AC3_DM = (AUDIO_FORMAT_E_AC3 | AUDIO_FORMAT_DOLBY_SUB_DM), +#endif AUDIO_FORMAT_PCM_24_BIT_PACKED = (AUDIO_FORMAT_PCM | AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED), AUDIO_FORMAT_AAC_MAIN = (AUDIO_FORMAT_AAC | @@ -330,7 +339,6 @@ typedef enum { AUDIO_FORMAT_PCM_SUB_16_BIT), AUDIO_FORMAT_PCM_24_BIT_OFFLOAD = (AUDIO_FORMAT_PCM_OFFLOAD | AUDIO_FORMAT_PCM_SUB_8_24_BIT), - } audio_format_t; /* For the channel mask for position assignment representation */ @@ -371,9 +379,11 @@ enum { AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT, AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT | AUDIO_CHANNEL_OUT_FRONT_RIGHT), +#ifdef QCOM_HARDWARE AUDIO_CHANNEL_OUT_2POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | AUDIO_CHANNEL_OUT_FRONT_RIGHT | AUDIO_CHANNEL_OUT_FRONT_CENTER), +#endif AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT | AUDIO_CHANNEL_OUT_FRONT_RIGHT | AUDIO_CHANNEL_OUT_BACK_LEFT | @@ -384,12 +394,14 @@ enum { AUDIO_CHANNEL_OUT_FRONT_RIGHT | AUDIO_CHANNEL_OUT_SIDE_LEFT | AUDIO_CHANNEL_OUT_SIDE_RIGHT), +#ifdef QCOM_HARDWARE AUDIO_CHANNEL_OUT_SURROUND = (AUDIO_CHANNEL_OUT_FRONT_LEFT | AUDIO_CHANNEL_OUT_FRONT_RIGHT | AUDIO_CHANNEL_OUT_FRONT_CENTER | AUDIO_CHANNEL_OUT_BACK_CENTER), AUDIO_CHANNEL_OUT_PENTA = (AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER), +#endif AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | AUDIO_CHANNEL_OUT_FRONT_RIGHT | AUDIO_CHANNEL_OUT_FRONT_CENTER | @@ -404,6 +416,7 @@ enum { AUDIO_CHANNEL_OUT_LOW_FREQUENCY | AUDIO_CHANNEL_OUT_SIDE_LEFT | AUDIO_CHANNEL_OUT_SIDE_RIGHT), +#ifdef QCOM_HARDWARE AUDIO_CHANNEL_OUT_6POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | AUDIO_CHANNEL_OUT_FRONT_RIGHT | AUDIO_CHANNEL_OUT_FRONT_CENTER | @@ -411,6 +424,7 @@ enum { AUDIO_CHANNEL_OUT_BACK_LEFT | AUDIO_CHANNEL_OUT_BACK_RIGHT | AUDIO_CHANNEL_OUT_BACK_CENTER), +#endif // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1 AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | AUDIO_CHANNEL_OUT_FRONT_RIGHT | @@ -462,6 +476,7 @@ enum { AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT, AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT), AUDIO_CHANNEL_IN_FRONT_BACK = (AUDIO_CHANNEL_IN_FRONT | AUDIO_CHANNEL_IN_BACK), +#ifdef QCOM_HARDWARE AUDIO_CHANNEL_IN_5POINT1 = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT | AUDIO_CHANNEL_IN_FRONT | @@ -471,6 +486,7 @@ enum { AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO = (AUDIO_CHANNEL_IN_VOICE_UPLINK | AUDIO_CHANNEL_IN_MONO), AUDIO_CHANNEL_IN_VOICE_DNLINK_MONO = (AUDIO_CHANNEL_IN_VOICE_DNLINK | AUDIO_CHANNEL_IN_MONO), AUDIO_CHANNEL_IN_VOICE_CALL_MONO = (AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO | AUDIO_CHANNEL_IN_VOICE_DNLINK_MONO), +#endif AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT | AUDIO_CHANNEL_IN_FRONT | @@ -655,8 +671,10 @@ enum { AUDIO_DEVICE_OUT_AUX_LINE = 0x200000, /* limited-output speaker device for acoustic safety */ AUDIO_DEVICE_OUT_SPEAKER_SAFE = 0x400000, +#ifdef QCOM_HARDWARE AUDIO_DEVICE_OUT_FM_TX = 0x1000000, AUDIO_DEVICE_OUT_PROXY = 0x2000000, +#endif AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT, AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE | AUDIO_DEVICE_OUT_SPEAKER | @@ -681,8 +699,10 @@ enum { AUDIO_DEVICE_OUT_FM | AUDIO_DEVICE_OUT_AUX_LINE | AUDIO_DEVICE_OUT_SPEAKER_SAFE | +#ifdef QCOM_HARDWARE AUDIO_DEVICE_OUT_FM_TX | AUDIO_DEVICE_OUT_PROXY | +#endif AUDIO_DEVICE_OUT_DEFAULT), AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | @@ -720,9 +740,11 @@ enum { AUDIO_DEVICE_IN_SPDIF = AUDIO_DEVICE_BIT_IN | 0x10000, AUDIO_DEVICE_IN_BLUETOOTH_A2DP = AUDIO_DEVICE_BIT_IN | 0x20000, AUDIO_DEVICE_IN_LOOPBACK = AUDIO_DEVICE_BIT_IN | 0x40000, +#ifdef QCOM_HARDWARE AUDIO_DEVICE_IN_PROXY = AUDIO_DEVICE_BIT_IN | 0x100000, AUDIO_DEVICE_IN_FM_RX = AUDIO_DEVICE_BIT_IN | 0x200000, AUDIO_DEVICE_IN_FM_RX_A2DP = AUDIO_DEVICE_BIT_IN | 0x400000, +#endif AUDIO_DEVICE_IN_DEFAULT = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT, AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION | @@ -744,9 +766,11 @@ enum { AUDIO_DEVICE_IN_SPDIF | AUDIO_DEVICE_IN_BLUETOOTH_A2DP | AUDIO_DEVICE_IN_LOOPBACK | +#ifdef QCOM_HARDWARE AUDIO_DEVICE_IN_FM_RX | AUDIO_DEVICE_IN_FM_RX_A2DP | AUDIO_DEVICE_IN_PROXY | +#endif AUDIO_DEVICE_IN_DEFAULT), AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, AUDIO_DEVICE_IN_ALL_USB = (AUDIO_DEVICE_IN_USB_ACCESSORY | @@ -780,12 +804,14 @@ typedef enum { // streams to hardware codec AUDIO_OUTPUT_FLAG_NON_BLOCKING = 0x20, // use non-blocking write AUDIO_OUTPUT_FLAG_HW_AV_SYNC = 0x40, // output uses a hardware A/V synchronization source +#ifdef QCOM_HARDWARE AUDIO_OUTPUT_FLAG_VOIP_RX = 0x1000, // use this flag in combination with DIRECT to // indicate HAL to activate EC & NS // path for VOIP calls AUDIO_OUTPUT_FLAG_INCALL_MUSIC = 0x2000, //use this flag for incall music delivery // flag for HDMI compressed passthrough AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH = 0x4000 +#endif } audio_output_flags_t; /* The audio input flags are analogous to audio output flags. @@ -1341,9 +1367,11 @@ static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t cha case 2: bits = AUDIO_CHANNEL_IN_STEREO; break; +#ifdef QCOM_HARDWARE case 6: bits = AUDIO_CHANNEL_IN_5POINT1; break; +#endif default: return AUDIO_CHANNEL_INVALID; } @@ -1396,6 +1424,7 @@ static inline bool audio_is_valid_format(audio_format_t format) case AUDIO_FORMAT_OPUS: case AUDIO_FORMAT_AC3: case AUDIO_FORMAT_E_AC3: +#ifdef QCOM_HARDWARE case AUDIO_FORMAT_QCELP: case AUDIO_FORMAT_EVRC: case AUDIO_FORMAT_EVRCB: @@ -1416,6 +1445,7 @@ static inline bool audio_is_valid_format(audio_format_t format) format != AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) { return false; } +#endif return true; default: return false; @@ -1429,20 +1459,25 @@ static inline bool audio_is_linear_pcm(audio_format_t format) static inline bool audio_is_offload_pcm(audio_format_t format) { +#ifdef QCOM_HARDWARE return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM_OFFLOAD); +#endif + return false; } static inline bool audio_is_compress_capture_format(audio_format_t format) { +#ifdef QCOM_HARDWARE if (format == AUDIO_FORMAT_AMR_WB) return true; else +#endif return false; } static inline bool audio_is_compress_voip_format(audio_format_t format) { - +#ifdef QCOM_HARDWARE if (format == AUDIO_FORMAT_AMR_NB || format == AUDIO_FORMAT_AMR_WB || format == AUDIO_FORMAT_EVRC || @@ -1451,6 +1486,7 @@ static inline bool audio_is_compress_voip_format(audio_format_t format) format == AUDIO_FORMAT_EVRCNW) return true; else +#endif return false; } @@ -1475,6 +1511,7 @@ static inline size_t audio_bytes_per_sample(audio_format_t format) case AUDIO_FORMAT_PCM_FLOAT: size = sizeof(float); break; +#ifdef QCOM_HARDWARE case AUDIO_FORMAT_AMR_NB: size = 32; break; @@ -1490,8 +1527,11 @@ static inline size_t audio_bytes_per_sample(audio_format_t format) case AUDIO_FORMAT_AMR_WB: size = 61; break; +#endif default: +#ifdef QCOM_HARDWARE size = sizeof(uint8_t); +#endif break; } return size; From 17417fff22477c9b699d16b4aaa1c49f441e0e31 Mon Sep 17 00:00:00 2001 From: Richard Ross Date: Thu, 4 Oct 2012 16:00:23 -0700 Subject: [PATCH 069/243] Add HTC Logging functions to support newer HTC props. * ifdef'd with HTCLOG. Change-Id: I70d0a6878dddf0f41d96735febda82c93496d8ec --- liblog/logd_write.c | 17 +++++++++++++++++ liblog/logd_write_kern.c | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/liblog/logd_write.c b/liblog/logd_write.c index b2668ced..f5defa58 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -83,6 +83,23 @@ int __android_log_dev_available(void) return (g_log_status == kLogAvailable); } +#ifdef HTCLOG +signed int __htclog_read_masks(char *buf __unused, signed int len __unused) +{ + return 0; +} + +int __htclog_init_mask(const char *a1 __unused, unsigned int a2 __unused, int a3 __unused) +{ + return 0; +} + +int __htclog_print_private(int a1 __unused, const char *a2 __unused, const char *fmt __unused, ...) +{ + return 0; +} +#endif + #if !FAKE_LOG_DEVICE /* give up, resources too limited */ static int __write_to_log_null(log_id_t log_fd __unused, struct iovec *vec __unused, diff --git a/liblog/logd_write_kern.c b/liblog/logd_write_kern.c index ae621cb1..37c3f0ce 100644 --- a/liblog/logd_write_kern.c +++ b/liblog/logd_write_kern.c @@ -87,6 +87,23 @@ int __android_log_dev_available(void) return (g_log_status == kLogAvailable); } +#ifdef HTCLOG +signed int __htclog_read_masks(char *buf __unused, signed int len __unused) +{ + return 0; +} + +int __htclog_init_mask(const char *a1 __unused, unsigned int a2 __unused, int a3 __unused) +{ + return 0; +} + +int __htclog_print_private(int a1 __unused, const char *a2 __unused, const char *fmt __unused, ...) +{ + return 0; +} +#endif + static int __write_to_log_null(log_id_t log_fd __unused, struct iovec *vec __unused, size_t nr __unused) { From 92df5cb3e7fa3a92ee24931bbeb64c3acc8644e1 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Wed, 12 Nov 2014 12:27:25 +0000 Subject: [PATCH 070/243] Revert "Init: Modify user/group option for bootanim" This reverts commit 65745d12fd0af9c0ffc7ef8c94bcdbc25788b9ce. This has a dependency on app-ops for validating access to sf that needs to be resolved. Remove until we work on PG --- rootdir/init.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootdir/init.rc b/rootdir/init.rc index a772e9af..fb1fb23e 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -593,7 +593,7 @@ service encrypt /system/bin/vdc --wait cryptfs enablecrypto inplace default service bootanim /system/bin/bootanimation class core - user media + user graphics group graphics audio disabled oneshot From 67d7a80c3d07c8bee577dec92d3cea658f34899c Mon Sep 17 00:00:00 2001 From: Emerson Pinter Date: Mon, 26 Nov 2012 21:48:12 -0200 Subject: [PATCH 071/243] liblog: add required function Some Motorola proprietaries require a function named __android_log_loggable. This change adds the function and solves problems with radio and other binaries on qualcomm based Motorola phones. This code is activated with TARGET_USES_MOTOROLA_LOG:=true Change-Id: I722b42d34198c027f265c3cf9f220d9798814915 --- liblog/Android.mk | 7 ++- liblog/logd_write.c | 95 ++++++++++++++++++++++++++++++++++++++++ liblog/logd_write_kern.c | 95 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 195 insertions(+), 2 deletions(-) diff --git a/liblog/Android.mk b/liblog/Android.mk index a4e5f5eb..bbcae54f 100644 --- a/liblog/Android.mk +++ b/liblog/Android.mk @@ -70,19 +70,22 @@ endif LOCAL_MULTILIB := both include $(BUILD_HOST_SHARED_LIBRARY) +ifeq ($(TARGET_USES_MOTOROLA_LOG),true) +LIBLOG_CFLAGS := -DMOTOROLA_LOG +endif # Shared and static library for target # ======================================================== include $(CLEAR_VARS) LOCAL_MODULE := liblog LOCAL_SRC_FILES := $(liblog_target_sources) -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := $(LIBLOG_CFLAGS) -Werror include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := liblog LOCAL_WHOLE_STATIC_LIBRARIES := liblog -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := $(LIBLOG_CFLAGS) -Werror include $(BUILD_SHARED_LIBRARY) include $(call first-makefiles-under,$(LOCAL_PATH)) diff --git a/liblog/logd_write.c b/liblog/logd_write.c index f5defa58..520106e8 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -35,6 +35,12 @@ #include #endif +#ifdef MOTOROLA_LOG +#if HAVE_LIBC_SYSTEM_PROPERTIES +#include +#endif +#endif + #include #include #include @@ -100,6 +106,95 @@ int __htclog_print_private(int a1 __unused, const char *a2 __unused, const char } #endif +#ifdef MOTOROLA_LOG +/* Fallback when there is neither log.tag. nor log.tag.DEFAULT. + * this is compile-time defaulted to "info". The log startup code + * looks at the build tags to see about whether it should be DEBUG... + * -- just as is done in frameworks/base/core/jni/android_util_Log.cpp + */ +static int prio_fallback = ANDROID_LOG_INFO; + +/* + * public interface so native code can see "should i log this" + * and behave similar to java Log.isLoggable() calls. + * + * NB: we have (level,tag) here to match the other __android_log entries. + * The Java side uses (tag,level) for its ordering. + * since the args are (int,char*) vs (char*,char*) we won't get strange + * swapped-the-strings errors. + */ + +#define LOGGING_PREFIX "log.tag." +#define LOGGING_DEFAULT "log.tag.DEFAULT" + +int __android_log_loggable(int prio, const char *tag) +{ + int nprio; + +#if HAVE_LIBC_SYSTEM_PROPERTIES + char keybuf[PROP_NAME_MAX]; + char results[PROP_VALUE_MAX]; + int n; + + /* we can NOT cache the log.tag. and log.tag.DEFAULT + * values because either one can be changed dynamically. + * + * damn, says the performance compulsive. + */ + + n = 0; + results[0] = '\0'; + if (tag) { + memcpy (keybuf, LOGGING_PREFIX, strlen (LOGGING_PREFIX) + 1); + /* watch out for buffer overflow */ + strncpy (keybuf + strlen (LOGGING_PREFIX), tag, + sizeof (keybuf) - strlen (LOGGING_PREFIX)); + keybuf[sizeof (keybuf) - 1] = '\0'; + n = __system_property_get (keybuf, results); + } + if (n == 0) { + /* nothing yet, look for the global */ + memcpy (keybuf, LOGGING_DEFAULT, sizeof (LOGGING_DEFAULT)); + n = __system_property_get (keybuf, results); + } + + if (n == 0) { + nprio = prio_fallback; + } else { + switch (results[0]) { + case 'E': + nprio = ANDROID_LOG_ERROR; + break; + case 'W': + nprio = ANDROID_LOG_WARN; + break; + case 'I': + nprio = ANDROID_LOG_INFO; + break; + case 'D': + nprio = ANDROID_LOG_DEBUG; + break; + case 'V': + nprio = ANDROID_LOG_VERBOSE; + break; + case 'S': + nprio = ANDROID_LOG_SILENT; + break; + default: + /* unspecified or invalid */ + nprio = prio_fallback; + break; + } + } +#else + /* no system property routines, fallback to a default */ + nprio = prio_fallback; +#endif + + return ((prio >= nprio) ? 1 : 0); +} +#endif + #if !FAKE_LOG_DEVICE /* give up, resources too limited */ static int __write_to_log_null(log_id_t log_fd __unused, struct iovec *vec __unused, diff --git a/liblog/logd_write_kern.c b/liblog/logd_write_kern.c index 37c3f0ce..34fcb1c7 100644 --- a/liblog/logd_write_kern.c +++ b/liblog/logd_write_kern.c @@ -32,6 +32,12 @@ #include #endif +#ifdef MOTOROLA_LOG +#if HAVE_LIBC_SYSTEM_PROPERTIES +#include +#endif +#endif + #include #include #include @@ -104,6 +110,95 @@ int __htclog_print_private(int a1 __unused, const char *a2 __unused, const char } #endif +#ifdef MOTOROLA_LOG +/* Fallback when there is neither log.tag. nor log.tag.DEFAULT. + * this is compile-time defaulted to "info". The log startup code + * looks at the build tags to see about whether it should be DEBUG... + * -- just as is done in frameworks/base/core/jni/android_util_Log.cpp + */ +static int prio_fallback = ANDROID_LOG_INFO; + +/* + * public interface so native code can see "should i log this" + * and behave similar to java Log.isLoggable() calls. + * + * NB: we have (level,tag) here to match the other __android_log entries. + * The Java side uses (tag,level) for its ordering. + * since the args are (int,char*) vs (char*,char*) we won't get strange + * swapped-the-strings errors. + */ + +#define LOGGING_PREFIX "log.tag." +#define LOGGING_DEFAULT "log.tag.DEFAULT" + +int __android_log_loggable(int prio, const char *tag) +{ + int nprio; + +#if HAVE_LIBC_SYSTEM_PROPERTIES + char keybuf[PROP_NAME_MAX]; + char results[PROP_VALUE_MAX]; + int n; + + /* we can NOT cache the log.tag. and log.tag.DEFAULT + * values because either one can be changed dynamically. + * + * damn, says the performance compulsive. + */ + + n = 0; + results[0] = '\0'; + if (tag) { + memcpy (keybuf, LOGGING_PREFIX, strlen (LOGGING_PREFIX) + 1); + /* watch out for buffer overflow */ + strncpy (keybuf + strlen (LOGGING_PREFIX), tag, + sizeof (keybuf) - strlen (LOGGING_PREFIX)); + keybuf[sizeof (keybuf) - 1] = '\0'; + n = __system_property_get (keybuf, results); + } + if (n == 0) { + /* nothing yet, look for the global */ + memcpy (keybuf, LOGGING_DEFAULT, sizeof (LOGGING_DEFAULT)); + n = __system_property_get (keybuf, results); + } + + if (n == 0) { + nprio = prio_fallback; + } else { + switch (results[0]) { + case 'E': + nprio = ANDROID_LOG_ERROR; + break; + case 'W': + nprio = ANDROID_LOG_WARN; + break; + case 'I': + nprio = ANDROID_LOG_INFO; + break; + case 'D': + nprio = ANDROID_LOG_DEBUG; + break; + case 'V': + nprio = ANDROID_LOG_VERBOSE; + break; + case 'S': + nprio = ANDROID_LOG_SILENT; + break; + default: + /* unspecified or invalid */ + nprio = prio_fallback; + break; + } + } +#else + /* no system property routines, fallback to a default */ + nprio = prio_fallback; +#endif + + return ((prio >= nprio) ? 1 : 0); +} +#endif + static int __write_to_log_null(log_id_t log_fd __unused, struct iovec *vec __unused, size_t nr __unused) { From 34c31143717ca4ca29d10f8767ef242d1a6643b9 Mon Sep 17 00:00:00 2001 From: David Ng Date: Wed, 4 Jan 2012 12:15:11 -0800 Subject: [PATCH 072/243] init: Add "export_rc" command to export env from a specified file New export_rc command to import environment variables from a specified file at the time the command is executed. Differences between "import" and "export_rc": 1) export_rc can only import environment vars 2) export_rc is performed when the command is executed rather than at the time the command is parsed (i.e. "import") Example: in /init.rc: on post-fs export_rc /system/etc/init.xyz.rc in /system/etc/init.xyz.rc: export LD_PRELOAD /system/lib/libxyz.so Change-Id: If616dea5b508c27e9f7a95b5e9db696ecea2fdee --- init/builtins.c | 19 +++++++++++++++ init/init_parser.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ init/keywords.h | 2 ++ 3 files changed, 81 insertions(+) diff --git a/init/builtins.c b/init/builtins.c index 3957a769..fb5882cc 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -51,6 +52,7 @@ int add_environment(const char *name, const char *value); extern int init_module(void *, unsigned long, const char *); +extern int init_export_rc_file(const char *); static int write_file(const char *path, const char *value) { @@ -234,6 +236,23 @@ int do_class_reset(int nargs, char **args) return 0; } +int do_export_rc(int nargs, char **args) +{ + /* Import environments from a specified file. + * The file content is of the form: + * export + * e.g. + * export LD_PRELOAD /system/lib/xyz.so + * export PROMPT abcde + * Differences between "import" and "export_rc": + * 1) export_rc can only import environment vars + * 2) export_rc is performed when the command + * is executed rather than at the time the + * command is parsed (i.e. "import") + */ + return init_export_rc_file(args[1]); +} + int do_domainname(int nargs, char **args) { return write_file("/proc/sys/kernel/domainname", args[1]); diff --git a/init/init_parser.c b/init/init_parser.c index 6466db21..bbdccf4c 100644 --- a/init/init_parser.c +++ b/init/init_parser.c @@ -48,6 +48,8 @@ static void parse_line_service(struct parse_state *state, int nargs, char **args static void *parse_action(struct parse_state *state, int nargs, char **args); static void parse_line_action(struct parse_state *state, int nargs, char **args); +void add_environment(const char *name, const char *value); + #define SECTION 0x01 #define COMMAND 0x02 #define OPTION 0x04 @@ -98,6 +100,7 @@ static int lookup_keyword(const char *s) if (!strcmp(s, "nable")) return K_enable; if (!strcmp(s, "xec")) return K_exec; if (!strcmp(s, "xport")) return K_export; + if (!strcmp(s, "xport_rc")) return K_export_rc; break; case 'g': if (!strcmp(s, "roup")) return K_group; @@ -412,6 +415,63 @@ int init_parse_config_file(const char *fn) return 0; } +typedef enum { + ENV_NOTREADY, + ENV_NAME, + ENV_VALUE, + ENV_WAITFORNEXTLINE, +} export_rc_state_t; + +int init_export_rc_file(const char *fn) +{ + char *data; + struct parse_state state; + char *env = NULL; + export_rc_state_t env_state = ENV_NOTREADY; + + data = read_file(fn, 0); + if (!data) return -1; + + state.filename = fn; + state.line = 0; + state.ptr = data; + state.nexttoken = 0; + state.parse_line = parse_line_no_op; + for (;;) { + switch (next_token(&state)) { + case T_EOF: + free(data); + return 0; + case T_NEWLINE: + env_state = ENV_NOTREADY; + break; + case T_TEXT: + switch (env_state) { + case ENV_NOTREADY: + if (strcmp(state.text, "export") == 0) { + env_state = ENV_NAME; + } else { + env_state = ENV_WAITFORNEXTLINE; + } + break; + case ENV_NAME: + env = state.text; + env_state = ENV_VALUE; + break; + case ENV_VALUE: + add_environment(env, state.text); + env_state = ENV_WAITFORNEXTLINE; + break; + default: + break; + } + break; + } + } + + return 0; +} + static int valid_name(const char *name) { if (strlen(name) > 16) { diff --git a/init/keywords.h b/init/keywords.h index 2d97e5b9..e9d6469d 100644 --- a/init/keywords.h +++ b/init/keywords.h @@ -9,6 +9,7 @@ int do_domainname(int nargs, char **args); int do_enable(int nargs, char **args); int do_exec(int nargs, char **args); int do_export(int nargs, char **args); +int do_export_rc(int nargs, char **args); int do_hostname(int nargs, char **args); int do_ifup(int nargs, char **args); int do_insmod(int nargs, char **args); @@ -60,6 +61,7 @@ enum { KEYWORD(enable, COMMAND, 1, do_enable) KEYWORD(exec, COMMAND, 1, do_exec) KEYWORD(export, COMMAND, 2, do_export) + KEYWORD(export_rc, COMMAND, 1, do_export_rc) KEYWORD(group, OPTION, 0, 0) KEYWORD(hostname, COMMAND, 1, do_hostname) KEYWORD(ifup, COMMAND, 1, do_ifup) From aee0850c1608ffea69580132279a4280899a0a0d Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Fri, 23 Aug 2013 21:12:12 -0700 Subject: [PATCH 073/243] sdcard: Allow building as a static library * Split main() out in order to allow linking with a multi-call executable such as recovery. Change-Id: I3325135e47e4dd5af3912f5ce67ec64007d54a63 --- sdcard/Android.mk | 11 ++++++++--- sdcard/main.c | 21 +++++++++++++++++++++ sdcard/sdcard.c | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 sdcard/main.c diff --git a/sdcard/Android.mk b/sdcard/Android.mk index 63b0f414..0ea83cc9 100644 --- a/sdcard/Android.mk +++ b/sdcard/Android.mk @@ -1,11 +1,16 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) - LOCAL_SRC_FILES := sdcard.c -LOCAL_MODULE := sdcard +LOCAL_MODULE := libsdcard LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror +LOCAL_MODULE_TAGS := optional +include $(BUILD_STATIC_LIBRARY) +include $(CLEAR_VARS) +LOCAL_SRC_FILES := main.c +LOCAL_MODULE := sdcard +LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror +LOCAL_STATIC_LIBRARIES := libsdcard LOCAL_SHARED_LIBRARIES := libc libcutils - include $(BUILD_EXECUTABLE) diff --git a/sdcard/main.c b/sdcard/main.c new file mode 100644 index 00000000..ad2405bd --- /dev/null +++ b/sdcard/main.c @@ -0,0 +1,21 @@ +/* + * 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. + */ + +extern int sdcard_main(int argc, char **argv); + +int main(int argc, char **argv) { + return sdcard_main(argc, argv); +} diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c index 7bf63943..54d31f05 100644 --- a/sdcard/sdcard.c +++ b/sdcard/sdcard.c @@ -1844,7 +1844,7 @@ static int run(const char* source_path, const char* dest_path, uid_t uid, return res; } -int main(int argc, char **argv) +int sdcard_main(int argc, char **argv) { int res; const char *source_path = NULL; From b78534f1efdd2587041dadc045fbbdade456a442 Mon Sep 17 00:00:00 2001 From: "Koushik K. Dutta" Date: Mon, 22 Feb 2010 23:22:36 -0800 Subject: [PATCH 074/243] fix up adb to prefer /sbin/sh if it exists Change-Id: I5c15731c95d123488e90aaeac5b497f556b53363 --- adb/services.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/adb/services.c b/adb/services.c index 57182da0..588690d9 100644 --- a/adb/services.c +++ b/adb/services.c @@ -314,8 +314,10 @@ static int create_subproc_raw(const char *cmd, const char *arg0, const char *arg #if ADB_HOST #define SHELL_COMMAND "/bin/sh" +#define ALTERNATE_SHELL_COMMAND "" #else #define SHELL_COMMAND "/system/bin/sh" +#define ALTERNATE_SHELL_COMMAND "/sbin/sh" #endif #if !ADB_HOST @@ -357,6 +359,9 @@ static int create_subproc_thread(const char *name, const subproc_mode mode) int ret_fd; pid_t pid = -1; + const char* shell_command; + struct stat st; + const char *arg0, *arg1; if (name == 0 || *name == 0) { arg0 = "-"; arg1 = 0; @@ -364,12 +369,19 @@ static int create_subproc_thread(const char *name, const subproc_mode mode) arg0 = "-c"; arg1 = name; } + if (stat(ALTERNATE_SHELL_COMMAND, &st) == 0) { + shell_command = ALTERNATE_SHELL_COMMAND; + } + else { + shell_command = SHELL_COMMAND; + } + switch (mode) { case SUBPROC_PTY: - ret_fd = create_subproc_pty(SHELL_COMMAND, arg0, arg1, &pid); + ret_fd = create_subproc_pty(shell_command, arg0, arg1, &pid); break; case SUBPROC_RAW: - ret_fd = create_subproc_raw(SHELL_COMMAND, arg0, arg1, &pid); + ret_fd = create_subproc_raw(shell_command, arg0, arg1, &pid); break; default: fprintf(stderr, "invalid subproc_mode %d\n", mode); From 4f8a6321b27a2335e14521f5bcba86a1afddb773 Mon Sep 17 00:00:00 2001 From: Shreyas Nagasandra Chandrasekhar Date: Wed, 29 Oct 2014 10:58:52 +0530 Subject: [PATCH 075/243] audio: Changes for LPA/Tunnel mode Intitial changes to enable LPA/Tunnel mode Change-Id: I099480931661c1190b53363d2ee6716a78b81ccb --- include/system/audio.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/system/audio.h b/include/system/audio.h index f45d67eb..876e0af9 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -810,7 +810,9 @@ typedef enum { // path for VOIP calls AUDIO_OUTPUT_FLAG_INCALL_MUSIC = 0x2000, //use this flag for incall music delivery // flag for HDMI compressed passthrough - AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH = 0x4000 + AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH = 0x4000, + AUDIO_OUTPUT_FLAG_LPA = 0x8000, + AUDIO_OUTPUT_FLAG_TUNNEL = 0x10000 #endif } audio_output_flags_t; From 3c129e9a1c1f1f24c1bdbd3dbdcd834570b0b0d2 Mon Sep 17 00:00:00 2001 From: Ramkumar Radhakrishnan Date: Wed, 7 Nov 2012 14:41:54 -0800 Subject: [PATCH 076/243] system/core: Add command NATIVE_WINDOW_SET_BUFFERS_SIZE Add native window command to set user defined buffer size. Change-Id: Id6d1f96daba81e8aba83479b5bda6ce0bfabb6e7 --- include/system/window.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/system/window.h b/include/system/window.h index bf93b79c..3d832a52 100644 --- a/include/system/window.h +++ b/include/system/window.h @@ -294,6 +294,7 @@ enum { NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* private */ NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM = 17,/* private */ NATIVE_WINDOW_SET_SIDEBAND_STREAM = 18, + NATIVE_WINDOW_SET_BUFFERS_SIZE = 19, /* private */ }; /* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */ From 348a6709e48dc505a6ed45a4ab335ddeb9adf2a5 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Sat, 1 Dec 2012 18:38:53 +0000 Subject: [PATCH 077/243] init: Bring back support for arbitrary chargermode cmdlines This was accidentally removed while debugging the init breakage fixed in change I8ef5c932efcd5e7f8d6f6fce0915683d84c3ee11. Put it back Change-Id: If35b9d5db281f8aab6de26f2bb63717d28b2db30 --- init/init.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/init/init.c b/init/init.c index 90a217ce..563b1ecb 100644 --- a/init/init.c +++ b/init/init.c @@ -67,11 +67,17 @@ static int property_triggers_enabled = 0; static int bootchart_count; #endif +#ifndef BOARD_CHARGING_CMDLINE_NAME +#define BOARD_CHARGING_CMDLINE_NAME "androidboot.battchg_pause" +#define BOARD_CHARGING_CMDLINE_VALUE "true" +#endif + static char console[32]; static char bootmode[32]; static char hardware[32]; static unsigned revision = 0; static char qemu[32]; +static char battchg_pause[32]; static struct action *cur_action = NULL; static struct command *cur_command = NULL; @@ -93,6 +99,8 @@ static time_t process_needs_restart; static const char *ENV[32]; +static unsigned charging_mode = 0; + /* add_environment - add "key=value" to the current environment */ int add_environment(const char *key, const char *val) { @@ -728,6 +736,8 @@ static void import_kernel_nv(char *name, int for_emulator) if (!strcmp(name,"qemu")) { strlcpy(qemu, value, sizeof(qemu)); + } else if (!strcmp(name,BOARD_CHARGING_CMDLINE_NAME)) { + strlcpy(battchg_pause, value, sizeof(battchg_pause)); } else if (!strncmp(name, "androidboot.", 12) && name_len > 12) { const char *boot_prop_name = name + 12; char prop[PROP_NAME_MAX]; @@ -1096,6 +1106,11 @@ int main(int argc, char **argv) queue_builtin_action(property_service_init_action, "property_service_init"); queue_builtin_action(signal_init_action, "signal_init"); + /* Older bootloaders use non-standard charging modes. Check for + * those now, after mounting the filesystems */ + if (strcmp(battchg_pause, BOARD_CHARGING_CMDLINE_VALUE) == 0) + is_charger = 1; + /* Don't mount filesystems or start core system services if in charger mode. */ if (is_charger) { action_for_each_trigger("charger", action_add_queue_tail); From ae5579561ae04b74752fe4bc7e4741578287e523 Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Sat, 17 Dec 2011 17:26:54 -0500 Subject: [PATCH 078/243] init: add detection of charging mode Based on Prashant Somashekar's patch which is in turn based on techomancer's patch http://goo.gl/I19GG. When BOARD_CHARGING_MODE_BOOTING_LPM is set, init will read that value (usually from /sys) and enable charging mode when set to 1. This differs from the original patch in that Samsung-specific lpm.rc is not loaded, but instead, init.rc is loaded using the "charger" class, which is how AOSP devices handle charging. The change is because the either the SELinux or the init.rc changes is causing lpm.rc to not work, and porting lpm.rc to the Android system is easier than trying to fix it. Change-Id: Ice7a074da7e982f9a64aaa97de28bfcbccdc8b91 --- init/Android.mk | 8 ++++++++ init/init.c | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/init/Android.mk b/init/Android.mk index 7e4527bd..d741a611 100755 --- a/init/Android.mk +++ b/init/Android.mk @@ -32,6 +32,14 @@ endif # Enable ueventd logging #LOCAL_CFLAGS += -DLOG_UEVENTS=1 +SYSTEM_CORE_INIT_DEFINES := BOARD_CHARGING_MODE_BOOTING_LPM + +$(foreach system_core_init_define,$(SYSTEM_CORE_INIT_DEFINES), \ + $(if $($(system_core_init_define)), \ + $(eval LOCAL_CFLAGS += -D$(system_core_init_define)=\"$($(system_core_init_define))\") \ + ) \ +) + LOCAL_MODULE:= init LOCAL_FORCE_STATIC_EXECUTABLE := true diff --git a/init/init.c b/init/init.c index 563b1ecb..163fba4d 100644 --- a/init/init.c +++ b/init/init.c @@ -1008,6 +1008,25 @@ static void selinux_initialize(void) security_setenforce(is_enforcing); } +static int charging_mode_booting(void) +{ +#ifndef BOARD_CHARGING_MODE_BOOTING_LPM + return 0; +#else + int f; + char cmb; + f = open(BOARD_CHARGING_MODE_BOOTING_LPM, O_RDONLY); + if (f < 0) + return 0; + + if (1 != read(f, (void *)&cmb,1)) + return 0; + + close(f); + return ('1' == cmb); +#endif +} + int main(int argc, char **argv) { int fd_count = 0; @@ -1081,7 +1100,7 @@ int main(int argc, char **argv) is_ffbm = !strncmp(bootmode, "ffbm", 4); if (!is_ffbm) - is_charger = !strcmp(bootmode, "charger"); + is_charger = !strcmp(bootmode, "charger") || charging_mode_booting(); INFO("property init\n"); property_load_boot_defaults(); From 8eb2ccd5b7aaa1b035e38962657c2fcd641c9613 Mon Sep 17 00:00:00 2001 From: "Christopher R. Palmer" Date: Mon, 22 Sep 2014 14:35:54 -0400 Subject: [PATCH 079/243] init: Fix memory corruption when sanitizing platform paths This commit fixes code that incorrectly increments s when it hits the terminator character of the string being sanitized. This means it will randomly start trashing memory beyond the end of the string being sanitized until it happens to hit two NULs (\0\0) which will break it out of the loop. Change-Id: I76553d7f183236a78a0bc7b408e92559b98f732f --- init/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init/util.c b/init/util.c index 0f69e1c5..e1a3ee33 100644 --- a/init/util.c +++ b/init/util.c @@ -329,9 +329,9 @@ void sanitize(char *s) if (!s) return; - for (; *s; s++) { + while (*s) { s += strspn(s, accept); - if (*s) *s = '_'; + if (*s) *s++ = '_'; } } From 4c2a894730ce1d5d618e20df873fd06968832c39 Mon Sep 17 00:00:00 2001 From: Brandon McAnsh Date: Thu, 13 Nov 2014 15:42:18 -0500 Subject: [PATCH 080/243] toolbox: Add setfattr Change-Id: I1981604f72d96c9ad38583f03f7f65df1ab865b7 Conflicts: toolbox/Android.mk Change-Id: I3e723c67436a374269767ec2e0594ca35af8d003 --- toolbox/Android.mk | 2 ++ toolbox/setfattr.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 toolbox/setfattr.c diff --git a/toolbox/Android.mk b/toolbox/Android.mk index d8d397e4..bba0445b 100644 --- a/toolbox/Android.mk +++ b/toolbox/Android.mk @@ -201,6 +201,8 @@ ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) OUR_TOOLS += r endif +OUR_TOOLS += setfattr + ALL_TOOLS = $(BSD_TOOLS) $(OUR_TOOLS) LOCAL_SRC_FILES := \ diff --git a/toolbox/setfattr.c b/toolbox/setfattr.c new file mode 100644 index 00000000..b71ede8c --- /dev/null +++ b/toolbox/setfattr.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +extern int setxattr(const char *, const char *, const void *, size_t, int); + +static int usage(const char *s) +{ + fprintf(stderr, "Usage: %s -n name -v value pathname\n", s); + fprintf(stderr, " -n name name of the extended attribute to set\n"); + fprintf(stderr, " -v value new value of the attribute\n"); + fprintf(stderr, " -h display this help and exit\n"); + + exit(10); +} + +int setfattr_main(int argc, char **argv) +{ + int i; + char *name = NULL; + char *valuestr = NULL; + unsigned long long value = 0; + size_t valuelen = 0; + + for (;;) { + int ret; + + ret = getopt(argc, argv, "hn:v:"); + + if (ret < 0) + break; + + switch(ret) { + case 'h': + usage(argv[0]); + break; + case 'n': + name = optarg; + break; + case 'v': + valuestr = optarg; + break; + } + } + + if (!name || !valuestr || optind == argc) + usage(argv[0]); + + /* + * We are being super lazy here, since setxattr can take an arbitrary + * amount of binary data. We assume that the value is numerical and + * not longer than 8 bytes. strtoull() detects the numeric base from + * the string prefix (0x for hexidecimal or 0 for octal). We also + * ignore endianness problems because it all works out fine on little + * endian. Hey, it's toolbox! + */ + value = strtoull(valuestr, NULL, 0); + while ((value >> (valuelen * 8))) + valuelen++; + + for (i = optind ; i < argc ; i++) + setxattr(argv[i], name, &value, valuelen, 0); + + return 0; +} From 4b1054fd3d49261789983366df2b2eb95483bca6 Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Tue, 18 Nov 2014 22:36:32 +0700 Subject: [PATCH 081/243] charger: allow home button to wake A squashed commit of the following: commit 6ce21d726a967b2cc942476758b9ab3851ff39f1 Author: Pawit Pornkitprasan Date: Sun Feb 3 22:21:32 2013 +0700 charger: do not suspend when handling home When using Google's suspend implementation, home press should also wake the device from suspend Change-Id: I51f3e45c5cb418b0b3718e7223a1336876379043 commit 75a7cf84df719d8cf5cd77093b3f9fee3c09017e Author: Pawit Pornkitprasan Date: Sat Jul 21 22:09:37 2012 +0700 charger: allow home button to wake On certain devices (e.g. galaxysmtd), the user expects the physical home button to be able to wake the device as well as the power button. Change-Id: If764f36aba3810dfa5233af8baf0a740b04889e0 Change-Id: I362b227e26bc864a2cad471df799bce2d682ecee --- healthd/healthd_mode_charger.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 247fd260..3a43883e 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -752,6 +752,11 @@ static void process_key(struct charger *charger, int code, int64_t now) } } } + } else { + if (key->pending) { + request_suspend(false); + kick_animation(charger->batt_anim); + } } key->pending = false; @@ -760,6 +765,7 @@ static void process_key(struct charger *charger, int code, int64_t now) static void handle_input_state(struct charger *charger, int64_t now) { process_key(charger, KEY_POWER, now); + process_key(charger, KEY_HOME, now); if (charger->next_key_check != -1 && now > charger->next_key_check) charger->next_key_check = -1; From a5d7fd2fc8cd01988fcef15f70b7a6cff2541fd6 Mon Sep 17 00:00:00 2001 From: ChampionSwimmer Date: Tue, 5 Mar 2013 00:36:05 +0530 Subject: [PATCH 082/243] mkbootimg: Support 32K 64K and 128K pagesizes Signed-off-by: ChampionSwimmer Signed-off-by: Michael Bestas Change-Id: I0ee608b74a1daefe536b9247f99368f3e043f93d --- mkbootimg/mkbootimg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mkbootimg/mkbootimg.c b/mkbootimg/mkbootimg.c index 658052cd..f46206f8 100644 --- a/mkbootimg/mkbootimg.c +++ b/mkbootimg/mkbootimg.c @@ -73,7 +73,7 @@ int usage(void) -static unsigned char padding[16384] = { 0, }; +static unsigned char padding[131072] = { 0, }; int write_padding(int fd, unsigned pagesize, unsigned itemsize) { @@ -157,7 +157,9 @@ int main(int argc, char **argv) } else if(!strcmp(arg,"--pagesize")) { pagesize = strtoul(val, 0, 10); if ((pagesize != 2048) && (pagesize != 4096) - && (pagesize != 8192) && (pagesize != 16384)) { + && (pagesize != 8192) && (pagesize != 16384) + && (pagesize != 32768) && (pagesize != 65536) + && (pagesize != 131072)) { fprintf(stderr,"error: unsupported page size %d\n", pagesize); return -1; } From 2f71277774908d4a34fac2349110d6c6e5373dfa Mon Sep 17 00:00:00 2001 From: Kun Liang Date: Fri, 31 Oct 2014 15:16:14 +0800 Subject: [PATCH 083/243] healthd: charger: only reboot under NORMAL mode If charger is not launched from normal poweroff charging, we don't want device to reboot. Just leave charger process to exit by itself but not reboot when not under NORMAL mode. Change-Id: I9f6535042d7016e21d172d167069a134c8851fa6 --- healthd/healthd_mode_charger.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 3a43883e..ce466bf0 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -1074,12 +1074,14 @@ void healthd_mode_charger_init(struct healthd_config* /*config*/) LOGI("--------------- STARTING CHARGER MODE ---------------\n"); - /* check the charging is enabled or not */ - ret = read_file_int(CHARGING_ENABLED_PATH, &charging_enabled); - if (!ret && !charging_enabled) { - /* if charging is disabled, reboot and exit power off charging */ - LOGI("android charging is disabled, exit!\n"); - android_reboot(ANDROID_RB_RESTART, 0, 0); + if (mode == NORMAL) { + /* check the charging is enabled or not */ + ret = read_file_int(CHARGING_ENABLED_PATH, &charging_enabled); + if (!ret && !charging_enabled) { + /* if charging is disabled, reboot and exit power off charging */ + LOGI("android charging is disabled, exit!\n"); + android_reboot(ANDROID_RB_RESTART, 0, 0); + } } ret = ev_init(input_callback, charger); From 46edf421c35228c9f804c2db670ffa65ac5bc414 Mon Sep 17 00:00:00 2001 From: Maya Erez Date: Mon, 4 Nov 2013 21:11:39 +0200 Subject: [PATCH 084/243] system: core: increase the polling time for remount_ro eMMC4.5 introduces an addition of cache on the device. We experienced long flush durations in some of the devices, and therefore the adb reboot resets the target before the flush completes. CRs-Fixed: 562350 Change-Id: I3f54901e12ffd232a7696dadfde1edec99ef91c6 --- libcutils/android_reboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcutils/android_reboot.c b/libcutils/android_reboot.c index 5d982958..d238fe99 100644 --- a/libcutils/android_reboot.c +++ b/libcutils/android_reboot.c @@ -95,7 +95,7 @@ static void remount_ro(void) /* Now poll /proc/mounts till it's done */ - while (!remount_ro_done() && (cnt < 50)) { + while (!remount_ro_done() && (cnt < 2400)) { usleep(100000); cnt++; } From 9b0c179ca31ea1485bfb2fdfd70353d2618f57ef Mon Sep 17 00:00:00 2001 From: Biswajit Paul Date: Mon, 3 Nov 2014 16:33:45 -0800 Subject: [PATCH 085/243] init: Do not call recursive_restorecon on soc.0 During coldboot calling restorecon_recursive on soc.0 causes boot time delays and failing the framework to bootup.Increase the coldboot timeout to accomodate recursive restorecon on "/sys/devices/" Change-Id: Ie364a3ca30db3a1344ea95def04f09660947a13f --- init/devices.c | 8 ++++++++ init/init.c | 2 +- init/init.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/init/devices.c b/init/devices.c index 91a0dd73..64262975 100644 --- a/init/devices.c +++ b/init/devices.c @@ -54,6 +54,7 @@ #define FIRMWARE_DIR1 "/etc/firmware" #define FIRMWARE_DIR2 "/vendor/firmware" #define FIRMWARE_DIR3 "/firmware/image" +#define DEVICES_BASE "/devices/soc.0" extern struct selabel_handle *sehandle; extern char bootdevice[32]; @@ -169,7 +170,14 @@ void fixup_sys_perms(const char *upath) } if (access(buf, F_OK) == 0) { INFO("restorecon_recursive: %s\n", buf); +#ifdef _PLATFORM_BASE + if(!strcmp(upath, DEVICES_BASE)) + restorecon(buf); + else + restorecon_recursive(buf); +#else restorecon_recursive(buf); +#endif } } diff --git a/init/init.c b/init/init.c index 163fba4d..7a68e628 100644 --- a/init/init.c +++ b/init/init.c @@ -586,7 +586,7 @@ static int wait_for_coldboot_done_action(int nargs, char **args) { int ret; INFO("wait for %s\n", coldboot_done); - ret = wait_for_file(coldboot_done, COMMAND_RETRY_TIMEOUT); + ret = wait_for_file(coldboot_done, COLDBOOT_RETRY_TIMEOUT); if (ret) ERROR("Timed out waiting for %s\n", coldboot_done); return ret; diff --git a/init/init.h b/init/init.h index a7615a36..1c275b79 100644 --- a/init/init.h +++ b/init/init.h @@ -84,6 +84,8 @@ struct svcenvinfo { #define COMMAND_RETRY_TIMEOUT 5 +#define COLDBOOT_RETRY_TIMEOUT 10 + struct service { /* list of all services */ struct listnode slist; From 56cab9c704b81d915e09b7ede6bcb27162450985 Mon Sep 17 00:00:00 2001 From: Matthew Qin Date: Wed, 22 Oct 2014 11:15:01 +0800 Subject: [PATCH 086/243] Revert "healthd: charger: Support alarm in power off charging mode" This reverts commit 0041eb9ba5643c99724fa92e79886deb5758c8e1. Change-Id: I6920564d072c13d9219a90816f4a21bc5f5b63fd --- healthd/healthd_mode_charger.cpp | 179 ------------------------------- 1 file changed, 179 deletions(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index ce466bf0..203e3eaf 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -40,10 +40,6 @@ #include #include -#include -#include -#include - #ifdef CHARGER_ENABLE_SUSPEND #include #endif @@ -213,17 +209,6 @@ static int char_width; static int char_height; static bool minui_inited; -enum alarm_time_type { - ALARM_TIME, - RTC_TIME, -}; - -/* - * shouldn't be changed after - * reading from alarm register - */ -static time_t alm_secs; - static int set_tricolor_led(int on, int color) { int fd, i; @@ -898,168 +883,6 @@ static void charger_event_handler(uint32_t /*epevents*/) ev_dispatch(); } -static int alarm_get_time(enum alarm_time_type time_type, - time_t *secs) -{ - struct tm tm; - unsigned int cmd; - int rc, fd = -1; - - if (!secs) - goto err; - - fd = open("/dev/rtc0", O_RDWR); - if (fd < 0) { - LOGE("Can't open rtc devfs node\n"); - goto err; - } - - switch (time_type) { - case ALARM_TIME: - cmd = RTC_ALM_READ; - break; - case RTC_TIME: - cmd = RTC_RD_TIME; - break; - default: - LOGE("Invalid time type\n"); - goto err; - } - - rc = ioctl(fd, cmd, &tm); - if (rc < 0) { - LOGE("Unable to get time\n"); - goto err; - } - - close(fd); - - *secs = mktime(&tm) + tm.tm_gmtoff; - if (*secs < 0) { - LOGE("Invalid seconds = %ld\n", *secs); - goto err; - } - - return 0; - -err: - if (fd >= 0) - close(fd); - return -1; -} - -#define ERR_SECS 2 -static int alarm_is_alm_expired() -{ - int rc; - time_t rtc_secs; - - rc = alarm_get_time(RTC_TIME, &rtc_secs); - if (rc < 0) - return 0; - - return (alm_secs >= rtc_secs - ERR_SECS && - alm_secs <= rtc_secs + ERR_SECS) ? 1 : 0; -} - -static int alarm_set_reboot_time_and_wait(time_t secs) -{ - int rc, fd; - struct timespec ts; - - fd = open("/dev/alarm", O_RDWR); - if (fd < 0) { - LOGE("Can't open alarm devfs node\n"); - goto err; - } - - /* get the elapsed realtime from boot time to now */ - rc = ioctl(fd, ANDROID_ALARM_GET_TIME( - ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP), &ts); - if (rc < 0) { - LOGE("Unable to get elapsed realtime\n"); - goto err; - } - - /* calculate the elapsed time from boot time to reboot time */ - ts.tv_sec += secs; - ts.tv_nsec = 0; - - rc = ioctl(fd, ANDROID_ALARM_SET( - ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP), &ts); - if (rc < 0) { - LOGE("Unable to set reboot time to %ld\n", secs); - goto err; - } - - do { - rc = ioctl(fd, ANDROID_ALARM_WAIT); - } while ((rc < 0 && errno == EINTR) || !alarm_is_alm_expired()); - - if (rc <= 0) { - LOGE("Unable to wait on alarm\n"); - goto err; - } - - close(fd); - return 0; - -err: - if (fd >= 0) - close(fd); - return -1; -} - -void *alarm_thread(void *) -{ - time_t rtc_secs, rb_secs; - int rc; - - /* - * to support power off alarm, the time - * stored in alarm register at latest - * shutdown time should be some time - * earlier than the actual alarm time - * set by user - */ - rc = alarm_get_time(ALARM_TIME, &alm_secs); - if (rc < 0 || !alm_secs) - goto err; - - rc = alarm_get_time(RTC_TIME, &rtc_secs); - if (rc < 0) - goto err; - - /* - * calculate the reboot time after which - * the phone will reboot - */ - rb_secs = alm_secs - rtc_secs; - if (rb_secs <= 0) - goto err; - - rc = alarm_set_reboot_time_and_wait(rb_secs); - if (rc < 0) - goto err; - - LOGI("Exit from power off charging, reboot the phone!\n"); - android_reboot(ANDROID_RB_RESTART2, 0, (char *)"rtc"); - -err: - LOGE("Exit from alarm thread\n"); - return NULL; -} - -void alarm_thread_create() -{ - pthread_t tid; - int rc; - - rc = pthread_create(&tid, NULL, alarm_thread, NULL); - if (rc < 0) - LOGE("Create alarm thread failed\n"); -} - void healthd_mode_charger_init(struct healthd_config* /*config*/) { int ret; @@ -1070,8 +893,6 @@ void healthd_mode_charger_init(struct healthd_config* /*config*/) dump_last_kmsg(); - alarm_thread_create(); - LOGI("--------------- STARTING CHARGER MODE ---------------\n"); if (mode == NORMAL) { From cf6da45149528abb8cc7589b94ff7291fe5293ec Mon Sep 17 00:00:00 2001 From: Matthew Qin Date: Fri, 17 Oct 2014 13:11:50 +0800 Subject: [PATCH 087/243] healthd: Support alarm in power off charging mode To implement this feature need to let the phone reboot some time earlier than the alarm time. Change-Id: I6505a99b51932ffa23518769f8fd4d2590021543 --- healthd/Android.mk | 2 +- healthd/healthd_board_default.cpp | 2 + healthd/healthd_msm.h | 20 +++ healthd/healthd_msm_alarm.cpp | 216 ++++++++++++++++++++++++++++++ 4 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 healthd/healthd_msm.h create mode 100644 healthd/healthd_msm_alarm.cpp diff --git a/healthd/Android.mk b/healthd/Android.mk index 1d238b1e..b8d844d1 100644 --- a/healthd/Android.mk +++ b/healthd/Android.mk @@ -5,7 +5,7 @@ ifneq ($(BUILD_TINY_ANDROID),true) LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES := healthd_board_default.cpp +LOCAL_SRC_FILES := healthd_board_default.cpp healthd_msm_alarm.cpp LOCAL_MODULE := libhealthd.default LOCAL_CFLAGS := -Werror include $(BUILD_STATIC_LIBRARY) diff --git a/healthd/healthd_board_default.cpp b/healthd/healthd_board_default.cpp index ed4ddb41..2084a700 100644 --- a/healthd/healthd_board_default.cpp +++ b/healthd/healthd_board_default.cpp @@ -15,10 +15,12 @@ */ #include +#include "healthd_msm.h" void healthd_board_init(struct healthd_config*) { // use defaults + power_off_alarm_init(); } diff --git a/healthd/healthd_msm.h b/healthd/healthd_msm.h new file mode 100644 index 00000000..6c46b207 --- /dev/null +++ b/healthd/healthd_msm.h @@ -0,0 +1,20 @@ +/* + * 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. + */ + +#ifndef _HEALTHD_MSM_H_ +#define _HEALTHD_MSM_H_ +void power_off_alarm_init(void); +#endif /* _HEALTHD_MSM_H_ */ diff --git a/healthd/healthd_msm_alarm.cpp b/healthd/healthd_msm_alarm.cpp new file mode 100644 index 00000000..cbe809aa --- /dev/null +++ b/healthd/healthd_msm_alarm.cpp @@ -0,0 +1,216 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "healthd_msm.h" + +#define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0) +#define LOGI(x...) do { KLOG_INFO("charger", x); } while (0) +#define LOGV(x...) do { KLOG_DEBUG("charger", x); } while (0) + +enum alarm_time_type { + ALARM_TIME, + RTC_TIME, +}; + +/* + * shouldn't be changed after + * reading from alarm register + */ +static time_t alm_secs; + +static int alarm_get_time(enum alarm_time_type time_type, + time_t *secs) +{ + struct tm tm; + unsigned int cmd; + int rc, fd = -1; + + if (!secs) + return -1; + + fd = open("/dev/rtc0", O_RDWR); + if (fd < 0) { + LOGE("Can't open rtc devfs node\n"); + return -1; + } + + switch (time_type) { + case ALARM_TIME: + cmd = RTC_ALM_READ; + break; + case RTC_TIME: + cmd = RTC_RD_TIME; + break; + default: + LOGE("Invalid time type\n"); + goto err; + } + + rc = ioctl(fd, cmd, &tm); + if (rc < 0) { + LOGE("Unable to get time\n"); + goto err; + } + + *secs = mktime(&tm) + tm.tm_gmtoff; + if (*secs < 0) { + LOGE("Invalid seconds = %ld\n", *secs); + goto err; + } + + close(fd); + return 0; + +err: + close(fd); + return -1; +} + +#define ERR_SECS 2 +static int alarm_is_alm_expired() +{ + int rc; + time_t rtc_secs; + + rc = alarm_get_time(RTC_TIME, &rtc_secs); + if (rc < 0) + return 0; + + return (alm_secs >= rtc_secs - ERR_SECS && + alm_secs <= rtc_secs + ERR_SECS) ? 1 : 0; +} + +static int alarm_set_reboot_time_and_wait(time_t secs) +{ + int rc, fd; + struct timespec ts; + + fd = open("/dev/alarm", O_RDWR); + if (fd < 0) { + LOGE("Can't open alarm devfs node\n"); + goto err; + } + + /* get the elapsed realtime from boot time to now */ + rc = ioctl(fd, ANDROID_ALARM_GET_TIME( + ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP), &ts); + if (rc < 0) { + LOGE("Unable to get elapsed realtime\n"); + goto err; + } + + /* calculate the elapsed time from boot time to reboot time */ + ts.tv_sec += secs; + ts.tv_nsec = 0; + + rc = ioctl(fd, ANDROID_ALARM_SET( + ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP), &ts); + if (rc < 0) { + LOGE("Unable to set reboot time to %ld\n", secs); + goto err; + } + + do { + rc = ioctl(fd, ANDROID_ALARM_WAIT); + } while ((rc < 0 && errno == EINTR) || !alarm_is_alm_expired()); + + if (rc <= 0) { + LOGE("Unable to wait on alarm\n"); + goto err; + } + + close(fd); + return 0; + +err: + if (fd >= 0) + close(fd); + return -1; +} + +static void *alarm_thread(void *) +{ + time_t rtc_secs, rb_secs; + int rc; + + /* + * to support power off alarm, the time + * stored in alarm register at latest + * shutdown time should be some time + * earlier than the actual alarm time + * set by user + */ + rc = alarm_get_time(ALARM_TIME, &alm_secs); + if (rc < 0 || !alm_secs) + goto err; + + rc = alarm_get_time(RTC_TIME, &rtc_secs); + if (rc < 0) + goto err; + + /* + * calculate the reboot time after which + * the phone will reboot + */ + rb_secs = alm_secs - rtc_secs; + if (rb_secs <= 0) + goto err; + + rc = alarm_set_reboot_time_and_wait(rb_secs); + if (rc < 0) + goto err; + + LOGI("Exit from power off charging, reboot the phone!\n"); + android_reboot(ANDROID_RB_RESTART2, 0, (char *)"rtc"); + +err: + LOGE("Exit from alarm thread\n"); + return NULL; +} + +void power_off_alarm_init(void) +{ + pthread_t tid; + int rc; + char value[PROP_VALUE_MAX]; + + property_get("ro.bootmode", value, ""); + if (!strcmp("charger", value)) { + rc = pthread_create(&tid, NULL, alarm_thread, NULL); + if (rc < 0) + LOGE("Create alarm thread failed\n"); + } +} From 4434134211753915f42becc08c1f73aa6d619e80 Mon Sep 17 00:00:00 2001 From: Peter Heatwole Date: Tue, 13 Aug 2013 13:55:24 -0700 Subject: [PATCH 088/243] adb/fastboot: Support SuperSpeed USB devices When enumerating USB 3.0 devices, a 6-byte SuperSpeed companion descriptor follows each standard descriptor. The ADB and Fastboot Linux clients currently fail to interpret these additional descriptors and simply bail. Fix this by skipping over them. Change-Id: I254dad8ed81e8de74a4fac36e8ce54b5da9715fe --- adb/usb_linux.c | 15 +++++++++++++++ fastboot/usb_linux.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/adb/usb_linux.c b/adb/usb_linux.c index f16bdd03..58de2cdf 100644 --- a/adb/usb_linux.c +++ b/adb/usb_linux.c @@ -237,6 +237,21 @@ static void find_usb_device(const char *base, // looks like ADB... ep1 = (struct usb_endpoint_descriptor *)bufptr; bufptr += USB_DT_ENDPOINT_SIZE; + + // USB3 devices are required to have superspeed + // companion descriptors. They aren't needed to + // locate the target so just skip them. + // + // When using the Android build environment, the old + // ch9.h header from the prebuilts directory for the + // host does not contain superspeed definitions. +#ifndef USB_DT_SS_EP_COMP_SIZE +#define USB_DT_SS_EP_COMP_SIZE 6 +#endif + if (device->bcdUSB >= 0x0300) { + bufptr += USB_DT_SS_EP_COMP_SIZE; + } + ep2 = (struct usb_endpoint_descriptor *)bufptr; bufptr += USB_DT_ENDPOINT_SIZE; diff --git a/fastboot/usb_linux.c b/fastboot/usb_linux.c index fabbd516..a52d3168 100644 --- a/fastboot/usb_linux.c +++ b/fastboot/usb_linux.c @@ -223,6 +223,21 @@ static int filter_usb_device(char* sysfs_name, } else { out = ept->bEndpointAddress; } + + // USB3 devices are required to have superspeed companion + // descriptors. They aren't needed to locate the target + // so just skip them. + // + // When using the Android build environment, the old ch9.h + // header from the prebuilts directory for the host does + // not contain superspeed-related definitions. +#ifndef USB_DT_SS_EP_COMP_SIZE +#define USB_DT_SS_EP_COMP_SIZE 6 +#endif + if (dev->bcdUSB >= 0x0300) { + len -= USB_DT_SS_EP_COMP_SIZE; + ptr += USB_DT_SS_EP_COMP_SIZE; + } } info.has_bulk_in = (in != -1); From 567c644b296be655acbb82f466651c9682a2a12e Mon Sep 17 00:00:00 2001 From: Sudhir Sharma Date: Fri, 31 Oct 2014 18:47:55 -0700 Subject: [PATCH 089/243] Make tombstones directory to not follow symlink. Use file descriptor to change ownership. Change-Id: I3e00ccb8496d8d91bae9b78ce5e38e4cabd4a3d6 --- debuggerd/tombstone.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/debuggerd/tombstone.cpp b/debuggerd/tombstone.cpp index a7e1524b..0bdf1bfd 100644 --- a/debuggerd/tombstone.cpp +++ b/debuggerd/tombstone.cpp @@ -742,16 +742,22 @@ char* engrave_tombstone(pid_t pid, pid_t tid, int signal, int original_si_code, log_t log; log.current_tid = tid; log.crashed_tid = tid; + int fd = -1; if ((mkdir(TOMBSTONE_DIR, 0755) == -1) && (errno != EEXIST)) { _LOG(&log, logtype::ERROR, "failed to create %s: %s\n", TOMBSTONE_DIR, strerror(errno)); } - - if (chown(TOMBSTONE_DIR, AID_SYSTEM, AID_SYSTEM) == -1) { - _LOG(&log, logtype::ERROR, "failed to change ownership of %s: %s\n", TOMBSTONE_DIR, strerror(errno)); + if(((fd = open(TOMBSTONE_DIR, O_NOFOLLOW|O_RDONLY)) != -1) ||((fd = open(TOMBSTONE_DIR, O_NOFOLLOW|O_WRONLY)) != -1)){ + if (fchown(fd, AID_SYSTEM, AID_SYSTEM) < 0){ + _LOG(&log, logtype::ERROR, "failed to change ownership of %s: %s\n", TOMBSTONE_DIR, strerror(errno)); + close(fd); + return NULL; + } + close(fd); + } else { + _LOG(&log, logtype::ERROR, "failed to open %s: %s\n", TOMBSTONE_DIR, strerror(errno)); + return NULL; } - - int fd = -1; char* path = NULL; if (selinux_android_restorecon(TOMBSTONE_DIR, 0) == 0) { path = find_and_open_tombstone(&fd); From b8bbec0ce89f3aba1f59ab732bf5bd27789c29fb Mon Sep 17 00:00:00 2001 From: Konstantin Dorfman Date: Thu, 5 Dec 2013 14:39:39 +0200 Subject: [PATCH 090/243] system: core: increase the polling time for remount_ro to 3600 eMMC4.5 introduces an addition of cache on the device. We experienced long flush durations in some of the devices, and therefore the adb reboot resets the target before the flush completes. Latest tests show that increasing it to 2400 wasn't enough thus it was increased to 3600. Change-Id: Ifbe7af16aa1861d0d57c808b0240361c0317d5c5 CRs-fixed: 581363 --- libcutils/android_reboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcutils/android_reboot.c b/libcutils/android_reboot.c index d238fe99..72bd18e5 100644 --- a/libcutils/android_reboot.c +++ b/libcutils/android_reboot.c @@ -95,7 +95,7 @@ static void remount_ro(void) /* Now poll /proc/mounts till it's done */ - while (!remount_ro_done() && (cnt < 2400)) { + while (!remount_ro_done() && (cnt < 3600)) { usleep(100000); cnt++; } From ca51248a210615f05a95ccb954ae48144787ffa5 Mon Sep 17 00:00:00 2001 From: Channagoud Kadabi Date: Wed, 5 Nov 2014 16:59:27 -0800 Subject: [PATCH 091/243] system: core: fastboot: Increase USB protocol buffer size to 1024 With USB3.0 SS support the max packet size supported by USB protocol is 1024 bytes. When connected to a USB device in SuperSpeed, if only 512 bytes are sent at a time the device would interpret each transfer as a short packet and slows down overall throughput. To accommodate for SuperSpeed USB bulk endpoints, increase the buffer size to 1024. Change-Id: I4f447fe38045bc0008e2d6dd3f36c2d6819d6c15 --- fastboot/fastboot_protocol.txt | 4 ++-- fastboot/protocol.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fastboot/fastboot_protocol.txt b/fastboot/fastboot_protocol.txt index 2248992d..37b19590 100644 --- a/fastboot/fastboot_protocol.txt +++ b/fastboot/fastboot_protocol.txt @@ -12,8 +12,8 @@ Basic Requirements ------------------ * Two bulk endpoints (in, out) are required -* Max packet size must be 64 bytes for full-speed and 512 bytes for - high-speed USB +* Max packet size must be 64 bytes for full-speed, 512 bytes for + high-speed and 1024 bytes for Super Speed USB. * The protocol is entirely host-driven and synchronous (unlike the multi-channel, bi-directional, asynchronous ADB protocol) diff --git a/fastboot/protocol.c b/fastboot/protocol.c index 84e9837b..10a84c12 100644 --- a/fastboot/protocol.c +++ b/fastboot/protocol.c @@ -216,7 +216,7 @@ int fb_download_data(usb_handle *usb, const void *data, unsigned size) } } -#define USB_BUF_SIZE 512 +#define USB_BUF_SIZE 1024 static char usb_buf[USB_BUF_SIZE]; static int usb_buf_len; From e31fea29665881a56e790a91c215e2dc5d124368 Mon Sep 17 00:00:00 2001 From: Abhijeet Dharmapurikar Date: Mon, 3 Nov 2014 12:34:24 -0800 Subject: [PATCH 092/243] healthd: Treat Wipower charging as a form of Wireless Charging Wipower charging is a form of Wireless charging where the power path is via induction and control path goes over BT. Change-Id: Ib2767d512394a0b4aef11a961a83872070a46cd8 --- healthd/BatteryMonitor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 4a6b7020..ccee10d5 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -135,6 +135,7 @@ BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String { "USB_CDP", ANDROID_POWER_SUPPLY_TYPE_AC }, { "USB_ACA", ANDROID_POWER_SUPPLY_TYPE_AC }, { "Wireless", ANDROID_POWER_SUPPLY_TYPE_WIRELESS }, + { "Wipower", ANDROID_POWER_SUPPLY_TYPE_WIRELESS }, { NULL, 0 }, }; From daf741c65b9a446982966bf48dd166089001dc79 Mon Sep 17 00:00:00 2001 From: Kui Wang Date: Thu, 15 May 2014 20:13:41 +0800 Subject: [PATCH 093/243] Add torch light access permission to torch app Add torch light access permission to torch app Change-Id: Icf3eb08d75481fb70229887b76a8cdb5d3516944 --- rootdir/init.rc | 1 + 1 file changed, 1 insertion(+) diff --git a/rootdir/init.rc b/rootdir/init.rc index fb1fb23e..afcdde31 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -400,6 +400,7 @@ on boot chown system system /sys/class/timed_output/vibrator/enable chown system system /sys/class/leds/keyboard-backlight/brightness chown system system /sys/class/leds/lcd-backlight/brightness + chown system system /sys/class/leds/torch-light/brightness chown system system /sys/class/leds/button-backlight/brightness chown system system /sys/class/leds/jogball-backlight/brightness chown system system /sys/class/leds/red/brightness From a5deda01b96b918f3d4b2f80d6cedd4a47346d5b Mon Sep 17 00:00:00 2001 From: Andrew Dodd Date: Mon, 18 Jun 2012 21:19:19 -0400 Subject: [PATCH 094/243] init: Check for symlinks with lstat() not open() Using open() with an O_NOFOLLOW flag will result in a file falsely being determined to be a symlink if the open fails for another reason. For example, a character device that isn't ready due to the underlying hardware not being initialized yet will fail to open() An example of this are any CG2900 device files prior to execution of ste-cg29xx_ctrl This uses lstat() instead of open() with O_NOFOLLOW to check whether a file is a symlink or not. Change-Id: Ie0d8d94b426c84c29b1b04d41a4cc15536cb307c --- init/builtins.c | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/init/builtins.c b/init/builtins.c index fb5882cc..10a810ee 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -77,61 +77,47 @@ static int write_file(const char *path, const char *value) } } -static int _open(const char *path) -{ - int fd; - - fd = open(path, O_RDONLY | O_NOFOLLOW); - if (fd < 0) - fd = open(path, O_WRONLY | O_NOFOLLOW); - - return fd; -} static int _chown(const char *path, unsigned int uid, unsigned int gid) { - int fd; int ret; - fd = _open(path); - if (fd < 0) { + struct stat p_statbuf; + + ret = lstat(path, &p_statbuf); + if (ret < 0) { return -1; } - ret = fchown(fd, uid, gid); - if (ret < 0) { - int errno_copy = errno; - close(fd); - errno = errno_copy; + if (S_ISLNK(p_statbuf.st_mode) == 1) { + errno = EINVAL; return -1; } - close(fd); + ret = chown(path, uid, gid); - return 0; + return ret; } static int _chmod(const char *path, mode_t mode) { - int fd; int ret; - fd = _open(path); - if (fd < 0) { + struct stat p_statbuf; + + ret = lstat(path, &p_statbuf); + if (ret < 0) { return -1; } - ret = fchmod(fd, mode); - if (ret < 0) { - int errno_copy = errno; - close(fd); - errno = errno_copy; + if (S_ISLNK(p_statbuf.st_mode) == 1) { + errno = EINVAL; return -1; } - close(fd); + ret = chmod(path, mode); - return 0; + return ret; } static int insmod(const char *filename, char *options) From 1c187bfbf7b709976db00b2ef072e80bfee19146 Mon Sep 17 00:00:00 2001 From: dhacker29 Date: Fri, 2 Nov 2012 11:43:02 -0500 Subject: [PATCH 095/243] Allow a device to define the max number of service groups in init.h Certain proprieatary binaries (such as tcmd for instance) require more than 12 supplementary service groups. By definiing: TARGET_NR_SVC_SUPP_GIDS := in BoardConfig this can now be changed per device. Change-Id: Iab853836a028147c051be21e39575635cb463dd1 Signed-off-by: dhacker29 --- init/Android.mk | 4 ++++ init/init.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/init/Android.mk b/init/Android.mk index d741a611..ebb18612 100755 --- a/init/Android.mk +++ b/init/Android.mk @@ -40,6 +40,10 @@ $(foreach system_core_init_define,$(SYSTEM_CORE_INIT_DEFINES), \ ) \ ) +ifneq ($(TARGET_NR_SVC_SUPP_GIDS),) +LOCAL_CFLAGS += -DNR_SVC_SUPP_GIDS=$(TARGET_NR_SVC_SUPP_GIDS) +endif + LOCAL_MODULE:= init LOCAL_FORCE_STATIC_EXECUTABLE := true diff --git a/init/init.h b/init/init.h index 1c275b79..48ac12f8 100644 --- a/init/init.h +++ b/init/init.h @@ -80,7 +80,9 @@ struct svcenvinfo { #define SVC_RESTART 0x100 /* Use to safely restart (stop, wait, start) a service */ #define SVC_DISABLED_START 0x200 /* a start was requested but it was disabled at the time */ +#ifndef NR_SVC_SUPP_GIDS #define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */ +#endif #define COMMAND_RETRY_TIMEOUT 5 From 99837f8e619bba22ffb7ad016dbd9b5d67a1ff89 Mon Sep 17 00:00:00 2001 From: Chirayu Desai Date: Sun, 25 Nov 2012 16:14:19 +0530 Subject: [PATCH 096/243] toolbox: new applet restart - stop + start - for the lazy. Change-Id: Ie0ef0e27f5b7819a5575ece6b82c5813f4e38420 --- toolbox/Android.mk | 1 + toolbox/restart.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 toolbox/restart.c diff --git a/toolbox/Android.mk b/toolbox/Android.mk index bba0445b..1f891fca 100644 --- a/toolbox/Android.mk +++ b/toolbox/Android.mk @@ -175,6 +175,7 @@ OUR_TOOLS := \ ps \ readlink \ renice \ + restart \ restorecon \ rmmod \ route \ diff --git a/toolbox/restart.c b/toolbox/restart.c new file mode 100644 index 00000000..9d803dea --- /dev/null +++ b/toolbox/restart.c @@ -0,0 +1,27 @@ +#include +#include +#include + +#include + +int restart_main(int argc, char *argv[]) +{ + char buf[1024]; + + if(argc > 1) { + property_set("ctl.stop", argv[1]); + property_set("ctl.start", argv[1]); + } else { + /* defaults to stopping and starting the common services */ + property_set("ctl.stop", "zygote_secondary"); + property_set("ctl.stop", "zygote"); + property_set("ctl.stop", "surfaceflinger"); + property_set("ctl.stop", "netd"); + property_set("ctl.start", "netd"); + property_set("ctl.start", "surfaceflinger"); + property_set("ctl.start", "zygote"); + property_set("ctl.start", "zygote_secondary"); + } + + return 0; +} From b89d1b2e41e685c15ab889d8a8eb15b1f42149b7 Mon Sep 17 00:00:00 2001 From: Ethan Chen Date: Thu, 29 Aug 2013 00:56:27 -0700 Subject: [PATCH 097/243] init: define BOARD_CHARGING_CMDLINE parameters Change-Id: I722e49e2a13418bf887c361c85e9d102168ca973 --- init/Android.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/init/Android.mk b/init/Android.mk index ebb18612..b336a2fa 100755 --- a/init/Android.mk +++ b/init/Android.mk @@ -32,7 +32,9 @@ endif # Enable ueventd logging #LOCAL_CFLAGS += -DLOG_UEVENTS=1 -SYSTEM_CORE_INIT_DEFINES := BOARD_CHARGING_MODE_BOOTING_LPM +SYSTEM_CORE_INIT_DEFINES := BOARD_CHARGING_MODE_BOOTING_LPM \ + BOARD_CHARGING_CMDLINE_NAME \ + BOARD_CHARGING_CMDLINE_VALUE $(foreach system_core_init_define,$(SYSTEM_CORE_INIT_DEFINES), \ $(if $($(system_core_init_define)), \ From 4e1b58d9cb26c75862b7993b8ef28cb09a738814 Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Mon, 24 Nov 2014 04:38:08 -0800 Subject: [PATCH 098/243] healthd: Use project pathmap for recovery Change-Id: Ifa71a7adfb3a3d897a6e24e7aa18388c364efb95 --- healthd/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/healthd/Android.mk b/healthd/Android.mk index b8d844d1..2e3270d3 100644 --- a/healthd/Android.mk +++ b/healthd/Android.mk @@ -35,7 +35,7 @@ ifeq ($(strip $(BOARD_CHARGER_ENABLE_SUSPEND)),true) LOCAL_CFLAGS += -DCHARGER_ENABLE_SUSPEND endif -LOCAL_C_INCLUDES := bootable/recovery +LOCAL_C_INCLUDES := $(call project-path-for,recovery) LOCAL_STATIC_LIBRARIES := libbatteryservice libbinder libminui libpng libz libutils libstdc++ libcutils liblog libm libc From c7038424b50b8a29d3be5878a2d211c7972f0ed8 Mon Sep 17 00:00:00 2001 From: myfluxi Date: Wed, 26 Nov 2014 11:51:18 -0800 Subject: [PATCH 099/243] Revert "healthd: charger: Modify charger unplug shutdown time to 1s" This fixes hammerhead off mode charging and shouldn't bother other devices. This reverts commit 2e8628e9685c62b2cf881ba9f5aef406713f0175. Change-Id: Ibe6477884d22e37981a3c5549a3a72aae1963152 --- healthd/healthd_mode_charger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 203e3eaf..9be16279 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -65,7 +65,7 @@ char *locale; #define BATTERY_UNKNOWN_TIME (2 * MSEC_PER_SEC) #define POWER_ON_KEY_TIME (2 * MSEC_PER_SEC) -#define UNPLUGGED_SHUTDOWN_TIME (1 * MSEC_PER_SEC) +#define UNPLUGGED_SHUTDOWN_TIME (10 * MSEC_PER_SEC) #define BATTERY_FULL_THRESH 95 #define SCREEN_ON_BATTERY_THRESH 0 From 6368b01f9e91fd1a11c3e32ad9aa9d75ba94d795 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Wed, 26 Nov 2014 21:49:52 +0000 Subject: [PATCH 100/243] Update permissions to the superuser binary Change-Id: Ia382c74854cfbe625653b8b6b016b37f93132658 --- include/private/android_filesystem_config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index e61e66ec..9f5e41e3 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -261,9 +261,10 @@ static const struct fs_path_config android_files[] = { * Do not change. */ { 02750, AID_ROOT, AID_INET, 0, "system/bin/netcfg" }, + /* CM's daemonized su doesn't need the setuid bit */ + { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/su" }, /* the following five files are INTENTIONALLY set-uid, but they * are NOT included on user builds. */ - { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" }, { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/librank" }, { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procrank" }, { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" }, From 5e67af223b34b5f9edb6d277e8fa68717f8baf58 Mon Sep 17 00:00:00 2001 From: Arne Coucheron Date: Tue, 25 Nov 2014 08:10:09 +0100 Subject: [PATCH 101/243] core: Fix compile error with QCOM_LEGACY_UIDS Change-Id: I01c7f73ba0e87533ae06b8af183b4c88dbbf944e --- include/private/android_filesystem_config.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index 9f5e41e3..21458c7e 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -184,11 +184,15 @@ static const struct android_id_info android_ids[] = { { "net_admin", AID_NET_ADMIN, }, { "net_bw_stats", AID_NET_BW_STATS, }, { "qcom_diag", AID_QCOM_DIAG, }, +#if !defined(QCOM_LEGACY_UIDS) { "ims", AID_IMS, }, +#endif { "net_bw_acct", AID_NET_BW_ACCT, }, { "net_bt_stack", AID_NET_BT_STACK, }, { "qcom_diag", AID_QCOM_DIAG, }, +#if !defined(QCOM_LEGACY_UIDS) { "sensors", AID_SENSORS, }, +#endif { "everybody", AID_EVERYBODY, }, { "misc", AID_MISC, }, { "nobody", AID_NOBODY, }, From c6fc6076d8105a8b82ecd5c7a032776d7edddde9 Mon Sep 17 00:00:00 2001 From: Shareef Ali Date: Sat, 29 Nov 2014 02:51:53 -0600 Subject: [PATCH 102/243] Core: fix compile issue of healthd.` fixes this in darwin cp: symlink: /sbin/healthd: File exists Change-Id: Ia0a51962ec6d1713ece1e9c1d4f9df479fee5f5b --- healthd/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/healthd/Android.mk b/healthd/Android.mk index 2e3270d3..5049886f 100644 --- a/healthd/Android.mk +++ b/healthd/Android.mk @@ -47,7 +47,7 @@ LOCAL_HAL_STATIC_LIBRARIES := libhealthd # Symlink /charger to /sbin/healthd LOCAL_POST_INSTALL_CMD := $(hide) mkdir -p $(TARGET_ROOT_OUT) \ - && ln -sf /sbin/healthd $(TARGET_ROOT_OUT)/charger + && rm -f $(TARGET_ROOT_OUT)/charger && ln -sf /sbin/healthd $(TARGET_ROOT_OUT)/charger include $(BUILD_EXECUTABLE) From 9fc1145ef786c46174a39fd09ed78be6ab82b68a Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Wed, 26 Nov 2014 13:48:46 -0800 Subject: [PATCH 103/243] adb: Look for bu in /sbin when in recovery mode * Restore global variable recovery_mode. This is set based on the commandline parameter --banner. * Use recovery_mode to select path to 'bu' binary for both backup and restore services. Change-Id: Ie4c945d00601514d7f16357bae10ff7f232633e1 --- adb/adb.c | 6 ++++++ adb/adb.h | 2 ++ adb/services.c | 13 +++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/adb/adb.c b/adb/adb.c index 4300754b..af2e5b9c 100644 --- a/adb/adb.c +++ b/adb/adb.c @@ -1684,6 +1684,10 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r return -1; } +#if !ADB_HOST +int recovery_mode = 0; +#endif + int main(int argc, char **argv) { #if ADB_HOST @@ -1717,6 +1721,8 @@ int main(int argc, char **argv) } } + recovery_mode = (strcmp(adb_device_banner, "recovery") == 0); + start_device_log(); D("Handling main()\n"); return adb_main(0, DEFAULT_ADB_PORT); diff --git a/adb/adb.h b/adb/adb.h index 1097123e..f918a77f 100644 --- a/adb/adb.h +++ b/adb/adb.h @@ -380,6 +380,8 @@ int adb_commandline(int argc, char **argv); int connection_state(atransport *t); +extern int recovery_mode; + #define CS_ANY -1 #define CS_OFFLINE 0 #define CS_BOOTLOADER 1 diff --git a/adb/services.c b/adb/services.c index 588690d9..4cc4c75a 100644 --- a/adb/services.c +++ b/adb/services.c @@ -407,6 +407,11 @@ static int create_subproc_thread(const char *name, const subproc_mode mode) } #endif +static const char* bu_path() +{ + return (recovery_mode ? "/sbin/bu" : "/system/bin/bu"); +} + int service_to_fd(const char *name) { int ret = -1; @@ -469,13 +474,17 @@ int service_to_fd(const char *name) *c = ' '; } char* cmd; - if (asprintf(&cmd, "/system/bin/bu backup %s", arg) != -1) { + if (asprintf(&cmd, "%s backup %s", bu_path(), arg) != -1) { ret = create_subproc_thread(cmd, SUBPROC_RAW); free(cmd); } free(arg); } else if(!strncmp(name, "restore:", 8)) { - ret = create_subproc_thread("/system/bin/bu restore", SUBPROC_RAW); + char* cmd; + if (asprintf(&cmd, "%s restore", bu_path()) != -1) { + ret = create_subproc_thread(cmd, SUBPROC_RAW); + free(cmd); + } } else if(!strncmp(name, "tcpip:", 6)) { int port; if (sscanf(name + 6, "%d", &port) == 0) { From 7eb80791878ba3c0086c1a35e0fa4f7d5e80a71f Mon Sep 17 00:00:00 2001 From: Sravan Kumar Ambapuram Date: Wed, 7 May 2014 11:15:38 +0530 Subject: [PATCH 104/243] healthd: increase healthd fast timer to 10mins instead of 1min healthd 1 min wakeups are causing significant power impact during static display use case. so increasing the timer to 10min. Change-Id: If7a514e4152789144242e198175918b6687c3bcf --- healthd/healthd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/healthd/healthd.cpp b/healthd/healthd.cpp index dcb95c88..c2dcc36f 100644 --- a/healthd/healthd.cpp +++ b/healthd/healthd.cpp @@ -37,7 +37,7 @@ using namespace android; // Periodic chores intervals in seconds -#define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (60 * 1) +#define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (60 * 10) #define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (60 * 10) static struct healthd_config healthd_config = { From b27db7d61512854a6bf2739d2bfd1c9f28dd89a4 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Mon, 1 Dec 2014 13:08:32 -0800 Subject: [PATCH 105/243] adb: Fix compilation warning Change-Id: Iab0cb977f81824338a37ecba233b45883c0bc13b --- adb/services.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adb/services.c b/adb/services.c index 4cc4c75a..34956d99 100644 --- a/adb/services.c +++ b/adb/services.c @@ -407,10 +407,12 @@ static int create_subproc_thread(const char *name, const subproc_mode mode) } #endif +#if !ADB_HOST static const char* bu_path() { return (recovery_mode ? "/sbin/bu" : "/system/bin/bu"); } +#endif int service_to_fd(const char *name) { From f522a5990087089ed956829fb65d26384ed0ab4e Mon Sep 17 00:00:00 2001 From: rbox Date: Mon, 23 Dec 2013 15:24:23 -0700 Subject: [PATCH 106/243] adb: Allow configuring the adb shell with a persistent property. To set to bash: setprop persist.sys.adb.shell /system/xbin/bash Change-Id: I24e65f4592aaf23356c13db02c9869076df3b841 --- adb/services.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adb/services.c b/adb/services.c index 34956d99..e9bd8714 100644 --- a/adb/services.c +++ b/adb/services.c @@ -369,7 +369,12 @@ static int create_subproc_thread(const char *name, const subproc_mode mode) arg0 = "-c"; arg1 = name; } - if (stat(ALTERNATE_SHELL_COMMAND, &st) == 0) { + char value[PROPERTY_VALUE_MAX]; + property_get("persist.sys.adb.shell", value, ""); + if (value[0] != '\0' && stat(value, &st) == 0) { + shell_command = value; + } + else if (stat(ALTERNATE_SHELL_COMMAND, &st) == 0) { shell_command = ALTERNATE_SHELL_COMMAND; } else { From a726b7c7c02b11a966dfbfc6b0de5b8013aec182 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Mon, 1 Dec 2014 14:54:19 +0000 Subject: [PATCH 107/243] Set gateway properties for being accessible in DataCallResponse Some devices need gateway properties to be set inorder to setup route correctly Change-Id: I45dce29de916f07eb79fad77dec914787c78e7ce --- libnetutils/ifc_utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c index 913f51e8..d9c50ab8 100644 --- a/libnetutils/ifc_utils.c +++ b/libnetutils/ifc_utils.c @@ -699,6 +699,8 @@ ifc_configure(const char *ifname, property_set(dns_prop_name, dns1 ? ipaddr_to_string(dns1) : ""); snprintf(dns_prop_name, sizeof(dns_prop_name), "net.%s.dns2", ifname); property_set(dns_prop_name, dns2 ? ipaddr_to_string(dns2) : ""); + snprintf(dns_prop_name, sizeof(dns_prop_name), "net.%s.gw", ifname); + property_set(dns_prop_name, gateway ? ipaddr_to_string(gateway) : ""); return 0; } From 51585e24e4e7c2c304767a537d7b3ee6e6fa31c9 Mon Sep 17 00:00:00 2001 From: atinm Date: Tue, 3 May 2011 00:26:33 -0400 Subject: [PATCH 108/243] Use RECOVERY_PRE_COMMAND before calling __reboot() recovery For the Power menu, frameworks/base/core/jni/android_os_Power.cpp#L180 already uses RECOVERY_PRE_COMMAND if TARGET_RECOVERY_PRE_COMMAND is defined in the BoardConfig.mk for a device to make a system() call before calling __reboot() for recovery. This commit adds the same thing to the other places that we know we are getting into recovery using __reboot(), namely, adb reboot recovery, the reboot binary and init in the case of errors. Signed-off-by: Humberto Borba Conflicts: libcutils/Android.mk libcutils/android_reboot.c Change-Id: Id0fb6675accd732f46d4b10e0fce459d2582875c --- libcutils/Android.mk | 5 +++++ libcutils/android_reboot.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/libcutils/Android.mk b/libcutils/Android.mk index b016a423..0b410042 100644 --- a/libcutils/Android.mk +++ b/libcutils/Android.mk @@ -141,7 +141,12 @@ LOCAL_CFLAGS_mips += -DHAVE_MEMSET16 -DHAVE_MEMSET32 LOCAL_CFLAGS_x86 += -DHAVE_MEMSET16 -DHAVE_MEMSET32 LOCAL_CFLAGS_x86_64 += -DHAVE_MEMSET16 -DHAVE_MEMSET32 +ifneq ($(TARGET_RECOVERY_PRE_COMMAND),) + LOCAL_CFLAGS += -DRECOVERY_PRE_COMMAND='$(TARGET_RECOVERY_PRE_COMMAND)' +endif + LOCAL_C_INCLUDES := $(libcutils_c_includes) + LOCAL_STATIC_LIBRARIES := liblog LOCAL_CFLAGS += $(targetSmpFlag) -Werror LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk diff --git a/libcutils/android_reboot.c b/libcutils/android_reboot.c index 72bd18e5..7fca9e9f 100644 --- a/libcutils/android_reboot.c +++ b/libcutils/android_reboot.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -121,6 +122,10 @@ int android_reboot(int cmd, int flags UNUSED, char *arg) break; case ANDROID_RB_RESTART2: +#ifdef RECOVERY_PRE_COMMAND + if (!strncmp((char *)arg,"recovery",8)) + system( RECOVERY_PRE_COMMAND ); +#endif ret = syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, arg); break; From c0860dada6e1305741d28c55d8119aab031412e3 Mon Sep 17 00:00:00 2001 From: Danesh M Date: Fri, 25 Nov 2011 20:53:19 -0500 Subject: [PATCH 109/243] libcutils : reboot mount fix On aries for eg, cache needs to be rw for the RECOVERY_PRE_COMMAND to work because we write to /cache/.startrecovery This patchset moves the RECOVERY_PRE_COMMAND prior to the remount. Conflicts: libcutils/android_reboot.c Change-Id: I4bd97517e00cdd117191d29b610e9623ad7d9255 --- libcutils/android_reboot.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libcutils/android_reboot.c b/libcutils/android_reboot.c index 7fca9e9f..30d2dc24 100644 --- a/libcutils/android_reboot.c +++ b/libcutils/android_reboot.c @@ -112,6 +112,13 @@ int android_reboot(int cmd, int flags UNUSED, char *arg) sync(); remount_ro(); +#ifdef RECOVERY_PRE_COMMAND + if (cmd == ANDROID_RB_RESTART2) { + if (!strncmp((char *)arg,"recovery",8)) + system( RECOVERY_PRE_COMMAND ); + } +#endif + switch (cmd) { case ANDROID_RB_RESTART: ret = reboot(RB_AUTOBOOT); @@ -122,10 +129,6 @@ int android_reboot(int cmd, int flags UNUSED, char *arg) break; case ANDROID_RB_RESTART2: -#ifdef RECOVERY_PRE_COMMAND - if (!strncmp((char *)arg,"recovery",8)) - system( RECOVERY_PRE_COMMAND ); -#endif ret = syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, arg); break; From e9f305d5f0cc3ed7cdcb20227018dbcfb41f7152 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 1 Dec 2011 04:35:39 +0100 Subject: [PATCH 110/243] RECOVERY_PRE_COMMAND_CLEAR_REASON and extended reboot arguments fix the 2 new warnings created by our 4-lines recovery patch ;p Allow also to override toolbox reboot applet, for bootmenu Conflicts: libcutils/Android.mk libcutils/android_reboot.c toolbox/Android.mk Change-Id: I2bff30b5f911e7b9ba8f26593523368223b12814 --- libcutils/Android.mk | 5 ++++- libcutils/android_reboot.c | 31 ++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/libcutils/Android.mk b/libcutils/Android.mk index 0b410042..69e00d1f 100644 --- a/libcutils/Android.mk +++ b/libcutils/Android.mk @@ -145,8 +145,11 @@ ifneq ($(TARGET_RECOVERY_PRE_COMMAND),) LOCAL_CFLAGS += -DRECOVERY_PRE_COMMAND='$(TARGET_RECOVERY_PRE_COMMAND)' endif -LOCAL_C_INCLUDES := $(libcutils_c_includes) +ifeq ($(TARGET_RECOVERY_PRE_COMMAND_CLEAR_REASON),true) + LOCAL_CFLAGS += -DRECOVERY_PRE_COMMAND_CLEAR_REASON +endif +LOCAL_C_INCLUDES := $(libcutils_c_includes) $(KERNEL_HEADERS) LOCAL_STATIC_LIBRARIES := liblog LOCAL_CFLAGS += $(targetSmpFlag) -Werror LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk diff --git a/libcutils/android_reboot.c b/libcutils/android_reboot.c index 30d2dc24..9f8f968c 100644 --- a/libcutils/android_reboot.c +++ b/libcutils/android_reboot.c @@ -107,36 +107,49 @@ static void remount_ro(void) int android_reboot(int cmd, int flags UNUSED, char *arg) { - int ret; + int ret = 0; + int reason = -1; sync(); remount_ro(); #ifdef RECOVERY_PRE_COMMAND - if (cmd == ANDROID_RB_RESTART2) { - if (!strncmp((char *)arg,"recovery",8)) - system( RECOVERY_PRE_COMMAND ); + if (cmd == (int) ANDROID_RB_RESTART2) { + if (arg && strlen(arg) > 0) { + char cmd[PATH_MAX]; + sprintf(cmd, RECOVERY_PRE_COMMAND " %s", arg); + system(cmd); + } } #endif switch (cmd) { case ANDROID_RB_RESTART: - ret = reboot(RB_AUTOBOOT); + reason = RB_AUTOBOOT; break; case ANDROID_RB_POWEROFF: ret = reboot(RB_POWER_OFF); - break; + return ret; case ANDROID_RB_RESTART2: - ret = syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, - LINUX_REBOOT_CMD_RESTART2, arg); + // REBOOT_MAGIC break; default: - ret = -1; + return -1; } +#ifdef RECOVERY_PRE_COMMAND_CLEAR_REASON + reason = RB_AUTOBOOT; +#endif + + if (reason != -1) + ret = reboot(reason); + else + ret = syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, + LINUX_REBOOT_CMD_RESTART2, arg); + return ret; } From 1ff785445828a9a40138d67e1de2a4fbae9680e9 Mon Sep 17 00:00:00 2001 From: Arne Coucheron Date: Wed, 3 Dec 2014 06:14:55 +0100 Subject: [PATCH 111/243] libutils: Properly #ifdef NEEDS_VECTORIMPL_SYMBOLS * Compile error might occur otherwise Change-Id: I982e5f72ea4e84594e415394cceed44f90045526 --- include/utils/VectorImpl.h | 4 ++-- libutils/VectorImpl.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/utils/VectorImpl.h b/include/utils/VectorImpl.h index cab95bef..88c3a05d 100644 --- a/include/utils/VectorImpl.h +++ b/include/utils/VectorImpl.h @@ -106,7 +106,7 @@ class VectorImpl virtual void do_move_forward(void* dest, const void* from, size_t num) const = 0; virtual void do_move_backward(void* dest, const void* from, size_t num) const = 0; -#if NEEDS_VECTORIMPL_SYMBOLS +#ifdef NEEDS_VECTORIMPL_SYMBOLS // take care of FBC... virtual void reservedVectorImpl1(); virtual void reservedVectorImpl2(); @@ -168,7 +168,7 @@ class SortedVectorImpl : public VectorImpl protected: virtual int do_compare(const void* lhs, const void* rhs) const = 0; -#if NEEDS_VECTORIMPL_SYMBOLS +#ifdef NEEDS_VECTORIMPL_SYMBOLS // take care of FBC... virtual void reservedSortedVectorImpl1(); virtual void reservedSortedVectorImpl2(); diff --git a/libutils/VectorImpl.cpp b/libutils/VectorImpl.cpp index 0bfc1f00..c4944cf8 100644 --- a/libutils/VectorImpl.cpp +++ b/libutils/VectorImpl.cpp @@ -516,7 +516,7 @@ void VectorImpl::_do_move_backward(void* dest, const void* from, size_t num) con do_move_backward(dest, from, num); } -#if NEEDS_VECTORIMPL_SYMBOLS +#ifdef NEEDS_VECTORIMPL_SYMBOLS void VectorImpl::reservedVectorImpl1() { } void VectorImpl::reservedVectorImpl2() { } void VectorImpl::reservedVectorImpl3() { } @@ -642,7 +642,7 @@ ssize_t SortedVectorImpl::remove(const void* item) return i; } -#if NEEDS_VECTORIMPL_SYMBOLS +#ifdef NEEDS_VECTORIMPL_SYMBOLS void SortedVectorImpl::reservedSortedVectorImpl1() { }; void SortedVectorImpl::reservedSortedVectorImpl2() { }; void SortedVectorImpl::reservedSortedVectorImpl3() { }; From 0e39aefc7c71de83e89ffe6d3c05527c804aaabd Mon Sep 17 00:00:00 2001 From: "Christopher R. Palmer" Date: Wed, 3 Dec 2014 16:48:04 -0500 Subject: [PATCH 112/243] init: Make restorecon_recursive work for /data/ In the following commit: commit f2b7ee765516c84a9995e3acdc8fbcd7dc1b33cc Author: Stephen Smalley Date: Thu Feb 6 13:52:52 2014 -0500 Apply restorecon_recursive to all of /data. they removed all the adhoc restorecon_recursive of subdirectories of /data/ and replaced it with: # Set SELinux security contexts on upgrade or policy update. restorecon_recursive /data Unfortunately, that is a no-op because restorecon doesn't recurse through /data/ unless you add a FORCE flag. Since the expectation seems to be that the recursive restorecon in init will actually work, update the built-in to add the force flag and a flag to allow /data/data to also be recursed through. Change-Id: I434c505188e924b27ef2e6a2e0ee0a6951e43f0e --- init/util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/init/util.c b/init/util.c index e1a3ee33..570f2f31 100644 --- a/init/util.c +++ b/init/util.c @@ -530,7 +530,12 @@ int restorecon(const char* pathname) return selinux_android_restorecon(pathname, 0); } +#define RESTORECON_RECURSIVE_FLAGS \ + (SELINUX_ANDROID_RESTORECON_DATADATA | \ + SELINUX_ANDROID_RESTORECON_FORCE | \ + SELINUX_ANDROID_RESTORECON_RECURSE) + int restorecon_recursive(const char* pathname) { - return selinux_android_restorecon(pathname, SELINUX_ANDROID_RESTORECON_RECURSE); + return selinux_android_restorecon(pathname, RESTORECON_RECURSIVE_FLAGS); } From e24e1333075934b7688c41c606226cae0f84723e Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Thu, 4 Dec 2014 17:58:29 +0000 Subject: [PATCH 113/243] Revert "init: Make restorecon_recursive work for /data/" This reverts commit 0e39aefc7c71de83e89ffe6d3c05527c804aaabd. Change-Id: I37af3548c7a2635ced7b5f0bd847226d6c5c4bf0 --- init/util.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/init/util.c b/init/util.c index 570f2f31..e1a3ee33 100644 --- a/init/util.c +++ b/init/util.c @@ -530,12 +530,7 @@ int restorecon(const char* pathname) return selinux_android_restorecon(pathname, 0); } -#define RESTORECON_RECURSIVE_FLAGS \ - (SELINUX_ANDROID_RESTORECON_DATADATA | \ - SELINUX_ANDROID_RESTORECON_FORCE | \ - SELINUX_ANDROID_RESTORECON_RECURSE) - int restorecon_recursive(const char* pathname) { - return selinux_android_restorecon(pathname, RESTORECON_RECURSIVE_FLAGS); + return selinux_android_restorecon(pathname, SELINUX_ANDROID_RESTORECON_RECURSE); } From 6653c316fc3c4334c548db9de1ef975553001814 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 19 Nov 2014 22:07:34 -0800 Subject: [PATCH 114/243] Remove the adb usb vendor id whitelist. If there are bad vendors, we should blacklist them. Whitelisting the entire world is crazy. Change-Id: I1f4c27fd34fc420e2a3b4b2c8749198030db69f1 Disable vendor id filtering for Linux. It's time we switched to blacklisting any problematic devices rather than slowly whitelisting the entire world. This seems to work for me, but let's see how other people get on before coming back to actually remove the list. We'll also need to find a Mac to test the equivalent Mac change. Change-Id: I2bf583a27f9a3f98ef006ea62b906a4f89960507 Disable vendor id filtering for OS X. Companion patch for change I2bf583a27f9a3f98ef006ea62b906a4f89960507. Due to the use of USB class 0xff it's not possible to register a listener which uses the OS methods for filtering notifications, so this patch also introduces a check in the notification listener which checks the class, subclass, and protocol for the interface each notification relates to. Change-Id: I380cc80f96addc5057660efb2179b35f9378886a --- adb/Android.mk | 2 - adb/adb.c | 3 - adb/transport_usb.c | 18 +-- adb/usb_osx.c | 93 +++++------ adb/usb_vendors.c | 367 -------------------------------------------- adb/usb_vendors.h | 25 --- 6 files changed, 38 insertions(+), 470 deletions(-) delete mode 100755 adb/usb_vendors.c delete mode 100644 adb/usb_vendors.h diff --git a/adb/Android.mk b/adb/Android.mk index a815c77d..80c23147 100644 --- a/adb/Android.mk +++ b/adb/Android.mk @@ -62,7 +62,6 @@ LOCAL_SRC_FILES := \ file_sync_client.c \ $(EXTRA_SRCS) \ $(USB_SRCS) \ - usb_vendors.c LOCAL_C_INCLUDES += external/openssl/include @@ -154,7 +153,6 @@ LOCAL_SRC_FILES := \ file_sync_client.c \ get_my_path_linux.c \ usb_linux.c \ - usb_vendors.c \ fdevent.c LOCAL_CFLAGS := \ diff --git a/adb/adb.c b/adb/adb.c index af2e5b9c..c2e5f4ab 100644 --- a/adb/adb.c +++ b/adb/adb.c @@ -41,8 +41,6 @@ #include #include #include -#else -#include "usb_vendors.h" #endif #if ADB_TRACE @@ -1318,7 +1316,6 @@ int adb_main(int is_daemon, int server_port) #ifdef WORKAROUND_BUG6558362 if(is_daemon) adb_set_affinity(); #endif - usb_vendors_init(); usb_init(); local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT); adb_auth_init(); diff --git a/adb/transport_usb.c b/adb/transport_usb.c index ee6b637b..3d198030 100644 --- a/adb/transport_usb.c +++ b/adb/transport_usb.c @@ -23,10 +23,6 @@ #define TRACE_TAG TRACE_TRANSPORT #include "adb.h" -#if ADB_HOST -#include "usb_vendors.h" -#endif - #ifdef HAVE_BIG_ENDIAN #define H4(x) (((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24) static inline void fix_endians(apacket *p) @@ -131,18 +127,6 @@ void init_usb_transport(atransport *t, usb_handle *h, int state) #if ADB_HOST int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol) { - unsigned i; - for (i = 0; i < vendorIdCount; i++) { - if (vid == vendorIds[i]) { - if (usb_class == ADB_CLASS && usb_subclass == ADB_SUBCLASS && - usb_protocol == ADB_PROTOCOL) { - return 1; - } - - return 0; - } - } - - return 0; + return (usb_class == ADB_CLASS && usb_subclass == ADB_SUBCLASS && usb_protocol == ADB_PROTOCOL); } #endif diff --git a/adb/usb_osx.c b/adb/usb_osx.c index ca4f2afd..294cc72d 100644 --- a/adb/usb_osx.c +++ b/adb/usb_osx.c @@ -28,12 +28,11 @@ #define TRACE_TAG TRACE_USB #include "adb.h" -#include "usb_vendors.h" #define DBG D static IONotificationPortRef notificationPort = 0; -static io_iterator_t* notificationIterators; +static io_iterator_t notificationIterator; struct usb_handle { @@ -61,8 +60,6 @@ InitUSB() { CFMutableDictionaryRef matchingDict; CFRunLoopSourceRef runLoopSource; - SInt32 vendor, if_subclass, if_protocol; - unsigned i; //* To set up asynchronous notifications, create a notification port and //* add its run loop event source to the program's run loop @@ -70,47 +67,33 @@ InitUSB() runLoopSource = IONotificationPortGetRunLoopSource(notificationPort); CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode); - memset(notificationIterators, 0, sizeof(notificationIterators)); + //* Create our matching dictionary to find the Android device's + //* adb interface + //* IOServiceAddMatchingNotification consumes the reference, so we do + //* not need to release this + matchingDict = IOServiceMatching(kIOUSBInterfaceClassName); - //* loop through all supported vendors - for (i = 0; i < vendorIdCount; i++) { - //* Create our matching dictionary to find the Android device's - //* adb interface - //* IOServiceAddMatchingNotification consumes the reference, so we do - //* not need to release this - matchingDict = IOServiceMatching(kIOUSBInterfaceClassName); - - if (!matchingDict) { - DBG("ERR: Couldn't create USB matching dictionary.\n"); - return -1; - } - - //* Match based on vendor id, interface subclass and protocol - vendor = vendorIds[i]; - if_subclass = ADB_SUBCLASS; - if_protocol = ADB_PROTOCOL; - CFDictionarySetValue(matchingDict, CFSTR(kUSBVendorID), - CFNumberCreate(kCFAllocatorDefault, - kCFNumberSInt32Type, &vendor)); - CFDictionarySetValue(matchingDict, CFSTR(kUSBInterfaceSubClass), - CFNumberCreate(kCFAllocatorDefault, - kCFNumberSInt32Type, &if_subclass)); - CFDictionarySetValue(matchingDict, CFSTR(kUSBInterfaceProtocol), - CFNumberCreate(kCFAllocatorDefault, - kCFNumberSInt32Type, &if_protocol)); - IOServiceAddMatchingNotification( - notificationPort, - kIOFirstMatchNotification, - matchingDict, - AndroidInterfaceAdded, - NULL, - ¬ificationIterators[i]); - - //* Iterate over set of matching interfaces to access already-present - //* devices and to arm the notification - AndroidInterfaceAdded(NULL, notificationIterators[i]); + if (!matchingDict) { + DBG("ERR: Couldn't create USB matching dictionary.\n"); + return -1; } + //* We have to get notifications for all potential candidates and test them + //* at connection time because the matching rules don't allow for a + //* USB interface class of 0xff for class+subclass+protocol matches + //* See https://developer.apple.com/library/mac/qa/qa1076/_index.html + IOServiceAddMatchingNotification( + notificationPort, + kIOFirstMatchNotification, + matchingDict, + AndroidInterfaceAdded, + NULL, + ¬ificationIterator); + + //* Iterate over set of matching interfaces to access already-present + //* devices and to arm the notification + AndroidInterfaceAdded(NULL, notificationIterator); + return 0; } @@ -126,6 +109,7 @@ AndroidInterfaceAdded(void *refCon, io_iterator_t iterator) HRESULT result; SInt32 score; UInt32 locationId; + UInt8 class, subclass, protocol; UInt16 vendor; UInt16 product; UInt8 serialIndex; @@ -156,6 +140,16 @@ AndroidInterfaceAdded(void *refCon, io_iterator_t iterator) continue; } + kr = (*iface)->GetInterfaceClass(iface, &class); + kr = (*iface)->GetInterfaceSubClass(iface, &subclass); + kr = (*iface)->GetInterfaceProtocol(iface, &protocol); + if(class != ADB_CLASS || subclass != ADB_SUBCLASS || protocol != ADB_PROTOCOL) { + // Ignore non-ADB devices. + DBG("Ignoring interface with incorrect class/subclass/protocol - %d, %d, %d\n", class, subclass, protocol); + (*iface)->Release(iface); + continue; + } + //* this gets us an ioservice, with which we will find the actual //* device; after getting a plugin, and querying the interface, of //* course. @@ -192,7 +186,6 @@ AndroidInterfaceAdded(void *refCon, io_iterator_t iterator) //* Now after all that, we actually have a ref to the device and //* the interface that matched our criteria - kr = (*dev)->GetDeviceVendor(dev, &vendor); kr = (*dev)->GetDeviceProduct(dev, &product); kr = (*dev)->GetLocationID(dev, &locationId); @@ -384,8 +377,6 @@ CheckInterface(IOUSBInterfaceInterface **interface, UInt16 vendor, UInt16 produc void* RunLoopThread(void* unused) { - unsigned i; - InitUSB(); currentRunLoop = CFRunLoopGetCurrent(); @@ -398,9 +389,7 @@ void* RunLoopThread(void* unused) CFRunLoopRun(); currentRunLoop = 0; - for (i = 0; i < vendorIdCount; i++) { - IOObjectRelease(notificationIterators[i]); - } + IOObjectRelease(notificationIterator); IONotificationPortDestroy(notificationPort); DBG("RunLoopThread done\n"); @@ -415,9 +404,6 @@ void usb_init() { adb_thread_t tid; - notificationIterators = (io_iterator_t*)malloc( - vendorIdCount * sizeof(io_iterator_t)); - adb_mutex_init(&start_lock, NULL); adb_cond_init(&start_cond, NULL); @@ -442,11 +428,6 @@ void usb_cleanup() close_usb_devices(); if (currentRunLoop) CFRunLoopStop(currentRunLoop); - - if (notificationIterators != NULL) { - free(notificationIterators); - notificationIterators = NULL; - } } int usb_write(usb_handle *handle, const void *buf, int len) diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c deleted file mode 100755 index 957e5db1..00000000 --- a/adb/usb_vendors.c +++ /dev/null @@ -1,367 +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. - */ - -#include "usb_vendors.h" - -#include - -#ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# include "windows.h" -# include "shlobj.h" -#else -# include -# include -#endif - -#include "sysdeps.h" -#include "adb.h" - -#define ANDROID_PATH ".android" -#define ANDROID_ADB_INI "adb_usb.ini" - -#define TRACE_TAG TRACE_USB - -/* Keep the list below sorted alphabetically by #define name */ -// Acer's USB Vendor ID -#define VENDOR_ID_ACER 0x0502 -// Allwinner's USB Vendor ID -#define VENDOR_ID_ALLWINNER 0x1F3A -// Amlogic's USB Vendor ID -#define VENDOR_ID_AMLOGIC 0x1b8e -// AnyDATA's USB Vendor ID -#define VENDOR_ID_ANYDATA 0x16D5 -// Archos's USB Vendor ID -#define VENDOR_ID_ARCHOS 0x0E79 -// Asus's USB Vendor ID -#define VENDOR_ID_ASUS 0x0b05 -// BYD's USB Vendor ID -#define VENDOR_ID_BYD 0x1D91 -// Compal's USB Vendor ID -#define VENDOR_ID_COMPAL 0x04B7 -// Compalcomm's USB Vendor ID -#define VENDOR_ID_COMPALCOMM 0x1219 -// Dell's USB Vendor ID -#define VENDOR_ID_DELL 0x413c -// ECS's USB Vendor ID -#define VENDOR_ID_ECS 0x03fc -// EMERGING_TECH's USB Vendor ID -#define VENDOR_ID_EMERGING_TECH 0x297F -// Emerson's USB Vendor ID -#define VENDOR_ID_EMERSON 0x2207 -// Foxconn's USB Vendor ID -#define VENDOR_ID_FOXCONN 0x0489 -// Fujitsu's USB Vendor ID -#define VENDOR_ID_FUJITSU 0x04C5 -// Funai's USB Vendor ID -#define VENDOR_ID_FUNAI 0x0F1C -// Garmin-Asus's USB Vendor ID -#define VENDOR_ID_GARMIN_ASUS 0x091E -// Gigabyte's USB Vendor ID -#define VENDOR_ID_GIGABYTE 0x0414 -// Gigaset's USB Vendor ID -#define VENDOR_ID_GIGASET 0x1E85 -// GIONEE's USB Vendor ID -#define VENDOR_ID_GIONEE 0x271D -// Google's USB Vendor ID -#define VENDOR_ID_GOOGLE 0x18d1 -// Haier's USB Vendor ID -#define VENDOR_ID_HAIER 0x201E -// Harris's USB Vendor ID -#define VENDOR_ID_HARRIS 0x19A5 -// Hisense's USB Vendor ID -#define VENDOR_ID_HISENSE 0x109b -// Honeywell's USB Vendor ID -#define VENDOR_ID_HONEYWELL 0x0c2e -// HP's USB Vendor ID -#define VENDOR_ID_HP 0x03f0 -// HTC's USB Vendor ID -#define VENDOR_ID_HTC 0x0bb4 -// Huawei's USB Vendor ID -#define VENDOR_ID_HUAWEI 0x12D1 -// INQ Mobile's USB Vendor ID -#define VENDOR_ID_INQ_MOBILE 0x2314 -// Intel's USB Vendor ID -#define VENDOR_ID_INTEL 0x8087 -// Intermec's USB Vendor ID -#define VENDOR_ID_INTERMEC 0x067e -// IRiver's USB Vendor ID -#define VENDOR_ID_IRIVER 0x2420 -// K-Touch's USB Vendor ID -#define VENDOR_ID_K_TOUCH 0x24E3 -// KT Tech's USB Vendor ID -#define VENDOR_ID_KT_TECH 0x2116 -// Kobo's USB Vendor ID -#define VENDOR_ID_KOBO 0x2237 -// Kyocera's USB Vendor ID -#define VENDOR_ID_KYOCERA 0x0482 -// Lab126's USB Vendor ID -#define VENDOR_ID_LAB126 0x1949 -// Lenovo's USB Vendor ID -#define VENDOR_ID_LENOVO 0x17EF -// LenovoMobile's USB Vendor ID -#define VENDOR_ID_LENOVOMOBILE 0x2006 -// LG's USB Vendor ID -#define VENDOR_ID_LGE 0x1004 -// Lumigon's USB Vendor ID -#define VENDOR_ID_LUMIGON 0x25E3 -// Motorola's USB Vendor ID -#define VENDOR_ID_MOTOROLA 0x22b8 -// MSI's USB Vendor ID -#define VENDOR_ID_MSI 0x0DB0 -// MTK's USB Vendor ID -#define VENDOR_ID_MTK 0x0e8d -// NEC's USB Vendor ID -#define VENDOR_ID_NEC 0x0409 -// B&N Nook's USB Vendor ID -#define VENDOR_ID_NOOK 0x2080 -// Nvidia's USB Vendor ID -#define VENDOR_ID_NVIDIA 0x0955 -// OPPO's USB Vendor ID -#define VENDOR_ID_OPPO 0x22D9 -// On-The-Go-Video's USB Vendor ID -#define VENDOR_ID_OTGV 0x2257 -// OUYA's USB Vendor ID -#define VENDOR_ID_OUYA 0x2836 -// Pantech's USB Vendor ID -#define VENDOR_ID_PANTECH 0x10A9 -// Pegatron's USB Vendor ID -#define VENDOR_ID_PEGATRON 0x1D4D -// Philips's USB Vendor ID -#define VENDOR_ID_PHILIPS 0x0471 -// Panasonic Mobile Communication's USB Vendor ID -#define VENDOR_ID_PMC 0x04DA -// Positivo's USB Vendor ID -#define VENDOR_ID_POSITIVO 0x1662 -// Prestigio's USB Vendor ID -#define VENDOR_ID_PRESTIGIO 0x29e4 -// Qisda's USB Vendor ID -#define VENDOR_ID_QISDA 0x1D45 -// Qualcomm's USB Vendor ID -#define VENDOR_ID_QUALCOMM 0x05c6 -// Quanta's USB Vendor ID -#define VENDOR_ID_QUANTA 0x0408 -// Rockchip's USB Vendor ID -#define VENDOR_ID_ROCKCHIP 0x2207 -// Samsung's USB Vendor ID -#define VENDOR_ID_SAMSUNG 0x04e8 -// Sharp's USB Vendor ID -#define VENDOR_ID_SHARP 0x04dd -// SK Telesys's USB Vendor ID -#define VENDOR_ID_SK_TELESYS 0x1F53 -// Smartisan's USB Vendor ID -#define VENDOR_ID_SMARTISAN 0x29a9 -// Sony's USB Vendor ID -#define VENDOR_ID_SONY 0x054C -// Sony Ericsson's USB Vendor ID -#define VENDOR_ID_SONY_ERICSSON 0x0FCE -// T & A Mobile Phones' USB Vendor ID -#define VENDOR_ID_T_AND_A 0x1BBB -// TechFaith's USB Vendor ID -#define VENDOR_ID_TECHFAITH 0x1d09 -// Teleepoch's USB Vendor ID -#define VENDOR_ID_TELEEPOCH 0x2340 -// Texas Instruments's USB Vendor ID -#define VENDOR_ID_TI 0x0451 -// Toshiba's USB Vendor ID -#define VENDOR_ID_TOSHIBA 0x0930 -// Unowhy's USB Vendor ID -#define VENDOR_ID_UNOWHY 0x2A49 -// Vizio's USB Vendor ID -#define VENDOR_ID_VIZIO 0xE040 -// Wacom's USB Vendor ID -#define VENDOR_ID_WACOM 0x0531 -// Xiaomi's USB Vendor ID -#define VENDOR_ID_XIAOMI 0x2717 -// YotaDevices's USB Vendor ID -#define VENDOR_ID_YOTADEVICES 0x2916 -// Yulong Coolpad's USB Vendor ID -#define VENDOR_ID_YULONG_COOLPAD 0x1EBF -// ZTE's USB Vendor ID -#define VENDOR_ID_ZTE 0x19D2 -/* Keep the list above sorted alphabetically by #define name */ - -/** built-in vendor list */ -/* Keep the list below sorted alphabetically */ -int builtInVendorIds[] = { - VENDOR_ID_ACER, - VENDOR_ID_ALLWINNER, - VENDOR_ID_AMLOGIC, - VENDOR_ID_ANYDATA, - VENDOR_ID_ARCHOS, - VENDOR_ID_ASUS, - VENDOR_ID_BYD, - VENDOR_ID_COMPAL, - VENDOR_ID_COMPALCOMM, - VENDOR_ID_DELL, - VENDOR_ID_ECS, - VENDOR_ID_EMERGING_TECH, - VENDOR_ID_EMERSON, - VENDOR_ID_FOXCONN, - VENDOR_ID_FUJITSU, - VENDOR_ID_FUNAI, - VENDOR_ID_GARMIN_ASUS, - VENDOR_ID_GIGABYTE, - VENDOR_ID_GIGASET, - VENDOR_ID_GIONEE, - VENDOR_ID_GOOGLE, - VENDOR_ID_HAIER, - VENDOR_ID_HARRIS, - VENDOR_ID_HISENSE, - VENDOR_ID_HONEYWELL, - VENDOR_ID_HP, - VENDOR_ID_HTC, - VENDOR_ID_HUAWEI, - VENDOR_ID_INQ_MOBILE, - VENDOR_ID_INTEL, - VENDOR_ID_INTERMEC, - VENDOR_ID_IRIVER, - VENDOR_ID_KOBO, - VENDOR_ID_K_TOUCH, - VENDOR_ID_KT_TECH, - VENDOR_ID_KYOCERA, - VENDOR_ID_LAB126, - VENDOR_ID_LENOVO, - VENDOR_ID_LENOVOMOBILE, - VENDOR_ID_LGE, - VENDOR_ID_LUMIGON, - VENDOR_ID_MOTOROLA, - VENDOR_ID_MSI, - VENDOR_ID_MTK, - VENDOR_ID_NEC, - VENDOR_ID_NOOK, - VENDOR_ID_NVIDIA, - VENDOR_ID_OPPO, - VENDOR_ID_OTGV, - VENDOR_ID_OUYA, - VENDOR_ID_PANTECH, - VENDOR_ID_PEGATRON, - VENDOR_ID_PHILIPS, - VENDOR_ID_PMC, - VENDOR_ID_POSITIVO, - VENDOR_ID_PRESTIGIO, - VENDOR_ID_QISDA, - VENDOR_ID_QUALCOMM, - VENDOR_ID_QUANTA, - VENDOR_ID_ROCKCHIP, - VENDOR_ID_SAMSUNG, - VENDOR_ID_SHARP, - VENDOR_ID_SK_TELESYS, - VENDOR_ID_SMARTISAN, - VENDOR_ID_SONY, - VENDOR_ID_SONY_ERICSSON, - VENDOR_ID_T_AND_A, - VENDOR_ID_TECHFAITH, - VENDOR_ID_TELEEPOCH, - VENDOR_ID_TI, - VENDOR_ID_TOSHIBA, - VENDOR_ID_UNOWHY, - VENDOR_ID_VIZIO, - VENDOR_ID_WACOM, - VENDOR_ID_XIAOMI, - VENDOR_ID_YOTADEVICES, - VENDOR_ID_YULONG_COOLPAD, - VENDOR_ID_ZTE, -}; -/* Keep the list above sorted alphabetically */ - -#define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0])) - -/* max number of supported vendor ids (built-in + 3rd party). increase as needed */ -#define VENDOR_COUNT_MAX 128 - -int vendorIds[VENDOR_COUNT_MAX]; -unsigned vendorIdCount = 0; - -int get_adb_usb_ini(char* buff, size_t len); - -void usb_vendors_init(void) -{ - if (VENDOR_COUNT_MAX < BUILT_IN_VENDOR_COUNT) { - fprintf(stderr, "VENDOR_COUNT_MAX not big enough for built-in vendor list.\n"); - exit(2); - } - - /* add the built-in vendors at the beginning of the array */ - memcpy(vendorIds, builtInVendorIds, sizeof(builtInVendorIds)); - - /* default array size is the number of built-in vendors */ - vendorIdCount = BUILT_IN_VENDOR_COUNT; - - if (VENDOR_COUNT_MAX == BUILT_IN_VENDOR_COUNT) - return; - - char temp[PATH_MAX]; - if (get_adb_usb_ini(temp, sizeof(temp)) == 0) { - FILE * f = fopen(temp, "rt"); - - if (f != NULL) { - /* The vendor id file is pretty basic. 1 vendor id per line. - Lines starting with # are comments */ - while (fgets(temp, sizeof(temp), f) != NULL) { - if (temp[0] == '#') - continue; - - long value = strtol(temp, NULL, 0); - if (errno == EINVAL || errno == ERANGE || value > INT_MAX || value < 0) { - fprintf(stderr, "Invalid content in %s. Quitting.\n", ANDROID_ADB_INI); - exit(2); - } - - vendorIds[vendorIdCount++] = (int)value; - - /* make sure we don't go beyond the array */ - if (vendorIdCount == VENDOR_COUNT_MAX) { - break; - } - } - fclose(f); - } - } -} - -/* Utils methods */ - -/* builds the path to the adb vendor id file. returns 0 if success */ -int build_path(char* buff, size_t len, const char* format, const char* home) -{ - if (snprintf(buff, len, format, home, ANDROID_PATH, ANDROID_ADB_INI) >= (signed)len) { - return 1; - } - - return 0; -} - -/* fills buff with the path to the adb vendor id file. returns 0 if success */ -int get_adb_usb_ini(char* buff, size_t len) -{ -#ifdef _WIN32 - const char* home = getenv("ANDROID_SDK_HOME"); - if (home != NULL) { - return build_path(buff, len, "%s\\%s\\%s", home); - } else { - char path[MAX_PATH]; - SHGetFolderPath( NULL, CSIDL_PROFILE, NULL, 0, path); - return build_path(buff, len, "%s\\%s\\%s", path); - } -#else - const char* home = getenv("HOME"); - if (home == NULL) - home = "/tmp"; - - return build_path(buff, len, "%s/%s/%s", home); -#endif -} diff --git a/adb/usb_vendors.h b/adb/usb_vendors.h deleted file mode 100644 index cee23a15..00000000 --- a/adb/usb_vendors.h +++ /dev/null @@ -1,25 +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. - */ - -#ifndef __USB_VENDORS_H -#define __USB_VENDORS_H - -extern int vendorIds[]; -extern unsigned vendorIdCount; - -void usb_vendors_init(void); - -#endif From 5b56f46bb22ee173b1065dff7e14c21f311f92f5 Mon Sep 17 00:00:00 2001 From: William Roberts Date: Wed, 3 Jul 2013 14:38:32 -0700 Subject: [PATCH 115/243] Add SIGHUP Handler to rotate log files Sending SIGHUP to auditd will now cuase a log file rotation to occur. Signed-off-by: William Roberts --- auditd/auditd.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/auditd/auditd.c b/auditd/auditd.c index 875ae646..d8b4c9e5 100644 --- a/auditd/auditd.c +++ b/auditd/auditd.c @@ -64,6 +64,8 @@ static volatile int quit = 0; +static audit_log *alog = NULL; + static void signal_handler(int sig) { switch (sig) { @@ -71,6 +73,9 @@ static void signal_handler(int sig) case SIGTERM: quit = 1; break; + case SIGHUP: + audit_log_rotate(alog); + break; } return; } @@ -135,7 +140,6 @@ int main(int argc, char *argv[]) struct pollfd pfds; struct audit_reply rep; struct sigaction action; - audit_log *l = NULL; SLOGI("Starting up"); @@ -146,6 +150,7 @@ int main(int argc, char *argv[]) sigemptyset(&action.sa_mask); action.sa_flags = 0; rc = sigaction(SIGINT, &action, NULL); + rc |= sigaction(SIGHUP, &action, NULL); if (rc < 0) { rc = errno; SLOGE("Failed on set signal handler: %s", strerror(errno)); @@ -171,8 +176,8 @@ int main(int argc, char *argv[]) goto err; } - l = audit_log_open(AUDITD_LOG_FILE, AUDITD_OLD_LOG_FILE, AUDITD_MAX_LOG_FILE_SIZE); - if (!l) { + alog = audit_log_open(AUDITD_LOG_FILE, AUDITD_OLD_LOG_FILE, AUDITD_MAX_LOG_FILE_SIZE); + if (!alog) { SLOGE("Failed on audit_log_open"); goto err; } @@ -187,7 +192,7 @@ int main(int argc, char *argv[]) pfds.events = POLLIN; if (check_kernel_log) { - audit_log_put_kmsg(l); + audit_log_put_kmsg(alog); } while (!quit) { @@ -208,7 +213,7 @@ int main(int argc, char *argv[]) continue; } - audit_log_write(l, "type=%d msg=%.*s\n", rep.type, rep.len, rep.msg.data); + audit_log_write(alog, "type=%d msg=%.*s\n", rep.type, rep.len, rep.msg.data); /* Keep reading for events */ } @@ -218,6 +223,6 @@ int main(int argc, char *argv[]) audit_set_pid(audit_fd, 0, WAIT_NO); audit_close(audit_fd); } - audit_log_close(l); + audit_log_close(alog); return rc; } From 076b0c8add030d37f8393645dac9935057d2f674 Mon Sep 17 00:00:00 2001 From: Joshua Brindle Date: Fri, 6 Sep 2013 15:48:30 -0400 Subject: [PATCH 116/243] Add audit watch rule support and bugfixes Add libaudit support for adding directory watch rules. Add rule parsing support to auditd. Rule format matches auditctl. Currently only supports -w and -e. Fields supported are uid, euid, suid, fsuid, loginuid, gid, egid, sgid, fsgid and success. Fields allow further limiting of matches, for example: -w /system -pwa -F uid!=system -F success=1 will match a write on /system that was successful and done by a uid other than system Retry on EAGAIN from recvfrom on the audit netlink socket. Always enable audit syscall functionality on start of auditd. Signed-off-by: Joshua Brindle Change-Id: I74a94dbffde835a27539559427f22b73a4c7ea24 Conflicts: auditd/README Conflicts: auditd/README --- auditd/Android.mk | 4 +- auditd/README | 17 +++- auditd/audit_rules.c | 213 +++++++++++++++++++++++++++++++++++++++++++ auditd/audit_rules.h | 24 +++++ auditd/auditd.c | 13 +++ auditd/fields.c | 91 ++++++++++++++++++ auditd/fields.h | 2 + auditd/fieldtab.h | 33 +++++++ auditd/libaudit.c | 169 ++++++++++++++++++++++++++++++++-- auditd/libaudit.h | 68 ++++++++++++++ 10 files changed, 626 insertions(+), 8 deletions(-) create mode 100644 auditd/audit_rules.c create mode 100644 auditd/audit_rules.h create mode 100644 auditd/fields.c create mode 100644 auditd/fields.h create mode 100644 auditd/fieldtab.h diff --git a/auditd/Android.mk b/auditd/Android.mk index c29319a6..91d592bb 100644 --- a/auditd/Android.mk +++ b/auditd/Android.mk @@ -11,7 +11,9 @@ AUDITD_MAX_LOG_FILE_SIZEKB ?= 100 LOCAL_SRC_FILES:= \ auditd.c \ libaudit.c \ - audit_log.c + audit_log.c \ + audit_rules.c \ + fields.c LOCAL_SHARED_LIBRARIES := \ libcutils \ diff --git a/auditd/README b/auditd/README index 9d14c0de..a29363cf 100644 --- a/auditd/README +++ b/auditd/README @@ -41,4 +41,19 @@ AUDITD_MAX_LOG_FILE_SIZEKB := 1000 PRODUCT_PACKAGES += auditd - +Rules + +Limited support for loading rules is present in auditd. +Put an audit.rules file in /data/misc/audit/ and it will be read +when auditd is run. Only enable (-e) and watch (-w) rules are +currently supported. For watch files fields that are supported are: +uid, euid, suid, fsuid, loginuid, gid, egid, sgid, fsgid and success. + +An example audit.rules may look like: + +# Audit successful writes to /system not done by the system UID +-w /system -pwa -F success=1 -F uid!=system +# Audit write attempts (successful or not) to /dev/block by anyone +-w /dev/block -pwa +# Audit write attempts to /data/security not done by system UID +-w /data/security -pwa -F uid!=system diff --git a/auditd/audit_rules.c b/auditd/audit_rules.c new file mode 100644 index 00000000..768c3b93 --- /dev/null +++ b/auditd/audit_rules.c @@ -0,0 +1,213 @@ +/* + * Copyright 2013, Quark Security Inc + * + * 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. + * + * Written by Joshua Brindle + */ + +#include +#include +#include +#include +#include + +#define LOG_TAG "audit_rules" +#include + +#include "libaudit.h" +#include "fields.h" + +#define LINE_LEN 255 +#define OPERS "=><&!" + +static int string_to_oper(const char *s) +{ + if (strcmp(s, "=") == 0) { + return AUDIT_EQUAL; + } else if (strcmp(s, "!=") == 0) { + return AUDIT_NOT_EQUAL; + } else if (strcmp(s, ">=") == 0) { + return AUDIT_GREATER_THAN_OR_EQUAL; + } else if (strcmp(s, "<=") == 0) { + return AUDIT_LESS_THAN_OR_EQUAL; + } else if (strcmp(s, "<") == 0) { + return AUDIT_LESS_THAN; + } else if (strcmp(s, ">") == 0) { + return AUDIT_GREATER_THAN; + } else if (strcmp(s, "&=") == 0) { + return AUDIT_BIT_TEST; + } else if (strcmp(s, "&") == 0) { + return AUDIT_BIT_MASK; + } else { + return -1; + } +} + +static int audit_rules_parse_and_add(int audit_fd, char *line) +{ + char *argv[AUDIT_MAX_FIELDS]; + int argc; + int rc = 0; + int added_rule = 0; + char p; + int opt; + size_t len; + struct audit_rule_data *rule; + + /* Strip crlf */ + line[strlen(line) -1] = '\0'; + + argv[0] = "auditd"; + + for (argc=1; argc < AUDIT_MAX_FIELDS - 1; argc++) { + argv[argc] = strsep(&line, " \n\r"); + if (argv[argc] == NULL) { + break; + } + } + + optind = 0; + char *field; + char *oper; + size_t length; + int audit_field; + int oper_field; + int i; + + while ((opt = getopt(argc, argv, "w:e:p:F:")) != -1) { + switch(opt) { + case 'w': + if (audit_add_dir(&rule, optarg)) { + SLOGE("Error adding rule"); + return -1; + } + added_rule = 1; + break; + case 'e': + if (audit_set_enabled(audit_fd, strtoul(optarg, NULL, 10))) { + return -1; + } + break; + case 'F': + if (added_rule == 0) { + SLOGE("Specify rule type before permissions"); + return -1; + } + + length = strcspn(optarg, OPERS); + field = strndup(optarg, length); + if (field == NULL) { + SLOGE("Out of memory!"); + return -1; + } + audit_field = string_to_audit_field(field); + if (audit_field == 0) { + SLOGE("Invalid field: %s", field); + free(field); + return -1; + } + free(field); + + optarg = &optarg[length]; + length = strspn(optarg, OPERS); + oper = strndup(optarg, length); + oper_field = string_to_oper(oper); + if (oper_field == -1) { + SLOGE("Invalid operator: %s", oper); + free(oper); + return -1; + } + free(oper); + optarg = &optarg[length]; + if (audit_add_field(rule, audit_field, oper_field, optarg) < 0) { + SLOGE("Adding field failed"); + return -1; + } + break; + case 'p': + if (added_rule == 0) { + SLOGE("Specify rule type before permissions"); + return -1; + } + uint32_t perms = 0; + for (len=0; len < strlen(optarg); len++) { + switch(optarg[len]) { + case 'w': + perms |= AUDIT_PERM_WRITE; + break; + case 'e': + perms |= AUDIT_PERM_EXEC; + break; + case 'r': + perms |= AUDIT_PERM_READ; + break; + case 'a': + perms |= AUDIT_PERM_ATTR; + break; + default: + SLOGE("Unknown permission %c", optarg[len]); + break; + } + } + if (audit_update_watch_perms(rule, perms)) { + SLOGE("Could not set perms on rule"); + return -1; + } + break; + case '?': + SLOGE("Unsupported option: %c", optopt); + break; + } + } + + if (added_rule) { + rc = audit_send(audit_fd, AUDIT_ADD_RULE, rule, sizeof(*rule) + rule->buflen); + free(rule); + } + + return rc; +} + +int audit_rules_read_and_add(int audit_fd, const char *rulefile) +{ + int rc; + struct stat s; + char line[LINE_LEN]; + FILE *rules; + + rc = stat(rulefile, &s); + if (rc < 0) { + SLOGE("Could not read audit rules %s: %s", rulefile, strerror(errno)); + return 0; + } + + rules = fopen(rulefile, "r"); + if (rules == NULL) { + return -1; + } + + while (fgets(line, sizeof(line), rules)) { + SLOGE(line); + if (line[0] != '-') { + continue; + } + if (audit_rules_parse_and_add(audit_fd, line) < 0) { + SLOGE("Could not read audit rules"); + return -1; + } + } + + fclose(rules); + return 0; +} diff --git a/auditd/audit_rules.h b/auditd/audit_rules.h new file mode 100644 index 00000000..16a617ec --- /dev/null +++ b/auditd/audit_rules.h @@ -0,0 +1,24 @@ +/* + * Copyright 2013, Quark Security Inc + * + * 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. + * + * Written by Joshua Brindle + */ + +#ifndef _AUDIT_RULES_H_ +#define _AUDIT_RULES_H_ + +extern int audit_rules_read_and_add(int audit_fd, const char *rulefile); + +#endif diff --git a/auditd/auditd.c b/auditd/auditd.c index d8b4c9e5..013827c4 100644 --- a/auditd/auditd.c +++ b/auditd/auditd.c @@ -45,6 +45,7 @@ #include "libaudit.h" #include "audit_log.h" +#include "audit_rules.h" /* * TODO: @@ -60,6 +61,8 @@ #define AUDITD_LOG_FILE AUDITD_LOG_DIR "/audit.log" #define AUDITD_OLD_LOG_FILE AUDITD_LOG_DIR "/audit.old" +#define AUDITD_RULES_FILE "/data/misc/audit/audit.rules" + #define AUDITD_MAX_LOG_FILE_SIZE (1024 * AUDITD_MAX_LOG_FILE_SIZEKB) static volatile int quit = 0; @@ -188,6 +191,16 @@ int main(int argc, char *argv[]) goto err; } + if (audit_set_enabled(audit_fd, 1) < 0) { + rc = errno; + SLOGE("Failed on audit_set_enabled with error: %s", strerror(errno)); + goto err; + } + + if (audit_rules_read_and_add(audit_fd, AUDITD_RULES_FILE)) { + SLOGE("error reading audit rules: %s", strerror(errno)); + } + pfds.fd = audit_fd; pfds.events = POLLIN; diff --git a/auditd/fields.c b/auditd/fields.c new file mode 100644 index 00000000..75c571ae --- /dev/null +++ b/auditd/fields.c @@ -0,0 +1,91 @@ +/* + * Copyright 2013, Quark Security Inc + * + * 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. + * + * Written by Joshua Brindle + */ + +#include +#include +#include +#include +#include + +#define LOG_TAG "audit_fields" +#include + +#define L1(line) L2(line) +#define L2(line) str##line +static const union audit_to_string_data { + struct { +#define S_(v, s) char L1(__LINE__)[sizeof(s)]; +#include "fieldtab.h" +#undef S_ + }; + char str[0]; +} audit_to_string_data = { + { +#define S_(v, s) s, +#include "fieldtab.h" +#undef S_ + } +}; +static const int audit_to_string[] = { +#define S_(v, s) offsetof(union audit_to_string_data, L1(__LINE__)), +#include "fieldtab.h" +#undef S_ +}; + +static const int audit_map[] = { +#define S_(v, s) v, +#include "fieldtab.h" +#undef S_ +}; + +#define FIELDS (sizeof(audit_to_string) / sizeof(audit_to_string[0])) + +int string_to_audit_field(const char *s) +{ + unsigned int val; + + if (isdigit(s[0])) { + val = atoi(s); + if (val > 0 && val < FIELDS) { + return audit_map[val]; + } + } else { + for (val = 0; val < FIELDS; val++) { + if (strcmp(s, (audit_to_string_data.str + + audit_to_string[val])) == 0) { + return audit_map[val]; + } + } + } + + errno = EINVAL; + return 0; +} + +const char* audit_field_to_string(int field) +{ + unsigned int i; + for (i=0; i < FIELDS; i++) { + if (audit_map[i] == field) { + return audit_to_string_data.str + audit_to_string[i]; + } + } + + errno = EINVAL; + return NULL; +} diff --git a/auditd/fields.h b/auditd/fields.h new file mode 100644 index 00000000..3886d138 --- /dev/null +++ b/auditd/fields.h @@ -0,0 +1,2 @@ +extern int string_to_audit_field(const char *s); +extern const char* audit_field_to_string(int i); diff --git a/auditd/fieldtab.h b/auditd/fieldtab.h new file mode 100644 index 00000000..f7decb44 --- /dev/null +++ b/auditd/fieldtab.h @@ -0,0 +1,33 @@ +S_(AUDIT_PID, "pid") +S_(AUDIT_UID, "uid") +S_(AUDIT_EUID, "euid") +S_(AUDIT_SUID, "suid") +S_(AUDIT_FSUID, "fsuid") +S_(AUDIT_GID, "gid") +S_(AUDIT_EGID, "egid") +S_(AUDIT_SGID, "sgid") +S_(AUDIT_FSGID, "fsgid") +S_(AUDIT_LOGINUID, "auid") +S_(AUDIT_PERS, "pers") +S_(AUDIT_ARCH, "arch") +S_(AUDIT_MSGTYPE, "msgtype") +S_(AUDIT_SUBJ_USER, "subj_user") +S_(AUDIT_SUBJ_ROLE, "subj_role") +S_(AUDIT_SUBJ_TYPE, "subj_type") +S_(AUDIT_SUBJ_SEN, "subj_sen") +S_(AUDIT_SUBJ_CLR, "subj_clr") +S_(AUDIT_PPID, "ppid") +S_(AUDIT_OBJ_USER, "obj_user") +S_(AUDIT_OBJ_ROLE, "obj_role") +S_(AUDIT_OBJ_TYPE, "obj_type") +S_(AUDIT_OBJ_LEV_LOW, "obj_lev_low") +S_(AUDIT_OBJ_LEV_HIGH, "obj_lev_high") +S_(AUDIT_DEVMAJOR, "devmajor") +S_(AUDIT_DEVMINOR, "devminor") +S_(AUDIT_INODE, "inode") +S_(AUDIT_EXIT, "exit") +S_(AUDIT_SUCCESS, "success") +S_(AUDIT_WATCH, "path") +S_(AUDIT_PERM, "perm") +S_(AUDIT_DIR, "dir") +S_(AUDIT_FILETYPE, "filetype") diff --git a/auditd/libaudit.c b/auditd/libaudit.c index 06e55570..d65b6199 100644 --- a/auditd/libaudit.c +++ b/auditd/libaudit.c @@ -22,12 +22,18 @@ #include #include #include +#include +#include +#include +#include +#include #define LOG_TAG "libaudit" #include #include #include "libaudit.h" +#include "fields.h" /** * Copies the netlink message data to the reply structure. @@ -137,7 +143,7 @@ static int get_ack(int fd, int16_t seq) * @return * This function returns a positive sequence number on success, else -errno. */ -static int audit_send(int fd, int type, const void *data, unsigned int size) +int audit_send(int fd, int type, const void *data, unsigned int size) { int rc; static int16_t sequence = 0; @@ -220,6 +226,154 @@ static int audit_send(int fd, int type, const void *data, unsigned int size) return rc; } +int audit_update_watch_perms(struct audit_rule_data *rule, int perms) +{ + uint32_t i; + + if (rule == NULL) { + return -EINVAL; + } + + for (i = 0; i < rule->field_count; i++) { + if (rule->fields[i] == AUDIT_PERM) { + rule->values[i] = perms; + break; + } + } + + if (rule->fields[i] == AUDIT_PERM) { + return 0; + } + + if (rule->field_count > AUDIT_MAX_FIELDS - 1) { + return -2; + } + + rule->fields[rule->field_count] = AUDIT_PERM; + rule->fieldflags[rule->field_count] = AUDIT_EQUAL; + rule->values[rule->field_count] = perms; + rule->field_count++; + + return 0; +} + +int audit_add_field(struct audit_rule_data *rule, int field, int oper, char *value) +{ + int i; + struct passwd *pw; + struct group *gr; + + if (rule == NULL) { + return -EINVAL; + } + + if (rule->field_count > AUDIT_MAX_FIELDS - 1) { + return -2; + } + + rule->fields[rule->field_count] = field; + rule->fieldflags[rule->field_count] = oper; + + switch(field) { + case AUDIT_UID: + case AUDIT_EUID: + case AUDIT_SUID: + case AUDIT_FSUID: + case AUDIT_LOGINUID: + if (isdigit(value[0])) { + rule->values[rule->field_count] = strtoul(value, NULL, 0); + } else { + pw = getpwnam(value); + if (pw == NULL) { + SLOGE("Unknown user %s", value); + return -1; + } + rule->values[rule->field_count] = pw->pw_uid; + } + break; + case AUDIT_GID: + case AUDIT_EGID: + case AUDIT_SGID: + case AUDIT_FSGID: + if (isdigit(value[0])) { + rule->values[rule->field_count] = strtoul(value, NULL, 0); + } else { + gr = getgrnam(value); + if (gr == NULL) { + SLOGE("Unknown group %s", value); + return -1; + } + rule->values[rule->field_count] = gr->gr_gid; + } + break; + case AUDIT_SUCCESS: + // According to the auditctl man page success should only have 0 or 1 + if (strcmp(value, "0") == 0 || strcmp(value, "1") == 0) { + rule->values[rule->field_count] = strtoul(value, NULL, 0); + } else { + SLOGE("Invalid value %s for success field", value); + return -1; + } + break; + default: + SLOGE("Unsupported field: %s", audit_field_to_string(field)); + return -1; + } + + rule->field_count++; + return 0; +} + +int audit_add_dir(struct audit_rule_data **rulep, const char *path) +{ + int len = strlen(path); + struct audit_rule_data *rule; + + if (rulep == NULL) { + return -EINVAL; + } + *rulep = calloc(1, sizeof(*rule) + len); + rule = *rulep; + if (!rule) { + SLOGE("Out of memory"); + return -1; + } + + rule->flags = AUDIT_FILTER_EXIT; + rule->action = AUDIT_ALWAYS; + rule->field_count = 2; + + rule->mask[0] = ~0; + rule->fields[0] = AUDIT_DIR; + rule->fieldflags[0] = AUDIT_EQUAL; + rule->values[0] = len; + + rule->mask[1] = ~0; + rule->fields[1] = AUDIT_PERM; + rule->fieldflags[1] = AUDIT_EQUAL; + rule->values[1] = AUDIT_PERM_READ | AUDIT_PERM_WRITE | + AUDIT_PERM_EXEC | AUDIT_PERM_ATTR; + + rule->buflen = len; + memcpy(&rule->buf[0], path, len); + + return 0; +} + +int audit_set_enabled(int fd, uint32_t state) +{ + if (state > AUDIT_LOCKED) { + return -1; + } + + struct audit_status s; + memset(&s, 0, sizeof(s)); + s.mask = AUDIT_STATUS_ENABLED; + s.enabled = state; + + return audit_send(fd, AUDIT_SET, &s, sizeof(s)); +} + int audit_set_pid(int fd, uint32_t pid, rep_wait_t wmode) { int rc; @@ -296,12 +450,15 @@ int audit_get_reply(int fd, struct audit_reply *rep, reply_t block, int peek) * another error manifests. */ if (len < 0 && errno != EINTR) { - if (block == GET_REPLY_NONBLOCKING && errno == EAGAIN) { - /* If the request is non blocking and the errno is EAGAIN, just return 0 */ - return 0; + if (errno == EAGAIN) { + if (block == GET_REPLY_NONBLOCKING) { + /* If the request is non blocking and the errno is EAGAIN, just return 0 */ + return 0; + } + } else { + SLOGE("Error receiving from netlink socket, error: %s", strerror(errno)); + return -errno; } - SLOGE("Error receiving from netlink socket, error: %s", strerror(errno)); - return -errno; } /* 0 or greater indicates success */ diff --git a/auditd/libaudit.h b/auditd/libaudit.h index fbaa7b96..ffe6b0f1 100644 --- a/auditd/libaudit.h +++ b/auditd/libaudit.h @@ -27,6 +27,10 @@ #define MAX_AUDIT_MESSAGE_LENGTH 8970 +#define AUDIT_OFF 0 +#define AUDIT_ON 1 +#define AUDIT_LOCKED 2 + typedef enum { GET_REPLY_BLOCKING=0, GET_REPLY_NONBLOCKING @@ -108,4 +112,68 @@ extern int audit_get_reply(int fd, struct audit_reply *rep, reply_t block, */ extern int audit_set_pid(int fd, uint32_t pid, rep_wait_t wmode); +/** + * Sends a command to the audit netlink socket + * @param fd + * The fd returned by a call to audit_open() + * @param type + * message type, see audit.h in the kernel + * @param data + * opaque data pointer + * @param size + * size of data in *data + * @return + * This function returns 0 on success, -errno on error. + */ +extern int audit_send(int fd, int type, const void *data, unsigned int size); + +/** + * Allocates a rule and adds a directory to watch, defaults to all permissions. + * Call audit_update_watch_perms() subsequently to update permissions. + * @param rulep + * double pointer to an unallocated audit_rule_data, which will be allocated. This must be freed + * @param path + * path to add to the rule + * @return + * This function returns 0 on success, -errno on error. + */ +extern int audit_add_dir(struct audit_rule_data **rulep, const char *path); + +/** + * Sets enabled flag, 0 for audit off, 1 for audit on, 2 for audit locked + * @param fd + * file descripter returned by audit_open() + * @param state + * 0 for audit off, 1 for audit on, 2 for audit locked + * @return + * This function returns 0 on success, -errno on error, -1 if already locked + */ +extern int audit_set_enabled(int fd, uint32_t state); + +/** + * Sets permissions for an already allocated watch rule + * @param rule + * rule to set permissions on + * @param perms + * permissions to set, AUDIT_PERM_{READ,WRITE,EXEC,ATTR} + * @return + * This function returns 0 on success, -1 if rule is NULL and -2 if there are too many fields + */ +extern int audit_update_watch_perms(struct audit_rule_data *rule, int perms); + +/** + * Sets permissions for an already allocated watch rule + * @param rule + * rule to add field to + * @param field + * field from audit.h AUDIT_PID...AUDIT_FILETYPE + * @param oper + * operator from audit.h AUDIT_EQUAL|AUDIT_NOT_EQUAL|AUDIT_BIT_MASK + * @param value + * value to match for the field (e.g., uid=1000, 1000 is the value) + * @return + * This function returns 0 on success, -1 if rule is NULL and -2 if there are too many fields + */ +extern int audit_add_field(struct audit_rule_data *rule, int field, int oper, char *value); + #endif From 827a9617988770713a3255951112473e6d3f9950 Mon Sep 17 00:00:00 2001 From: Stephen Smalley Date: Thu, 14 Nov 2013 10:45:09 -0500 Subject: [PATCH 117/243] Add sample audit.rules file. To use: adb push audit.rules /data/misc/audit adb reboot --- auditd/audit.rules | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 auditd/audit.rules diff --git a/auditd/audit.rules b/auditd/audit.rules new file mode 100644 index 00000000..2b217aec --- /dev/null +++ b/auditd/audit.rules @@ -0,0 +1,4 @@ +-w /dev/block -pwa -F success=1 -F uid!=system +-w /system -pwa -F success=1 +-w /data/security -pwa -F success=1 -F uid!=system +-w /data/misc/audit -pwa -F success=1 -F uid!=audit From 3cdd37fdffe862a3516fab781fd2ae5ea5d6a505 Mon Sep 17 00:00:00 2001 From: "Christopher R. Palmer" Date: Wed, 3 Dec 2014 16:48:04 -0500 Subject: [PATCH 118/243] init: Make restorecon_recursive work for /data/ In the following commit: commit f2b7ee765516c84a9995e3acdc8fbcd7dc1b33cc Author: Stephen Smalley Date: Thu Feb 6 13:52:52 2014 -0500 Apply restorecon_recursive to all of /data. they removed all the adhoc restorecon_recursive of subdirectories of /data/ and replaced it with: # Set SELinux security contexts on upgrade or policy update. restorecon_recursive /data Unfortunately, that is a no-op because restorecon doesn't recurse through /data/ unless you add a FORCE flag. Since the expectation seems to be that the recursive restorecon in init will actually work, update the built-in to add the force flag and a flag to allow /data/data to also be recursed through. [RC: Removed the DATADATA flag. It throws a ton of errors, and it's supposed to be handled by seapp_contexts, not file_contexts. The actual root paths, however, now get their individual restorecon calls so that installd can deal with them] Change-Id: I435c505188e924b27ef2e6a2e0ee0a6951e43f0e --- init/util.c | 6 +++++- rootdir/init.rc | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/init/util.c b/init/util.c index e1a3ee33..4af4b4f4 100644 --- a/init/util.c +++ b/init/util.c @@ -530,7 +530,11 @@ int restorecon(const char* pathname) return selinux_android_restorecon(pathname, 0); } +#define RESTORECON_RECURSIVE_FLAGS \ + (SELINUX_ANDROID_RESTORECON_FORCE | \ + SELINUX_ANDROID_RESTORECON_RECURSE) + int restorecon_recursive(const char* pathname) { - return selinux_android_restorecon(pathname, SELINUX_ANDROID_RESTORECON_RECURSE); + return selinux_android_restorecon(pathname, RESTORECON_RECURSIVE_FLAGS); } diff --git a/rootdir/init.rc b/rootdir/init.rc index afcdde31..b0f4bc78 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -324,6 +324,9 @@ on post-fs-data # Set SELinux security contexts on upgrade or policy update. restorecon_recursive /data + restorecon /data/data + restorecon /data/user + restorecon /data/user/0 # If there is no fs-post-data action in the init..rc file, you # must uncomment this line, otherwise encrypted filesystems From 41c64964ed867d76ec1063a8cc28a1f7c0fd7393 Mon Sep 17 00:00:00 2001 From: Narsinga Rao Chella Date: Sat, 15 Nov 2014 15:48:48 -0800 Subject: [PATCH 119/243] system: Support for offloading Java audio tracks Offload Java audio tracks if the property is set. This is used to avoid mixing in audioflinger and to apply effects in DSP. Also update function to calculate bytes per sample for offload format. Change-Id: I0705e70a806a335e372e844de8a1210fbfe58cd7 --- include/system/audio.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/system/audio.h b/include/system/audio.h index 876e0af9..5e46a306 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -863,7 +863,9 @@ static const audio_offload_info_t AUDIO_INFO_INITIALIZER = { bit_rate: 0, duration_us: 0, has_video: false, - is_streaming: false + is_streaming: false, + bit_width: 16, + use_small_bufs: false, }; /* common audio stream configuration parameters @@ -1505,6 +1507,7 @@ static inline size_t audio_bytes_per_sample(audio_format_t format) size = sizeof(uint8_t) * 3; break; case AUDIO_FORMAT_PCM_16_BIT: + case AUDIO_FORMAT_PCM_16_BIT_OFFLOAD: size = sizeof(int16_t); break; case AUDIO_FORMAT_PCM_8_BIT: From 7d56df60c851d7befa60dfc4207343c5af2eef52 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Wed, 19 Nov 2014 13:33:22 -0800 Subject: [PATCH 120/243] logd: throttle SELinux denials to 20/sec Impose a limit of 20 selinux denials per second. Denials beyond that point don't add any value, and have the potential to cause crashes or denial of service attacks. Do some other misc cleanup while I'm here. Bug: 18341932 Change-Id: I6125d629ae4d6ae131d2e53bfa41e1f50277d402 --- logd/LogAudit.cpp | 2 +- logd/libaudit.c | 24 +++++++++++------------- logd/libaudit.h | 9 +-------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp index f8d61621..179c3b28 100644 --- a/logd/LogAudit.cpp +++ b/logd/LogAudit.cpp @@ -234,7 +234,7 @@ int LogAudit::getLogSocket() { if (fd < 0) { return fd; } - if (audit_set_pid(fd, getpid(), WAIT_YES) < 0) { + if (audit_setup(fd, getpid()) < 0) { audit_close(fd); fd = -1; } diff --git a/logd/libaudit.c b/logd/libaudit.c index ca88d1b2..d00d5795 100644 --- a/logd/libaudit.c +++ b/logd/libaudit.c @@ -162,7 +162,7 @@ static int audit_send(int fd, int type, const void *data, size_t size) return rc; } -int audit_set_pid(int fd, uint32_t pid, rep_wait_t wmode) +int audit_setup(int fd, uint32_t pid) { int rc; struct audit_message rep; @@ -176,7 +176,8 @@ int audit_set_pid(int fd, uint32_t pid, rep_wait_t wmode) * and the the mask set to AUDIT_STATUS_PID */ status.pid = pid; - status.mask = AUDIT_STATUS_PID; + status.mask = AUDIT_STATUS_PID | AUDIT_STATUS_RATE_LIMIT; + status.rate_limit = 20; // audit entries per second /* Let the kernel know this pid will be registering for audit events */ rc = audit_send(fd, AUDIT_SET, &status, sizeof(status)); @@ -188,24 +189,21 @@ int audit_set_pid(int fd, uint32_t pid, rep_wait_t wmode) /* * In a request where we need to wait for a response, wait for the message * and discard it. This message confirms and sync's us with the kernel. - * This daemon is now registered as the audit logger. Only wait if the - * wmode is != WAIT_NO + * This daemon is now registered as the audit logger. + * + * TODO + * If the daemon dies and restarts the message didn't come back, + * so I went to non-blocking and it seemed to fix the bug. + * Need to investigate further. */ - if (wmode != WAIT_NO) { - /* TODO - * If the daemon dies and restarts the message didn't come back, - * so I went to non-blocking and it seemed to fix the bug. - * Need to investigate further. - */ - audit_get_reply(fd, &rep, GET_REPLY_NONBLOCKING, 0); - } + audit_get_reply(fd, &rep, GET_REPLY_NONBLOCKING, 0); return 0; } int audit_open() { - return socket(PF_NETLINK, SOCK_RAW, NETLINK_AUDIT); + return socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_AUDIT); } int audit_get_reply(int fd, struct audit_message *rep, reply_t block, int peek) diff --git a/logd/libaudit.h b/logd/libaudit.h index cb114f91..b9e330d9 100644 --- a/logd/libaudit.h +++ b/logd/libaudit.h @@ -37,11 +37,6 @@ typedef enum { GET_REPLY_NONBLOCKING } reply_t; -typedef enum { - WAIT_NO, - WAIT_YES -} rep_wait_t; - /* type == AUDIT_SIGNAL_INFO */ struct audit_sig_info { uid_t uid; @@ -92,12 +87,10 @@ extern int audit_get_reply(int fd, struct audit_message *rep, reply_t block, * The fd returned by a call to audit_open() * @param pid * The pid whom to set as the reciever of audit messages - * @param wmode - * Whether or not to block on the underlying socket io calls. * @return * This function returns 0 on success, -errno on error. */ -extern int audit_set_pid(int fd, uint32_t pid, rep_wait_t wmode); +extern int audit_setup(int fd, uint32_t pid); __END_DECLS From 021ef494df48835c61a8e709df53eb9b3ab0236c Mon Sep 17 00:00:00 2001 From: Ramakrishnan Ganesh Date: Fri, 15 Nov 2013 16:40:49 -0800 Subject: [PATCH 121/243] healthd: Reinitialize mChargerNames for every battery update Booting up the device without the usb sets the usb power supply type as UNKNOWN. Due to this mChargerNames gets incorrectly initialized at bootup. The value of usb power supply type changes at run-time. So it makes sense to update mChargerNames everytime we have a battery related update. Change-Id: I2ec9f9a420ca61814d43c316b418ce94de3691bc --- healthd/BatteryMonitor.cpp | 79 ++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 25 deletions(-) diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index ccee10d5..651a7d41 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -210,35 +210,64 @@ bool BatteryMonitor::update(void) { if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0) props.batteryTechnology = String8(buf); - unsigned int i; + // reinitialize the mChargerNames vector everytime there is an update + String8 path; + DIR* dir = opendir(POWER_SUPPLY_SYSFS_PATH); + if (dir == NULL) { + KLOG_ERROR(LOG_TAG, "Could not open %s\n", POWER_SUPPLY_SYSFS_PATH); + } else { + struct dirent* entry; + // reconstruct the charger strings + mChargerNames.clear(); + while ((entry = readdir(dir))) { + const char* name = entry->d_name; - for (i = 0; i < mChargerNames.size(); i++) { - String8 path; - path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, - mChargerNames[i].string()); + if (!strcmp(name, ".") || !strcmp(name, "..")) + continue; - if (readFromFile(path, buf, SIZE) > 0) { - if (buf[0] != '0') { + // Look for "type" file in each subdirectory + path.clear(); + path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name); + switch(readPowerSupplyType(path)) { + case ANDROID_POWER_SUPPLY_TYPE_AC: + case ANDROID_POWER_SUPPLY_TYPE_USB: + case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: path.clear(); - path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, - mChargerNames[i].string()); - switch(readPowerSupplyType(path)) { - case ANDROID_POWER_SUPPLY_TYPE_AC: - props.chargerAcOnline = true; - break; - case ANDROID_POWER_SUPPLY_TYPE_USB: - props.chargerUsbOnline = true; - break; - case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: - props.chargerWirelessOnline = true; - break; - default: - KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", - mChargerNames[i].string()); + path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name); + if (access(path.string(), R_OK) == 0) { + mChargerNames.add(String8(name)); + if (readFromFile(path, buf, SIZE) > 0) { + if (buf[0] != '0') { + path.clear(); + path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, + name); + switch(readPowerSupplyType(path)) { + case ANDROID_POWER_SUPPLY_TYPE_AC: + props.chargerAcOnline = true; + break; + case ANDROID_POWER_SUPPLY_TYPE_USB: + props.chargerUsbOnline = true; + break; + case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: + props.chargerWirelessOnline = true; + break; + default: + KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", + name); + } + } + } } - } - } - } + break; + case ANDROID_POWER_SUPPLY_TYPE_BATTERY: + break; + default: + KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", + name); + } //switch + } //while + closedir(dir); + }//else logthis = !healthd_board_battery_update(&props); From 72f04fc1258c4bc030b7c9a1dbd2cc03253a0e9a Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Fri, 12 Dec 2014 23:56:59 -0800 Subject: [PATCH 122/243] audio: Add 24-bit offload format to audio_bytes_per_sample Change-Id: I238f302beadf8ba7705ffcb70639fb32be4ff2c4 --- include/system/audio.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/system/audio.h b/include/system/audio.h index 5e46a306..fe0b01e9 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -1501,6 +1501,7 @@ static inline size_t audio_bytes_per_sample(audio_format_t format) switch (format) { case AUDIO_FORMAT_PCM_32_BIT: case AUDIO_FORMAT_PCM_8_24_BIT: + case AUDIO_FORMAT_PCM_24_BIT_OFFLOAD: size = sizeof(int32_t); break; case AUDIO_FORMAT_PCM_24_BIT_PACKED: From b8a3b73be9edb54532faba28d1bd46d9cf085604 Mon Sep 17 00:00:00 2001 From: sbrissen Date: Tue, 16 Dec 2014 08:35:50 -0500 Subject: [PATCH 123/243] Healthd: charger: allow override of LED/BACKLIGHT paths Change-Id: Ib7372e441d554e16ffc20ce43993ee78cdc5b187 --- healthd/Android.mk | 12 ++++++++++++ healthd/healthd_mode_charger.cpp | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/healthd/Android.mk b/healthd/Android.mk index 5049886f..0dac01d9 100644 --- a/healthd/Android.mk +++ b/healthd/Android.mk @@ -27,6 +27,18 @@ LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_SBIN_UNSTRIPPED) LOCAL_CFLAGS := -D__STDC_LIMIT_MACROS -Werror +HEALTHD_CHARGER_DEFINES := RED_LED_PATH \ + GREEN_LED_PATH \ + BLUE_LED_PATH \ + BACKLIGHT_PATH \ + CHARGING_ENABLED_PATH + +$(foreach healthd_charger_define,$(HEALTHD_CHARGER_DEFINES), \ + $(if $($(healthd_charger_define)), \ + $(eval LOCAL_CFLAGS += -D$(healthd_charger_define)=\"$($(healthd_charger_define))\") \ + ) \ +) + ifeq ($(strip $(BOARD_CHARGER_DISABLE_INIT_BLANK)),true) LOCAL_CFLAGS += -DCHARGER_DISABLE_INIT_BLANK endif diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 9be16279..8e940833 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -73,11 +73,21 @@ char *locale; #define LAST_KMSG_PATH "/proc/last_kmsg" #define LAST_KMSG_PSTORE_PATH "/sys/fs/pstore/console-ramoops" #define LAST_KMSG_MAX_SZ (32 * 1024) +#ifndef RED_LED_PATH #define RED_LED_PATH "/sys/class/leds/red/brightness" +#endif +#ifndef GREEN_LED_PATH #define GREEN_LED_PATH "/sys/class/leds/green/brightness" +#endif +#ifndef BLUE_LED_PATH #define BLUE_LED_PATH "/sys/class/leds/blue/brightness" +#endif +#ifndef BACKLIGHT_PATH #define BACKLIGHT_PATH "/sys/class/leds/lcd-backlight/brightness" +#endif +#ifndef CHARGING_ENABLED_PATH #define CHARGING_ENABLED_PATH "/sys/class/power_supply/battery/charging_enabled" +#endif #define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0) #define LOGI(x...) do { KLOG_INFO("charger", x); } while (0) From 403b632e657ed67fedeea1d1b4537e56ca85216f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Burtin?= Date: Sun, 5 Feb 2012 00:55:17 +0100 Subject: [PATCH 124/243] set /system/etc/init.d/* permissions ported from CM7 Change-Id: I279d78679f7d779d6cd6bbc6c834d94706937ae8 --- include/private/android_filesystem_config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index 21458c7e..c51a5ae3 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -291,6 +291,7 @@ static const struct fs_path_config android_files[] = { { 00750, AID_ROOT, AID_SHELL, 0, "init*" }, { 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" }, { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" }, + { 00755, AID_ROOT, AID_SHELL, 0, "system/etc/init.d/*" }, { 00644, AID_ROOT, AID_ROOT, 0, 0 }, }; From f4e12b9f1dcd53108c65dbd79248aee573d80920 Mon Sep 17 00:00:00 2001 From: myfluxi Date: Wed, 17 Dec 2014 19:15:19 +0100 Subject: [PATCH 125/243] healthd: Detect power supply type for all charger devices Power supply type is not determined via the device name, hence iterate over all available devices in the subsystem node and read the type from device file. shell@hammerhead:/ $ ls /sys/class/power_supply ac batt_therm battery touch usb wireless <4>[ 3184.867782] healthd: touch: Unknown power supply type <4>[ 3184.868039] healthd: batt_therm: Unknown power supply type <6>[ 3184.880506] healthd: battery l=89 v=4181 t=25.5 h=2 st=2 c=-288 chg=u <4>[ 3184.890362] healthd: touch: Unknown power supply type <4>[ 3184.890549] healthd: batt_therm: Unknown power supply type <6>[ 3184.899419] healthd: battery l=89 v=4181 t=25.5 h=2 st=2 c=-59 chg=u <4>[ 3184.908756] healthd: touch: Unknown power supply type <4>[ 3184.908984] healthd: batt_therm: Unknown power supply type <6>[ 3184.919672] healthd: battery l=89 v=4181 t=25.6 h=2 st=2 c=-25 chg=u Change-Id: I863bfab95193899460237b51997e0418eeb4ee2c --- healthd/BatteryMonitor.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 651a7d41..e99f519a 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -229,9 +229,9 @@ bool BatteryMonitor::update(void) { path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name); switch(readPowerSupplyType(path)) { - case ANDROID_POWER_SUPPLY_TYPE_AC: - case ANDROID_POWER_SUPPLY_TYPE_USB: - case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: + case ANDROID_POWER_SUPPLY_TYPE_BATTERY: + break; + default: path.clear(); path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name); if (access(path.string(), R_OK) == 0) { @@ -259,11 +259,6 @@ bool BatteryMonitor::update(void) { } } break; - case ANDROID_POWER_SUPPLY_TYPE_BATTERY: - break; - default: - KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", - name); } //switch } //while closedir(dir); From 4648a5a1b4b990ee539e59ab42e8d96b097f9e01 Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Thu, 18 Dec 2014 14:18:47 -0800 Subject: [PATCH 126/243] adb: host: Provide better sideload status * Show data transfer in MB and in multiple of the file size. * Show a spinner to indicate liveness, which is updated at least once per second regardless of data transfer. * Do not allow sideload of zero sized files. Change-Id: I1bd0df6a8183fad5a502fc26a7e789c27d24f71a --- adb/commandline.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/adb/commandline.c b/adb/commandline.c index 05b4ef6f..0b088d86 100644 --- a/adb/commandline.c +++ b/adb/commandline.c @@ -525,6 +525,8 @@ int adb_download(const char *service, const char *fn, unsigned progress) #define SIDELOAD_HOST_BLOCK_SIZE (CHUNK_SIZE) +#define MB (1024*1024) + /* * The sideload-host protocol serves the data in a file (given on the * command line) to the client, using a simple protocol: @@ -558,6 +560,11 @@ int adb_sideload_host(const char* fn) { fprintf(stderr, "* cannot read '%s' *\n", fn); return -1; } + if (sz == 0) { + printf("\n"); + fprintf(stderr, "* '%s' is empty *\n", fn); + return -1; + } char buf[100]; sprintf(buf, "sideload-host:%d:%d", sz, SIDELOAD_HOST_BLOCK_SIZE); @@ -573,8 +580,29 @@ int adb_sideload_host(const char* fn) { int opt = SIDELOAD_HOST_BLOCK_SIZE; opt = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (const void *) &opt, sizeof(opt)); - int last_percent = -1; + static const char spinner[] = "/-\\|"; + static const int spinlen = sizeof(spinner)-1; + size_t last_xfer = 0; + int spin_index = 0; for (;;) { + fd_set fds; + struct timeval tv; + FD_ZERO(&fds); + FD_SET(fd, &fds); + tv.tv_sec = 1; + tv.tv_usec = 0; + int rc = select(fd+1, &fds, NULL, NULL, &tv); + size_t diff = xfer - last_xfer; + if (rc == 0 || diff >= (1*MB)) { + spin_index = (spin_index+1) % spinlen; + printf("\rserving: '%s' %4dmb %.2fx %c", fn, + xfer/(1*MB), (double)xfer/sz, spinner[spin_index]); + fflush(stdout); + last_xfer = xfer; + } + if (rc == 0) { + continue; + } if (readx(fd, buf, 8)) { fprintf(stderr, "* failed to read command: %s\n", adb_error()); status = -1; @@ -609,22 +637,9 @@ int adb_sideload_host(const char* fn) { goto done; } xfer += to_write; - - // For normal OTA packages, we expect to transfer every byte - // twice, plus a bit of overhead (one read during - // verification, one read of each byte for installation, plus - // extra access to things like the zip central directory). - // This estimate of the completion becomes 100% when we've - // transferred ~2.13 (=100/47) times the package size. - int percent = (int)(xfer * 47LL / (sz ? sz : 1)); - if (percent != last_percent) { - printf("\rserving: '%s' (~%d%%) ", fn, percent); - fflush(stdout); - last_percent = percent; - } } - printf("\rTotal xfer: %.2fx%*s\n", (double)xfer / (sz ? sz : 1), (int)strlen(fn)+10, ""); + printf("\ntotal xfer: %4dmb %.2fx\n", xfer/(1*MB), (double)xfer/sz); done: if (fd >= 0) adb_close(fd); From 89c14eb73d51a4c8dcd0043838f1ff7efa12115f Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Fri, 19 Dec 2014 14:53:03 -0800 Subject: [PATCH 127/243] adb: Fix host build Change-Id: I173e920aa836bb0327bfae235022de011f3e2b99 --- adb/commandline.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adb/commandline.c b/adb/commandline.c index 0b088d86..44644c71 100644 --- a/adb/commandline.c +++ b/adb/commandline.c @@ -595,8 +595,8 @@ int adb_sideload_host(const char* fn) { size_t diff = xfer - last_xfer; if (rc == 0 || diff >= (1*MB)) { spin_index = (spin_index+1) % spinlen; - printf("\rserving: '%s' %4dmb %.2fx %c", fn, - xfer/(1*MB), (double)xfer/sz, spinner[spin_index]); + printf("\rserving: '%s' %4umb %.2fx %c", fn, + (unsigned)xfer/(1*MB), (double)xfer/sz, spinner[spin_index]); fflush(stdout); last_xfer = xfer; } @@ -639,7 +639,7 @@ int adb_sideload_host(const char* fn) { xfer += to_write; } - printf("\ntotal xfer: %4dmb %.2fx\n", xfer/(1*MB), (double)xfer/sz); + printf("\ntotal xfer: %4umb %.2fx\n", (unsigned)xfer/(1*MB), (double)xfer/sz); done: if (fd >= 0) adb_close(fd); From e9af679e7dac492baa0cf69a000ad1c83356b8f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Burtin?= Date: Sun, 5 Feb 2012 00:55:17 +0100 Subject: [PATCH 128/243] set /system/etc/init.d/* permissions ported from CM7 Change-Id: I3422c392248673fd7a8c8b45f34678097e553b5b --- include/private/android_filesystem_config.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index c51a5ae3..d15c4761 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -234,6 +234,7 @@ static const struct fs_path_config android_dirs[] = { { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" }, { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" }, { 00755, AID_ROOT, AID_ROOT, 0, "system/etc/ppp" }, + { 00755, AID_ROOT, AID_SHELL, 0, "system/etc" }, { 00755, AID_ROOT, AID_SHELL, 0, "vendor" }, { 00777, AID_ROOT, AID_ROOT, 0, "sdcard" }, { 00755, AID_ROOT, AID_ROOT, 0, 0 }, @@ -281,6 +282,7 @@ static const struct fs_path_config android_files[] = { { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/uncrypt" }, { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/install-recovery.sh" }, { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" }, + { 00755, AID_ROOT, AID_SHELL, 0, "system/etc/init.d/*" }, { 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" }, { 00755, AID_ROOT, AID_ROOT, 0, "system/lib64/valgrind/*" }, { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" }, From 3572bc6192dccac28c4805bb3ff685593778f4ee Mon Sep 17 00:00:00 2001 From: Brian Beloshapka Date: Wed, 3 Dec 2014 22:34:00 -0500 Subject: [PATCH 129/243] init: create symlinks to mtd block device nodes Given a device in the form of "/devices/virtual/mtd/mtd0/mtdblock0": * Creates symlinks for mtd block devices in /dev/block/mtd/mtd * Creates symlinks based on partition name in /dev/block/mtd/by-name/ Change-Id: Id8d61be88935a0ef83297d1d5e453d8ba0d586de --- init/devices.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/init/devices.c b/init/devices.c index 64262975..9f402693 100644 --- a/init/devices.c +++ b/init/devices.c @@ -352,6 +352,35 @@ static void remove_platform_device(const char *path) } } +/* Given a path that may start with an MTD device (/devices/virtual/mtd/mtd8/mtdblock8), + * populate the supplied buffer with the MTD partition number and return 0. + * If it doesn't start with an MTD device, or there is some error, return -1 */ +static int find_mtd_device_prefix(const char *path, char *buf, ssize_t buf_sz) +{ + const char *start, *end; + + if (strncmp(path, "/devices/virtual/mtd", 20)) + return -1; + + /* Beginning of the prefix is the initial "mtdXX" after "/devices/virtual/mtd/" */ + start = path + 21; + + /* End of the prefix is one path '/' later, capturing the partition number + * Example: mtd8 */ + end = strchr(start, '/'); + if (!end) { + return -1; + } + + /* Make sure we have enough room for the string plus null terminator */ + if (end - start + 1 > buf_sz) + return -1; + + strncpy(buf, start, end - start); + buf[end - start] = '\0'; + return 0; +} + /* Given a path that may start with a PCI device, populate the supplied buffer * with the PCI domain/bus number and the peripheral ID and return 0. * If it doesn't start with a PCI device, or there is some error, return -1 */ @@ -557,6 +586,10 @@ static char **get_block_device_symlinks(struct uevent *uevent) char *p; unsigned int size; struct stat info; + int mtd_fd = -1; + int nr; + char mtd_name_path[256]; + char mtd_name[64]; pdev = find_platform_device(uevent->path); if (pdev) { @@ -565,6 +598,9 @@ static char **get_block_device_symlinks(struct uevent *uevent) } else if (!find_pci_device_prefix(uevent->path, buf, sizeof(buf))) { device = buf; type = "pci"; + } else if (!find_mtd_device_prefix(uevent->path, buf, sizeof(buf))) { + device = buf; + type = "mtd"; } else { return NULL; } @@ -578,6 +614,29 @@ static char **get_block_device_symlinks(struct uevent *uevent) snprintf(link_path, sizeof(link_path), "/dev/block/%s/%s", type, device); + if(!strcmp(type, "mtd")) { + snprintf(mtd_name_path, sizeof(mtd_name_path), + "/sys/devices/virtual/%s/%s/name", type, device); + mtd_fd = open(mtd_name_path, O_RDONLY); + if(mtd_fd < 0) { + ERROR("Unable to open %s for reading", mtd_name_path); + return NULL; + } + nr = read(mtd_fd, mtd_name, sizeof(mtd_name) - 1); + if (nr <= 0) + return NULL; + close(mtd_fd); + mtd_name[nr - 1] = '\0'; + + p = strdup(mtd_name); + sanitize(p); + if (asprintf(&links[link_num], "/dev/block/%s/by-name/%s", type, p) > 0) + link_num++; + else + links[link_num] = NULL; + free(p); + } + if (uevent->partition_name) { p = strdup(uevent->partition_name); sanitize(p); From 533f2792a415e2fa680234301c679bac491bbeb2 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Wed, 15 Oct 2014 02:02:33 -0700 Subject: [PATCH 130/243] fastboot: Add missing fastboot USB IDs Change-Id: I1616e9e6a57652aa919f979833c0e19479343966 --- fastboot/fastboot.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c index 43d05aa3..4d83f4f4 100644 --- a/fastboot/fastboot.c +++ b/fastboot/fastboot.c @@ -214,7 +214,9 @@ int match_fastboot_with_serial(usb_ifc_info *info, const char *local_serial) (info->dev_vendor != 0x413c) && // DELL (info->dev_vendor != 0x2314) && // INQ Mobile (info->dev_vendor != 0x0b05) && // Asus - (info->dev_vendor != 0x0bb4)) // HTC + (info->dev_vendor != 0x0bb4) && // HTC + (info->dev_vendor != 0x0421) && // Nokia + (info->dev_vendor != 0x1ebf)) // Coolpad return -1; if(info->ifc_class != 0xff) return -1; if(info->ifc_subclass != 0x42) return -1; From bad5a074f2eac12244a1422e6cb772a11741a339 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Tue, 23 Dec 2014 00:47:33 +0000 Subject: [PATCH 131/243] libcutils: Do not use the kernel headers No idea why this is here, but it breaks arm64 builds. bionic's signal.h must be used on those Change-Id: Id4f07a9b13a32c563fda6e96e4a87b8b97d125fd --- libcutils/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcutils/Android.mk b/libcutils/Android.mk index 69e00d1f..bee2bd75 100644 --- a/libcutils/Android.mk +++ b/libcutils/Android.mk @@ -149,7 +149,7 @@ ifeq ($(TARGET_RECOVERY_PRE_COMMAND_CLEAR_REASON),true) LOCAL_CFLAGS += -DRECOVERY_PRE_COMMAND_CLEAR_REASON endif -LOCAL_C_INCLUDES := $(libcutils_c_includes) $(KERNEL_HEADERS) +LOCAL_C_INCLUDES := $(libcutils_c_includes) LOCAL_STATIC_LIBRARIES := liblog LOCAL_CFLAGS += $(targetSmpFlag) -Werror LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk From a8555c65bd2c0416d9a57ea8d0419a7dad62c51b Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Wed, 24 Dec 2014 00:11:16 +0000 Subject: [PATCH 132/243] libsysutils: Do not use the kernel headers No idea why this is here, but it breaks arm64 builds. bionic's signal.h must be used on those Change-Id: I64f71565b179af38345fcf1496274ee5858abb05 --- libsysutils/Android.mk | 2 -- 1 file changed, 2 deletions(-) diff --git a/libsysutils/Android.mk b/libsysutils/Android.mk index d71f0faf..3fdad320 100644 --- a/libsysutils/Android.mk +++ b/libsysutils/Android.mk @@ -16,7 +16,6 @@ common_src_files := \ include $(CLEAR_VARS) LOCAL_SRC_FILES:= $(common_src_files) LOCAL_MODULE:= libsysutils -LOCAL_C_INCLUDES := $(KERNEL_HEADERS) LOCAL_CFLAGS := -Werror LOCAL_SHARED_LIBRARIES := libcutils liblog include $(BUILD_SHARED_LIBRARY) @@ -24,7 +23,6 @@ include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_SRC_FILES:= $(common_src_files) LOCAL_MODULE:= libsysutils -LOCAL_C_INCLUDES := $(KERNEL_HEADERS) LOCAL_CFLAGS := -Werror include $(BUILD_STATIC_LIBRARY) From 252000b6495dcf2d5a879e3824fb6127df692e52 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Mon, 2 Aug 2010 11:23:47 -0700 Subject: [PATCH 133/243] Forward-port mkbootimg / unpackbootimg support * Mostly from Koush and Seth Shelnutt unpackbootimg (squashed) unpackbootimg ported forward from eclair Change-Id: I74d2df0b47d40e7105cc58c2b05f8f383dc7f8a0 port forward pagesize arg from eclair Change-Id: Ia789a4f392a3890aa0efa7efb42032482b48beb0 unpackbootimg should output BOARD_PAGE_SIZE Change-Id: Ieb5cda01943a33da97eee4d025f56c2c6e7560e8 output page size in mkbootimg add an option to override the pagesize for boot images created by nubs. ie, acer liquid mkliquidbootimg. Change-Id: Ie0c7e67edf5ae59019517e72b9be8c0b81388e41 Update unpackbootimg to verify the Android boot image magic value. It will also search the first 512 bytes for padding. Change-Id: I490cba05f2bb616a3f64e3271ecaa61eb9e64be8 unpackbootimg: Fix up the padding search in case the magic does not fall on a 8 byte boundary. Change-Id: I57471f9c2117cd7965b6958ea0aa88e356436da6 unpackbootimg: Fix magic search. Change-Id: I68470b637556a08e48ff72b7ef8811cba13b04ad unpackbootimg: apparently mkbootimg no longer accepts hex values Change-Id: I95a33f7b40470e4500d418d863a65a75e7aa8499 unpackbootimg: Need to also update the written file. Change-Id: I45faddbae85273c79b2837f97933634b6e70546f ramdiskaddr is now ramdisk_offset Change-Id: I3bf83af5f7001f581506dc7fd9b1eb653334ad35 unpackbootimg: remove host LOCAL_MODULE_TAG Change-Id: I199d680dc5ab8bf50f5be65c29095bf3adade695 unpackbootimg: Add support for device trees Change-Id: I340eed99d2274a2f4cbaf5a9f27726ff3a9302e5 unpackbootimg: Add support for detecting lz4 compressed ramdisks This will check for lz4 magic, and if found change the extension of the file. Else it'll fall back to the default behavior of assuming gzip. This has been tested with stock LS980 boot images and LS970 boot images for lz4 and gzip respectively. Change-Id: If2139ff172397b6db079ffb7ab9cb61897c38fb3 unpackbootimg: Add support for dumping ramdisk offset Change-Id: Ic62b9fe61db4435ecbc52b66db5ffc9b9d79cbb4 unpackbootimg: Add support for second, second_offset and tags_offset. Change-Id: Ia7ef7f00191dbf2c44736c4e4d980f72afa8c253 --- mkbootimg/Android.mk | 30 ++++++ mkbootimg/mkbootimg.c | 2 + mkbootimg/unpackbootimg.c | 211 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 243 insertions(+) create mode 100644 mkbootimg/unpackbootimg.c diff --git a/mkbootimg/Android.mk b/mkbootimg/Android.mk index 0c9b0c65..dd42459c 100644 --- a/mkbootimg/Android.mk +++ b/mkbootimg/Android.mk @@ -10,4 +10,34 @@ LOCAL_MODULE := mkbootimg include $(BUILD_HOST_EXECUTABLE) +include $(CLEAR_VARS) +LOCAL_SRC_FILES := unpackbootimg.c +LOCAL_MODULE := unpackbootimg +include $(BUILD_HOST_EXECUTABLE) + +include $(CLEAR_VARS) +LOCAL_SRC_FILES := mkbootimg.c +LOCAL_STATIC_LIBRARIES := libmincrypt libcutils libc +LOCAL_MODULE := utility_mkbootimg +LOCAL_MODULE_TAGS := eng +LOCAL_MODULE_STEM := mkbootimg +LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES +LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities +LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities +LOCAL_FORCE_STATIC_EXECUTABLE := true +include $(BUILD_EXECUTABLE) + +include $(CLEAR_VARS) +LOCAL_SRC_FILES := unpackbootimg.c +LOCAL_STATIC_LIBRARIES := libcutils libc +LOCAL_MODULE := utility_unpackbootimg +LOCAL_MODULE_TAGS := eng +LOCAL_MODULE_STEM := unpackbootimg +LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES +LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities +LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities +LOCAL_FORCE_STATIC_EXECUTABLE := true +include $(BUILD_EXECUTABLE) + $(call dist-for-goals,dist_files,$(LOCAL_BUILT_MODULE)) + diff --git a/mkbootimg/mkbootimg.c b/mkbootimg/mkbootimg.c index f46206f8..38b4b37f 100644 --- a/mkbootimg/mkbootimg.c +++ b/mkbootimg/mkbootimg.c @@ -66,6 +66,8 @@ int usage(void) " [ --base
]\n" " [ --pagesize ]\n" " [ --dt ]\n" + " [ --ramdisk_offset
]\n" + " [ --tags_offset
]\n" " -o|--output \n" ); return 1; diff --git a/mkbootimg/unpackbootimg.c b/mkbootimg/unpackbootimg.c new file mode 100644 index 00000000..3d2fda73 --- /dev/null +++ b/mkbootimg/unpackbootimg.c @@ -0,0 +1,211 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mincrypt/sha.h" +#include "bootimg.h" + +typedef unsigned char byte; + +int read_padding(FILE* f, unsigned itemsize, int pagesize) +{ + byte* buf = (byte*)malloc(sizeof(byte) * pagesize); + unsigned pagemask = pagesize - 1; + unsigned count; + + if((itemsize & pagemask) == 0) { + free(buf); + return 0; + } + + count = pagesize - (itemsize & pagemask); + + fread(buf, count, 1, f); + free(buf); + return count; +} + +void write_string_to_file(char* file, char* string) +{ + FILE* f = fopen(file, "w"); + fwrite(string, strlen(string), 1, f); + fwrite("\n", 1, 1, f); + fclose(f); +} + +int usage() { + printf("usage: unpackbootimg\n"); + printf("\t-i|--input boot.img\n"); + printf("\t[ -o|--output output_directory]\n"); + printf("\t[ -p|--pagesize ]\n"); + return 0; +} + +int main(int argc, char** argv) +{ + char tmp[PATH_MAX]; + char* directory = "./"; + char* filename = NULL; + int pagesize = 0; + + argc--; + argv++; + while(argc > 0){ + char *arg = argv[0]; + char *val = argv[1]; + argc -= 2; + argv += 2; + if(!strcmp(arg, "--input") || !strcmp(arg, "-i")) { + filename = val; + } else if(!strcmp(arg, "--output") || !strcmp(arg, "-o")) { + directory = val; + } else if(!strcmp(arg, "--pagesize") || !strcmp(arg, "-p")) { + pagesize = strtoul(val, 0, 16); + } else { + return usage(); + } + } + + if (filename == NULL) { + return usage(); + } + + int total_read = 0; + FILE* f = fopen(filename, "rb"); + boot_img_hdr header; + + //printf("Reading header...\n"); + int i; + for (i = 0; i <= 512; i++) { + fseek(f, i, SEEK_SET); + fread(tmp, BOOT_MAGIC_SIZE, 1, f); + if (memcmp(tmp, BOOT_MAGIC, BOOT_MAGIC_SIZE) == 0) + break; + } + total_read = i; + if (i > 512) { + printf("Android boot magic not found.\n"); + return 1; + } + fseek(f, i, SEEK_SET); + printf("Android magic found at: %d\n", i); + + fread(&header, sizeof(header), 1, f); + printf("BOARD_KERNEL_CMDLINE %s\n", header.cmdline); + printf("BOARD_KERNEL_BASE %08x\n", header.kernel_addr - 0x00008000); + printf("BOARD_RAMDISK_OFFSET %08x\n", header.ramdisk_addr - header.kernel_addr + 0x00008000); + printf("BOARD_SECOND_OFFSET %08x\n", header.second_addr - header.kernel_addr + 0x00008000); + printf("BOARD_TAGS_OFFSET %08x\n",header.tags_addr - header.kernel_addr + 0x00008000); + printf("BOARD_PAGE_SIZE %d\n", header.page_size); + printf("BOARD_SECOND_SIZE %d\n", header.second_size); + printf("BOARD_DT_SIZE %d\n", header.dt_size); + + if (pagesize == 0) { + pagesize = header.page_size; + } + + //printf("cmdline...\n"); + sprintf(tmp, "%s/%s", directory, basename(filename)); + strcat(tmp, "-cmdline"); + write_string_to_file(tmp, header.cmdline); + + //printf("base...\n"); + sprintf(tmp, "%s/%s", directory, basename(filename)); + strcat(tmp, "-base"); + char basetmp[200]; + sprintf(basetmp, "%08x", header.kernel_addr - 0x00008000); + write_string_to_file(tmp, basetmp); + + //printf("ramdisk_offset...\n"); + sprintf(tmp, "%s/%s", directory, basename(filename)); + strcat(tmp, "-ramdisk_offset"); + char ramdisktmp[200]; + sprintf(ramdisktmp, "%08x", header.ramdisk_addr - header.kernel_addr + 0x00008000); + write_string_to_file(tmp, ramdisktmp); + + //printf("second_offset...\n"); + sprintf(tmp, "%s/%s", directory, basename(filename)); + strcat(tmp, "-second_offset"); + char secondtmp[200]; + sprintf(secondtmp, "%08x", header.second_addr - header.kernel_addr + 0x00008000); + write_string_to_file(tmp, secondtmp); + + //printf("tags_offset...\n"); + sprintf(tmp, "%s/%s", directory, basename(filename)); + strcat(tmp, "-tags_offset"); + char tagstmp[200]; + sprintf(tagstmp, "%08x", header.tags_addr - header.kernel_addr + 0x00008000); + write_string_to_file(tmp, tagstmp); + + //printf("pagesize...\n"); + sprintf(tmp, "%s/%s", directory, basename(filename)); + strcat(tmp, "-pagesize"); + char pagesizetmp[200]; + sprintf(pagesizetmp, "%d", header.page_size); + write_string_to_file(tmp, pagesizetmp); + + total_read += sizeof(header); + //printf("total read: %d\n", total_read); + total_read += read_padding(f, sizeof(header), pagesize); + + sprintf(tmp, "%s/%s", directory, basename(filename)); + strcat(tmp, "-zImage"); + FILE *k = fopen(tmp, "wb"); + byte* kernel = (byte*)malloc(header.kernel_size); + //printf("Reading kernel...\n"); + fread(kernel, header.kernel_size, 1, f); + total_read += header.kernel_size; + fwrite(kernel, header.kernel_size, 1, k); + fclose(k); + + //printf("total read: %d\n", header.kernel_size); + total_read += read_padding(f, header.kernel_size, pagesize); + + + byte* ramdisk = (byte*)malloc(header.ramdisk_size); + //printf("Reading ramdisk...\n"); + fread(ramdisk, header.ramdisk_size, 1, f); + total_read += header.ramdisk_size; + sprintf(tmp, "%s/%s", directory, basename(filename)); + if(ramdisk[0] == 0x02 && ramdisk[1]== 0x21) + strcat(tmp, "-ramdisk.lz4"); + else + strcat(tmp, "-ramdisk.gz"); + FILE *r = fopen(tmp, "wb"); + fwrite(ramdisk, header.ramdisk_size, 1, r); + fclose(r); + + total_read += read_padding(f, header.ramdisk_size, pagesize); + + sprintf(tmp, "%s/%s", directory, basename(filename)); + strcat(tmp, "-second"); + FILE *s = fopen(tmp, "wb"); + byte* second = (byte*)malloc(header.second_size); + //printf("Reading second...\n"); + fread(second, header.second_size, 1, f); + total_read += header.second_size; + fwrite(second, header.second_size, 1, r); + fclose(s); + + total_read += read_padding(f, header.second_size, pagesize); + + sprintf(tmp, "%s/%s", directory, basename(filename)); + strcat(tmp, "-dt"); + FILE *d = fopen(tmp, "wb"); + byte* dt = (byte*)malloc(header.dt_size); + //printf("Reading dt...\n"); + fread(dt, header.dt_size, 1, f); + total_read += header.dt_size; + fwrite(dt, header.dt_size, 1, r); + fclose(d); + + fclose(f); + + //printf("Total Read: %d\n", total_read); + return 0; +} From 1240738355567f680efd5ccdd301cfdf9c33c0d2 Mon Sep 17 00:00:00 2001 From: codeworkx Date: Sat, 27 Jul 2013 08:18:42 +0200 Subject: [PATCH 134/243] libutils: refbase: jellybean mr1 compat [mikeioannina]: Update for L Can be enabled with global cflag REFBASE_JB_MR1_COMPAT_SYMBOLS Change-Id: Ideee0c3814a17b47f70fd612d27067fe19ae698d --- include/utils/RefBase.h | 9 +++++++++ libutils/RefBase.cpp | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/include/utils/RefBase.h b/include/utils/RefBase.h index 8e15c190..5afdf927 100644 --- a/include/utils/RefBase.h +++ b/include/utils/RefBase.h @@ -53,6 +53,15 @@ inline bool operator _op_ (const U* o) const { \ // --------------------------------------------------------------------------- +#ifdef REFBASE_JB_MR1_COMPAT_SYMBOLS +class ReferenceConverterBase { +public: + virtual size_t getReferenceTypeSize() const = 0; + virtual void* getReferenceBase(void const*) const = 0; + inline virtual ~ReferenceConverterBase() { } +}; +#endif + class ReferenceRenamer { protected: // destructor is purposedly not virtual so we avoid code overhead from diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp index 02907ad6..b0ca12e4 100644 --- a/libutils/RefBase.cpp +++ b/libutils/RefBase.cpp @@ -630,6 +630,13 @@ void RefBase::onLastWeakRef(const void* /*id*/) // --------------------------------------------------------------------------- +#ifdef REFBASE_JB_MR1_COMPAT_SYMBOLS +extern "C" void _ZN7android7RefBase14moveReferencesEPvPKvjRKNS_22ReferenceConverterBaseE(void* /*dst*/, void const* /*src*/, size_t /*n*/, + const ReferenceConverterBase& /*caster*/) +{ +} +#endif + #if DEBUG_REFS void RefBase::renameRefs(size_t n, const ReferenceRenamer& renamer) { for (size_t i=0 ; i Date: Mon, 29 Dec 2014 17:37:47 -0600 Subject: [PATCH 135/243] Core: ADB: Don't set root access as a default fallback option. Problem: if persist.sys.root_access is not present, it will set root access anyways regardless of build type flaw: user build is not shipping root. fix: set to 0 anyway which is no root. Change-Id: I00666f027b5d67e48560445fcc6541201edd7c65 --- adb/services.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adb/services.c b/adb/services.c index e9bd8714..a2c74b8d 100644 --- a/adb/services.c +++ b/adb/services.c @@ -77,7 +77,7 @@ void restart_root_service(int fd, void *cookie) return; } - property_get("persist.sys.root_access", value, "1"); + property_get("persist.sys.root_access", value, "0"); property_get("ro.build.type", build_type, ""); property_get("ro.cm.version", cm_version, ""); From c9eccd68c83268b30c33da947279c680b7df28cb Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Tue, 11 Sep 2012 20:10:38 -0700 Subject: [PATCH 136/243] rootdir: Update cpufreq permissions when governor changes * Requires a kernel change to send the uevent. * This should alleviate some frustration that the performance/kernel folks have expressed regarding the Power HAL. Change-Id: I31e6e13534159214a3b600082b7c0e4249433364 rootdir: Tighten permissions on boostpulse nodes * New PowerHAL code will only write to this as the system user, so remove the need for it to be world writable. Change-Id: Ia9e69a6feff7c5ef1ff34a1180225e4008e8130f rootdir: Set perms on interactive governor's min_sample_time Change-Id: I75e9f424af731bdf1ca222eee2f4f18b20a6552b rootdir: set perms on ondemand governor's up_threshold Change-Id: I0a042a81be677821fa4099a3e19281d390dd27c3 Set permissions on io_is_busy node for interactive governor Change-Id: I9dce40b0680fdb594f415aade22dbd92ebffa43c rootdir: Set permissions for additional ondemand sysfs nodes Change-Id: Id39cab7ab69ea8f67de99f5b4ee342e2c52ebedd ueventd: Add rules for governors and cpufreq This change requires a kernel patch in cpufreq to work. Change-Id: I6281645291ca4516748f65d0799e14971c5fb2ea --- rootdir/ueventd.rc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc index 5d0d1bf2..d21c3fd5 100644 --- a/rootdir/ueventd.rc +++ b/rootdir/ueventd.rc @@ -95,3 +95,42 @@ subsystem adf /sys/devices/virtual/usb_composite/* enable 0664 root system /sys/devices/system/cpu/cpu* cpufreq/scaling_max_freq 0664 system system /sys/devices/system/cpu/cpu* cpufreq/scaling_min_freq 0664 system system +/sys/devices/system/cpu/cpu* cpufreq/scaling_governor 0664 system system + +/sys/devices/system/cpu/cpufreq ondemand/boostfreq 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/boostpulse 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/boosttime 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/down_differential 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/down_differential_multi_core 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/ignore_nice_load 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/input_boost 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/io_is_busy 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/optimal_freq 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/powersave_bias 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/sampling_down_factor 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/sampling_rate 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/sampling_rate_min 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/sync_freq 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/up_threshold 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/up_threshold_any_cpu_load 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/up_threshold_multi_core 0664 system system +/sys/devices/system/cpu/cpufreq ondemand/up_threshold_multi_core 0664 system system + +/sys/devices/system/cpu/cpufreq interactive/above_hispeed_delay 0664 system system +/sys/devices/system/cpu/cpufreq interactive/align_windows 0664 system system +/sys/devices/system/cpu/cpufreq interactive/boost 0664 system system +/sys/devices/system/cpu/cpufreq interactive/boostpulse 0664 system system +/sys/devices/system/cpu/cpufreq interactive/boostpulse_duration 0664 system system +/sys/devices/system/cpu/cpufreq interactive/go_hispeed_load 0664 system system +/sys/devices/system/cpu/cpufreq interactive/hispeed_freq 0664 system system +/sys/devices/system/cpu/cpufreq interactive/io_is_busy 0664 system system +/sys/devices/system/cpu/cpufreq interactive/max_freq_hysteresis 0664 system system +/sys/devices/system/cpu/cpufreq interactive/min_sample_rate 0664 system system +/sys/devices/system/cpu/cpufreq interactive/min_sample_time 0664 system system +/sys/devices/system/cpu/cpufreq interactive/sampling_down_factor 0664 system system +/sys/devices/system/cpu/cpufreq interactive/sync_freq 0664 system system +/sys/devices/system/cpu/cpufreq interactive/target_loads 0664 system system +/sys/devices/system/cpu/cpufreq interactive/timer_rate 0664 system system +/sys/devices/system/cpu/cpufreq interactive/timer_slack 0664 system system +/sys/devices/system/cpu/cpufreq interactive/up_threshold_any_cpu_freq 0664 system system +/sys/devices/system/cpu/cpufreq interactive/up_threshold_any_cpu_load 0664 system system From e419108a138b3f57263e10a23696548ab189ad25 Mon Sep 17 00:00:00 2001 From: myfluxi Date: Sun, 4 Jan 2015 00:51:50 +0100 Subject: [PATCH 137/243] rootdir: Remove duplicate rule Change-Id: I1e7d06daa1d2092d9522a6a49842eb479da267fd --- rootdir/ueventd.rc | 1 - 1 file changed, 1 deletion(-) diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc index d21c3fd5..ea1eb41d 100644 --- a/rootdir/ueventd.rc +++ b/rootdir/ueventd.rc @@ -114,7 +114,6 @@ subsystem adf /sys/devices/system/cpu/cpufreq ondemand/up_threshold 0664 system system /sys/devices/system/cpu/cpufreq ondemand/up_threshold_any_cpu_load 0664 system system /sys/devices/system/cpu/cpufreq ondemand/up_threshold_multi_core 0664 system system -/sys/devices/system/cpu/cpufreq ondemand/up_threshold_multi_core 0664 system system /sys/devices/system/cpu/cpufreq interactive/above_hispeed_delay 0664 system system /sys/devices/system/cpu/cpufreq interactive/align_windows 0664 system system From c5a4b317264217964f154afe0b3c45b5aa3d6f65 Mon Sep 17 00:00:00 2001 From: Dmitry Shmidt Date: Thu, 15 Jan 2015 10:35:54 -0800 Subject: [PATCH 138/243] android_filesystem: Remove setuid bits from tcpdump Bug: 18669116 Change-Id: I25486f2fe0e994f569b788fc9f03ef6d383f54d4 Signed-off-by: Dmitry Shmidt --- include/private/android_filesystem_config.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index 5d9c3ea7..2f528b95 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -248,7 +248,6 @@ static const struct fs_path_config android_files[] = { { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/librank" }, { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procrank" }, { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" }, - { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/tcpdump" }, { 04770, AID_ROOT, AID_RADIO, 0, "system/bin/pppd-ril" }, /* the following files have enhanced capabilities and ARE included in user builds. */ From d89b1977189ce55f297d059b2e3dc2433f303067 Mon Sep 17 00:00:00 2001 From: David Ng Date: Fri, 21 Nov 2014 18:01:08 -0800 Subject: [PATCH 139/243] ueventd: Fix bootdevice by-name/by-num link creation Create bootdevice by-name/by-num links only if the block device is the bootdevice. This fixes the issue of bootdevice path being created incorrectly if the first reported device with by-name/by-num is not the bootdevice. Change-Id: Ifb68080e3149917f9ee88a4a421007f29e8d83d2 --- init/devices.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/init/devices.c b/init/devices.c index 9f402693..263aa313 100644 --- a/init/devices.c +++ b/init/devices.c @@ -585,6 +585,7 @@ static char **get_block_device_symlinks(struct uevent *uevent) int ret; char *p; unsigned int size; + int is_bootdevice = 0; struct stat info; int mtd_fd = -1; int nr; @@ -637,6 +638,11 @@ static char **get_block_device_symlinks(struct uevent *uevent) free(p); } + if (bootdevice[0] != '\0' && !strncmp(device, bootdevice, sizeof(bootdevice))) { + make_link(link_path, "/dev/block/bootdevice"); + is_bootdevice = 1; + } + if (uevent->partition_name) { p = strdup(uevent->partition_name); sanitize(p); @@ -646,11 +652,13 @@ static char **get_block_device_symlinks(struct uevent *uevent) link_num++; else links[link_num] = NULL; - if (asprintf(&links[link_num], "/dev/block/bootdevice/by-name/%s", p) > 0) - link_num++; - else - links[link_num] = NULL; + if (is_bootdevice) { + if (asprintf(&links[link_num], "/dev/block/bootdevice/by-name/%s", p) > 0) + link_num++; + else + links[link_num] = NULL; + } free(p); } @@ -660,10 +668,12 @@ static char **get_block_device_symlinks(struct uevent *uevent) else links[link_num] = NULL; - if (asprintf(&links[link_num], "/dev/block/bootdevice/by-num/p%d", uevent->partition_num) > 0) - link_num++; - else - links[link_num] = NULL; + if (is_bootdevice) { + if (asprintf(&links[link_num], "/dev/block/bootdevice/by-num/p%d", uevent->partition_num) > 0) + link_num++; + else + links[link_num] = NULL; + } } slash = strrchr(uevent->path, '/'); @@ -672,10 +682,6 @@ static char **get_block_device_symlinks(struct uevent *uevent) else links[link_num] = NULL; - if (!strncmp(device, bootdevice, sizeof(bootdevice))) { - make_link(link_path, "/dev/block/bootdevice"); - } - return links; } From 1f01e5f864fd43fe795308157c2c94889ba5f358 Mon Sep 17 00:00:00 2001 From: Al Sutton Date: Wed, 19 Nov 2014 19:50:48 +0000 Subject: [PATCH 140/243] Fix building on modern versions of Xcode and OS X. Recent versions of XCode fail to compile the adb and fastboot binaries due to two functions being deprecated in 10.9 (GetCurrentProcess and ProcessInformationCopyDictionary), and the use of -Werrror. This patch replaces the method implementations which use calls to methods deprecated in the 10.9 SDK with versions which only call non-deprecated methods. Return path including executable instead of without The previous implementation returned the path the executable was in instead of returning the path including the executable (i.e. it returned ...bin instead of ...bin/executable). This is not what the original methods did and caused the process forking of adb to fail. This patch corrects the implementation. Remove explict use of ASCII encoding Replace the use of CFStringGetCString with kCFStringEncodingASCII specified with CFStringGetFileSystemRepresentation which will ensure the correct character encoding is used to conver the CFString into a NULL terminated char array suitable for use with POSIX APIs. Change-Id: Ibab1dc05c4f4db8604d329a493b4241992b8e69d Change-Id: I855bf26aff45093ca9022924f3ecd1b80f2305a8 --- adb/get_my_path_darwin.c | 14 +++++++------- fastboot/util_osx.c | 17 +++++++++-------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/adb/get_my_path_darwin.c b/adb/get_my_path_darwin.c index 5b95d153..ff1396c3 100644 --- a/adb/get_my_path_darwin.c +++ b/adb/get_my_path_darwin.c @@ -19,12 +19,12 @@ void get_my_path(char *s, size_t maxLen) { - ProcessSerialNumber psn; - GetCurrentProcess(&psn); - CFDictionaryRef dict; - dict = ProcessInformationCopyDictionary(&psn, 0xffffffff); - CFStringRef value = (CFStringRef)CFDictionaryGetValue(dict, - CFSTR("CFBundleExecutable")); - CFStringGetCString(value, s, maxLen, kCFStringEncodingUTF8); + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef executableURL = CFBundleCopyExecutableURL(mainBundle); + CFStringRef executablePathString = CFURLCopyFileSystemPath(executableURL, kCFURLPOSIXPathStyle); + CFRelease(executableURL); + + CFStringGetFileSystemRepresentation(executablePathString, s, maxLen); + CFRelease(executablePathString); } diff --git a/fastboot/util_osx.c b/fastboot/util_osx.c index 26b832a3..e7185627 100644 --- a/fastboot/util_osx.c +++ b/fastboot/util_osx.c @@ -31,14 +31,15 @@ void get_my_path(char s[PATH_MAX]) { - char *x; - ProcessSerialNumber psn; - GetCurrentProcess(&psn); - CFDictionaryRef dict; - dict = ProcessInformationCopyDictionary(&psn, 0xffffffff); - CFStringRef value = (CFStringRef)CFDictionaryGetValue(dict, - CFSTR("CFBundleExecutable")); - CFStringGetCString(value, s, PATH_MAX - 1, kCFStringEncodingUTF8); + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef executableURL = CFBundleCopyExecutableURL(mainBundle); + CFStringRef executablePathString = CFURLCopyFileSystemPath(executableURL, kCFURLPOSIXPathStyle); + CFRelease(executableURL); + + CFStringGetFileSystemRepresentation(executablePathString, s, PATH_MAX-1); + CFRelease(executablePathString); + + char *x; x = strrchr(s, '/'); if(x) x[1] = 0; } From 4ec3924dc9502be092a11f40535c92ada335d88a Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sat, 17 Jan 2015 16:25:40 -0800 Subject: [PATCH 141/243] init: Don't wreck things if androidboot.bootdevice isn't set * Allow for the original behavior if the bootdevice isn't specified on the command line. Change-Id: Id5549d3229f975747b35bb30a260a15df3b71cec --- init/devices.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/init/devices.c b/init/devices.c index 263aa313..9852eb42 100644 --- a/init/devices.c +++ b/init/devices.c @@ -585,7 +585,7 @@ static char **get_block_device_symlinks(struct uevent *uevent) int ret; char *p; unsigned int size; - int is_bootdevice = 0; + int is_bootdevice = -1; struct stat info; int mtd_fd = -1; int nr; @@ -638,7 +638,9 @@ static char **get_block_device_symlinks(struct uevent *uevent) free(p); } - if (bootdevice[0] != '\0' && !strncmp(device, bootdevice, sizeof(bootdevice))) { + if (bootdevice[0] == '\0') + is_bootdevice = 0; + else if (!strncmp(device, bootdevice, sizeof(bootdevice))) { make_link(link_path, "/dev/block/bootdevice"); is_bootdevice = 1; } @@ -653,7 +655,7 @@ static char **get_block_device_symlinks(struct uevent *uevent) else links[link_num] = NULL; - if (is_bootdevice) { + if (is_bootdevice >= 0) { if (asprintf(&links[link_num], "/dev/block/bootdevice/by-name/%s", p) > 0) link_num++; else @@ -668,7 +670,7 @@ static char **get_block_device_symlinks(struct uevent *uevent) else links[link_num] = NULL; - if (is_bootdevice) { + if (is_bootdevice >= 0) { if (asprintf(&links[link_num], "/dev/block/bootdevice/by-num/p%d", uevent->partition_num) > 0) link_num++; else From d1bec30dacc7435ed75a4429c21c12057d754f02 Mon Sep 17 00:00:00 2001 From: Dan Pasanen Date: Tue, 13 Jan 2015 10:55:30 -0600 Subject: [PATCH 142/243] fs_mgr: skip an fstab entry if we detect a different filesystem type * also add fs_mgr_get_entry_for_mount_point_after to header for recovery to use. Change-Id: I1bc1a1aad3328d139ab0d3d81b8b8c4b1b6bc49f --- fs_mgr/Android.mk | 6 +++--- fs_mgr/fs_mgr.c | 9 +++++++++ fs_mgr/include/fs_mgr.h | 1 + init/Android.mk | 4 +++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fs_mgr/Android.mk b/fs_mgr/Android.mk index 7cffc37a..92aeb4e1 100644 --- a/fs_mgr/Android.mk +++ b/fs_mgr/Android.mk @@ -8,8 +8,8 @@ LOCAL_SRC_FILES:= fs_mgr.c fs_mgr_verity.c fs_mgr_fstab.c LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_MODULE:= libfs_mgr -LOCAL_STATIC_LIBRARIES := liblogwrap libmincrypt libext4_utils_static -LOCAL_C_INCLUDES += system/extras/ext4_utils +LOCAL_STATIC_LIBRARIES := liblogwrap libmincrypt libext4_utils_static libext2_blkid libext2_uuid +LOCAL_C_INCLUDES += system/extras/ext4_utils external/e2fsprogs/lib LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include LOCAL_CFLAGS := -Werror @@ -30,7 +30,7 @@ LOCAL_FORCE_STATIC_EXECUTABLE := true LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/sbin LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED) -LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils liblog libc libmincrypt libext4_utils_static +LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils liblog libc libmincrypt libext4_utils_static libext2_blkid libext2_uuid LOCAL_CFLAGS := -Werror diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index cb881548..23e61faf 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "mincrypt/rsa.h" #include "mincrypt/sha.h" @@ -328,6 +329,7 @@ int fs_mgr_mount_all(struct fstab *fstab) int mret = -1; int mount_errno = 0; int attempted_idx = -1; + char *detected_fs_type; if (!fstab) { return -1; @@ -358,6 +360,13 @@ int fs_mgr_mount_all(struct fstab *fstab) continue; } } + + /* Skip fstab entries for partitions that we KNOW are wrong */ + detected_fs_type = blkid_get_tag_value(NULL, "TYPE", fstab->recs[i].blk_device); + if (detected_fs_type && strcmp(fstab->recs[i].fs_type, detected_fs_type) != 0) { + continue; + } + int last_idx_inspected; mret = mount_with_alternatives(fstab, i, &last_idx_inspected, &attempted_idx); i = last_idx_inspected; diff --git a/fs_mgr/include/fs_mgr.h b/fs_mgr/include/fs_mgr.h index 0c7eb20d..71974ad9 100644 --- a/fs_mgr/include/fs_mgr.h +++ b/fs_mgr/include/fs_mgr.h @@ -72,6 +72,7 @@ int fs_mgr_add_entry(struct fstab *fstab, const char *mount_point, const char *fs_type, const char *blk_device); struct fstab_rec *fs_mgr_get_entry_for_mount_point(struct fstab *fstab, const char *path); +struct fstab_rec *fs_mgr_get_entry_for_mount_point_after(struct fstab_rec *start_rec, struct fstab *fstab, const char *path); int fs_mgr_is_voldmanaged(struct fstab_rec *fstab); int fs_mgr_is_nonremovable(struct fstab_rec *fstab); int fs_mgr_is_encryptable(struct fstab_rec *fstab); diff --git a/init/Android.mk b/init/Android.mk index b336a2fa..fbe6a2dc 100755 --- a/init/Android.mk +++ b/init/Android.mk @@ -60,7 +60,9 @@ LOCAL_STATIC_LIBRARIES := \ libc \ libselinux \ libmincrypt \ - libext4_utils_static + libext4_utils_static \ + libext2_blkid \ + libext2_uuid LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk ifneq ($(strip $(TARGET_PLATFORM_DEVICE_BASE)),) From 9942c546266f5a94d769cba699e5515480cb9c12 Mon Sep 17 00:00:00 2001 From: MarcKe Date: Sun, 25 Jan 2015 22:32:31 +0100 Subject: [PATCH 143/243] healthd: remove useless goto in charger mode jumping to the cleanup makes a check that will fail anyways, since fd is smaller than 0 Change-Id: Ic53f186e00fc09a49de5185b01a2bf64a8ceba35 --- healthd/healthd_mode_charger.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 8e940833..e7981de5 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -229,7 +229,7 @@ static int set_tricolor_led(int on, int color) fd = open(leds[i].path, O_RDWR); if (fd < 0) { LOGE("Could not open red led node\n"); - goto cleanup; + continue; } if (on) snprintf(buffer, sizeof(int), "%d\n", 255); @@ -238,7 +238,6 @@ static int set_tricolor_led(int on, int color) if (write(fd, buffer, strlen(buffer)) < 0) LOGE("Could not write to led node\n"); -cleanup: if (fd >= 0) close(fd); } From 210b74a75d2249840f2ffde77132932e526f60b4 Mon Sep 17 00:00:00 2001 From: MarcKe Date: Sun, 25 Jan 2015 22:43:56 +0100 Subject: [PATCH 144/243] healthd: more descriptive LED path opening error message Change-Id: I6e3fa9e34a471c387a62dfc3318fd94620a30cd7 --- healthd/healthd_mode_charger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index e7981de5..df4a4b8d 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -228,7 +228,7 @@ static int set_tricolor_led(int on, int color) if ((color & leds[i].color) && (access(leds[i].path, R_OK | W_OK) == 0)) { fd = open(leds[i].path, O_RDWR); if (fd < 0) { - LOGE("Could not open red led node\n"); + LOGE("Could not open led node %d\n", i); continue; } if (on) From e978018ef3b1efdb07a32a941d94fb170d8d2722 Mon Sep 17 00:00:00 2001 From: MarcKe Date: Mon, 26 Jan 2015 04:39:08 +0100 Subject: [PATCH 145/243] healthd: fix LED color on 100% if soc reaches 100, the loop variable would reach 3. acessing the the fourth element of soc_leds is undefined behaviour Change-Id: Iebc521c66844c811afa0244bc7977d1f88144227 --- healthd/healthd_mode_charger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index df4a4b8d..9a5872f8 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -252,7 +252,7 @@ static int set_battery_soc_leds(int soc) static int old_color = 0; for (i = 0; i < (int)ARRAY_SIZE(soc_leds); i++) { - if (soc < soc_leds[i].soc) + if (soc <= soc_leds[i].soc) break; } color = soc_leds[i].color; From 74b61ddd59d8ffcbae2706b0dd8e9a260e1f4c3f Mon Sep 17 00:00:00 2001 From: MarcKe Date: Mon, 26 Jan 2015 04:48:02 +0100 Subject: [PATCH 146/243] healthd: remove useless gotos in set_backlight_on Change-Id: Id2a254eade02a10da699a8293ae988e9ee53be80 --- healthd/healthd_mode_charger.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 9a5872f8..9ad4bde0 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -238,8 +238,7 @@ static int set_tricolor_led(int on, int color) if (write(fd, buffer, strlen(buffer)) < 0) LOGE("Could not write to led node\n"); - if (fd >= 0) - close(fd); + close(fd); } } @@ -282,17 +281,14 @@ static int set_backlight_on(void) fd = open(BACKLIGHT_PATH, O_RDWR); if (fd < 0) { LOGE("Could not open backlight node : %s\n", strerror(errno)); - goto cleanup; + return 0; } LOGV("Enabling backlight\n"); snprintf(buffer, sizeof(buffer), "%d\n", BACKLIGHT_ON_LEVEL); if (write(fd, buffer,strlen(buffer)) < 0) { LOGE("Could not write to backlight node : %s\n", strerror(errno)); - goto cleanup; } -cleanup: - if (fd >= 0) - close(fd); + close(fd); return 0; } From b08cf09c8b6be1052a812887418da48f06f747ad Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sat, 24 Jan 2015 00:36:08 +0100 Subject: [PATCH 147/243] android_reboot: execute recovery pre command while rw mounted The TARGET_RECOVERY_PRE_COMMAND might need to write to mounted partitions, so execute it before re-mounting everything as read- only. Change-Id: I66b2e81b8c05b9aa6eeddbfb589619ce53e36e2b --- libcutils/android_reboot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libcutils/android_reboot.c b/libcutils/android_reboot.c index 9f8f968c..30738d78 100644 --- a/libcutils/android_reboot.c +++ b/libcutils/android_reboot.c @@ -110,9 +110,6 @@ int android_reboot(int cmd, int flags UNUSED, char *arg) int ret = 0; int reason = -1; - sync(); - remount_ro(); - #ifdef RECOVERY_PRE_COMMAND if (cmd == (int) ANDROID_RB_RESTART2) { if (arg && strlen(arg) > 0) { @@ -123,6 +120,9 @@ int android_reboot(int cmd, int flags UNUSED, char *arg) } #endif + sync(); + remount_ro(); + switch (cmd) { case ANDROID_RB_RESTART: reason = RB_AUTOBOOT; From 13d53a47a96094459fa94926414466661443a514 Mon Sep 17 00:00:00 2001 From: Ethan Chen Date: Mon, 26 Jan 2015 22:34:51 -0800 Subject: [PATCH 148/243] fs_mgr: Allow ext2/3/4 to mount as ext4 Change-Id: Ic2d921239671d3035ca6dc0b2aa2cc3b197e7bc0 --- fs_mgr/fs_mgr.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index 23e61faf..8005c961 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -363,8 +363,15 @@ int fs_mgr_mount_all(struct fstab *fstab) /* Skip fstab entries for partitions that we KNOW are wrong */ detected_fs_type = blkid_get_tag_value(NULL, "TYPE", fstab->recs[i].blk_device); - if (detected_fs_type && strcmp(fstab->recs[i].fs_type, detected_fs_type) != 0) { - continue; + if (detected_fs_type) { + int cmp_len = strlen(detected_fs_type); + /* ext formats are mutually compatible by design */ + if (!strncmp(detected_fs_type,"ext", 3) && cmp_len == 4) { + cmp_len = 3; + } + if (strncmp(fstab->recs[i].fs_type, detected_fs_type, cmp_len)) { + continue; + } } int last_idx_inspected; From 3b29a7570fe2771e7d2d2baf59a3853384758dd9 Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Fri, 30 Jan 2015 15:41:52 -0800 Subject: [PATCH 149/243] init: Changes for factory mode * Allow device to override factory.prop path * Ensure ro.boot.ftm always gets set Change-Id: I9ffcf0650fe9e6092aa1eda4a91147200a6311a9 --- init/Android.mk | 3 +++ init/property_service.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/init/Android.mk b/init/Android.mk index fbe6a2dc..db000c22 100755 --- a/init/Android.mk +++ b/init/Android.mk @@ -71,6 +71,9 @@ endif ifneq ($(strip $(TARGET_INIT_VENDOR_LIB)),) LOCAL_WHOLE_STATIC_LIBRARIES += $(TARGET_INIT_VENDOR_LIB) endif +ifneq ($(strip $(TARGET_PROP_PATH_FACTORY)),) +LOCAL_CFLAGS += -DOVERRIDE_PROP_PATH_FACTORY=\"$(TARGET_PROP_PATH_FACTORY)\" +endif include $(BUILD_EXECUTABLE) diff --git a/init/property_service.c b/init/property_service.c index 37907799..5fefd269 100644 --- a/init/property_service.c +++ b/init/property_service.c @@ -605,6 +605,9 @@ void load_all_props(void) load_properties_from_file(PROP_PATH_SYSTEM_DEFAULT, NULL); load_properties_from_file(PROP_PATH_FACTORY, "ro.*"); + /* ensure ro.boot.ftm gets set */ + property_set("ro.boot.ftm", "0"); + /* Read vendor-specific property runtime overrides. */ vendor_load_properties(); From 66af09cc0ba9e9b17cf322e7ae8ef25a0b9ed125 Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Fri, 30 Jan 2015 15:43:06 -0800 Subject: [PATCH 150/243] adb: Changes for factory mode * Always insecure in factory mode Change-Id: Ic5b6e83ef816240521424814d66294fd786966cd --- adb/adb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/adb/adb.c b/adb/adb.c index c2e5f4ab..67c4a685 100644 --- a/adb/adb.c +++ b/adb/adb.c @@ -1326,8 +1326,12 @@ int adb_main(int is_daemon, int server_port) exit(1); } #else - property_get("ro.adb.secure", value, "0"); - auth_enabled = !strcmp(value, "1"); + // Override auth in factory test mode + property_get("ro.boot.ftm", value, "0"); + if (!strcmp(value, "0")) { + property_get("ro.adb.secure", value, "0"); + auth_enabled = !strcmp(value, "1"); + } if (auth_enabled) adb_auth_init(); From 58e1572f41c3f81481f58c58922cdd1fb871ffce Mon Sep 17 00:00:00 2001 From: Ethan Chen Date: Wed, 28 Jan 2015 14:35:25 -0800 Subject: [PATCH 151/243] Revert "fs_mgr: Allow ext2/3/4 to mount as ext4" This reverts commit 13d53a47a96094459fa94926414466661443a514. Change-Id: I66d0c957d52fc7f2324d1641d8af9880b8b2f7d5 --- fs_mgr/fs_mgr.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index 8005c961..23e61faf 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -363,15 +363,8 @@ int fs_mgr_mount_all(struct fstab *fstab) /* Skip fstab entries for partitions that we KNOW are wrong */ detected_fs_type = blkid_get_tag_value(NULL, "TYPE", fstab->recs[i].blk_device); - if (detected_fs_type) { - int cmp_len = strlen(detected_fs_type); - /* ext formats are mutually compatible by design */ - if (!strncmp(detected_fs_type,"ext", 3) && cmp_len == 4) { - cmp_len = 3; - } - if (strncmp(fstab->recs[i].fs_type, detected_fs_type, cmp_len)) { - continue; - } + if (detected_fs_type && strcmp(fstab->recs[i].fs_type, detected_fs_type) != 0) { + continue; } int last_idx_inspected; From e34ce8bbc2b0c8c61c21c7968238b734df6b5cfe Mon Sep 17 00:00:00 2001 From: Ethan Chen Date: Wed, 28 Jan 2015 14:35:54 -0800 Subject: [PATCH 152/243] Revert "fs_mgr: skip an fstab entry if we detect a different filesystem type" This reverts commit d1bec30dacc7435ed75a4429c21c12057d754f02. Change-Id: Iadcdf9d96dfd455bae61241bf8d6e14086ce32e7 --- fs_mgr/Android.mk | 6 +++--- fs_mgr/fs_mgr.c | 9 --------- fs_mgr/include/fs_mgr.h | 1 - init/Android.mk | 4 +--- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/fs_mgr/Android.mk b/fs_mgr/Android.mk index 92aeb4e1..7cffc37a 100644 --- a/fs_mgr/Android.mk +++ b/fs_mgr/Android.mk @@ -8,8 +8,8 @@ LOCAL_SRC_FILES:= fs_mgr.c fs_mgr_verity.c fs_mgr_fstab.c LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_MODULE:= libfs_mgr -LOCAL_STATIC_LIBRARIES := liblogwrap libmincrypt libext4_utils_static libext2_blkid libext2_uuid -LOCAL_C_INCLUDES += system/extras/ext4_utils external/e2fsprogs/lib +LOCAL_STATIC_LIBRARIES := liblogwrap libmincrypt libext4_utils_static +LOCAL_C_INCLUDES += system/extras/ext4_utils LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include LOCAL_CFLAGS := -Werror @@ -30,7 +30,7 @@ LOCAL_FORCE_STATIC_EXECUTABLE := true LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/sbin LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED) -LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils liblog libc libmincrypt libext4_utils_static libext2_blkid libext2_uuid +LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils liblog libc libmincrypt libext4_utils_static LOCAL_CFLAGS := -Werror diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index 23e61faf..cb881548 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -35,7 +35,6 @@ #include #include #include -#include #include "mincrypt/rsa.h" #include "mincrypt/sha.h" @@ -329,7 +328,6 @@ int fs_mgr_mount_all(struct fstab *fstab) int mret = -1; int mount_errno = 0; int attempted_idx = -1; - char *detected_fs_type; if (!fstab) { return -1; @@ -360,13 +358,6 @@ int fs_mgr_mount_all(struct fstab *fstab) continue; } } - - /* Skip fstab entries for partitions that we KNOW are wrong */ - detected_fs_type = blkid_get_tag_value(NULL, "TYPE", fstab->recs[i].blk_device); - if (detected_fs_type && strcmp(fstab->recs[i].fs_type, detected_fs_type) != 0) { - continue; - } - int last_idx_inspected; mret = mount_with_alternatives(fstab, i, &last_idx_inspected, &attempted_idx); i = last_idx_inspected; diff --git a/fs_mgr/include/fs_mgr.h b/fs_mgr/include/fs_mgr.h index 71974ad9..0c7eb20d 100644 --- a/fs_mgr/include/fs_mgr.h +++ b/fs_mgr/include/fs_mgr.h @@ -72,7 +72,6 @@ int fs_mgr_add_entry(struct fstab *fstab, const char *mount_point, const char *fs_type, const char *blk_device); struct fstab_rec *fs_mgr_get_entry_for_mount_point(struct fstab *fstab, const char *path); -struct fstab_rec *fs_mgr_get_entry_for_mount_point_after(struct fstab_rec *start_rec, struct fstab *fstab, const char *path); int fs_mgr_is_voldmanaged(struct fstab_rec *fstab); int fs_mgr_is_nonremovable(struct fstab_rec *fstab); int fs_mgr_is_encryptable(struct fstab_rec *fstab); diff --git a/init/Android.mk b/init/Android.mk index db000c22..af3605f1 100755 --- a/init/Android.mk +++ b/init/Android.mk @@ -60,9 +60,7 @@ LOCAL_STATIC_LIBRARIES := \ libc \ libselinux \ libmincrypt \ - libext4_utils_static \ - libext2_blkid \ - libext2_uuid + libext4_utils_static LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk ifneq ($(strip $(TARGET_PLATFORM_DEVICE_BASE)),) From ee4a7e8b6249f011405a48230b1eb4d1017503ae Mon Sep 17 00:00:00 2001 From: Dan Pasanen Date: Wed, 28 Jan 2015 14:36:24 -0800 Subject: [PATCH 153/243] fs_mgr: Add fs_mgr_get_entry_for_mount_point_after to header * Add this function for recovery to use Change-Id: I314c5452a337245ecac5c9628ad0568018e1cf7b --- fs_mgr/include/fs_mgr.h | 1 + 1 file changed, 1 insertion(+) diff --git a/fs_mgr/include/fs_mgr.h b/fs_mgr/include/fs_mgr.h index 0c7eb20d..71974ad9 100644 --- a/fs_mgr/include/fs_mgr.h +++ b/fs_mgr/include/fs_mgr.h @@ -72,6 +72,7 @@ int fs_mgr_add_entry(struct fstab *fstab, const char *mount_point, const char *fs_type, const char *blk_device); struct fstab_rec *fs_mgr_get_entry_for_mount_point(struct fstab *fstab, const char *path); +struct fstab_rec *fs_mgr_get_entry_for_mount_point_after(struct fstab_rec *start_rec, struct fstab *fstab, const char *path); int fs_mgr_is_voldmanaged(struct fstab_rec *fstab); int fs_mgr_is_nonremovable(struct fstab_rec *fstab); int fs_mgr_is_encryptable(struct fstab_rec *fstab); From 70d19d8c0ef2ad5d735ce3e0abe880ebdaeed6c4 Mon Sep 17 00:00:00 2001 From: Dan Pasanen Date: Wed, 28 Jan 2015 16:41:29 -0800 Subject: [PATCH 154/243] fs_mgr: Skip filesystem check unless fs_type matches * Prevent accidentally destroying a partition of the wrong type. * Don't skip iterations of the internal mount_all loop, otherwise encryptability may not be properly handled. Change-Id: I8f3ddc396a5fb85f4ae0a0a11dd61fb4d6462d6d --- fs_mgr/Android.mk | 6 +++--- fs_mgr/fs_mgr.c | 15 +++++++++++++-- init/Android.mk | 4 +++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/fs_mgr/Android.mk b/fs_mgr/Android.mk index 7cffc37a..92aeb4e1 100644 --- a/fs_mgr/Android.mk +++ b/fs_mgr/Android.mk @@ -8,8 +8,8 @@ LOCAL_SRC_FILES:= fs_mgr.c fs_mgr_verity.c fs_mgr_fstab.c LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_MODULE:= libfs_mgr -LOCAL_STATIC_LIBRARIES := liblogwrap libmincrypt libext4_utils_static -LOCAL_C_INCLUDES += system/extras/ext4_utils +LOCAL_STATIC_LIBRARIES := liblogwrap libmincrypt libext4_utils_static libext2_blkid libext2_uuid +LOCAL_C_INCLUDES += system/extras/ext4_utils external/e2fsprogs/lib LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include LOCAL_CFLAGS := -Werror @@ -30,7 +30,7 @@ LOCAL_FORCE_STATIC_EXECUTABLE := true LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/sbin LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED) -LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils liblog libc libmincrypt libext4_utils_static +LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils liblog libc libmincrypt libext4_utils_static libext2_blkid libext2_uuid LOCAL_CFLAGS := -Werror diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index cb881548..87ee5429 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "mincrypt/rsa.h" #include "mincrypt/sha.h" @@ -261,6 +262,8 @@ static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_ int i; int mount_errno = 0; int mounted = 0; + int cmp_len; + char *detected_fs_type; if (!end_idx || !attempted_idx || start_idx >= fstab->num_entries) { errno = EINVAL; @@ -286,8 +289,16 @@ static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_ } if (fstab->recs[i].fs_mgr_flags & MF_CHECK) { - check_fs(fstab->recs[i].blk_device, fstab->recs[i].fs_type, - fstab->recs[i].mount_point); + /* Skip file system check unless we are sure we are the right type */ + detected_fs_type = blkid_get_tag_value(NULL, "TYPE", fstab->recs[i].blk_device); + if (detected_fs_type) { + cmp_len = (!strncmp(detected_fs_type, "ext", 3) && + strlen(detected_fs_type) == 4) ? 3 : strlen(detected_fs_type); + if (!strncmp(fstab->recs[i].fs_type, detected_fs_type, cmp_len)) { + check_fs(fstab->recs[i].blk_device, fstab->recs[i].fs_type, + fstab->recs[i].mount_point); + } + } } if (!__mount(fstab->recs[i].blk_device, fstab->recs[i].mount_point, &fstab->recs[i])) { *attempted_idx = i; diff --git a/init/Android.mk b/init/Android.mk index af3605f1..db000c22 100755 --- a/init/Android.mk +++ b/init/Android.mk @@ -60,7 +60,9 @@ LOCAL_STATIC_LIBRARIES := \ libc \ libselinux \ libmincrypt \ - libext4_utils_static + libext4_utils_static \ + libext2_blkid \ + libext2_uuid LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk ifneq ($(strip $(TARGET_PLATFORM_DEVICE_BASE)),) From 835ceb97bc10bd96e5785029f7a0dc5975d4c922 Mon Sep 17 00:00:00 2001 From: "Brint E. Kriebel" Date: Mon, 2 Feb 2015 14:40:41 -0800 Subject: [PATCH 155/243] init: Move install-recovery.sh back to the standard location L moved the location of install-recovery.sh from /system/etc/ to /system/bin. Since CWM recovery isn't looking for this location anyway, let's return the file to this standard location. This allows all other code in L to function properly. Maintain the change to the init to allow flash_recovery to be disabled in settings. Change-Id: I8a85db8addeb75a2fd60d809c5ed4edc619ef7ed --- rootdir/init.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootdir/init.rc b/rootdir/init.rc index b0f4bc78..32d33d84 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -606,7 +606,7 @@ service installd /system/bin/installd class main socket installd stream 600 system system -service flash_recovery /system/etc/install-cm-recovery.sh +service flash_recovery /system/bin/install-recovery.sh class main seclabel u:r:install_recovery:s0 oneshot From 7c92abfb15354c7d55a44a3bde556682ce076d8b Mon Sep 17 00:00:00 2001 From: Sravan Kumar Ambapuram Date: Wed, 7 May 2014 11:15:38 +0530 Subject: [PATCH 156/243] healthd: Disable the RTC wakeup timer The timer is used here to avoid battery drained to zero. But the periodic wakeup during suspend should not be needed as MSM PMIC already support that by trigger interrupt to avoid the critical low battery situation. This will save more power. And if the design is not support HW interrupt of low battery, need to enable the timer to periodic check. Change-Id: I040b4bc8548dc59b5e7cacb9a5a8a3557604f458 Signed-off-by: arter97 --- healthd/healthd.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/healthd/healthd.cpp b/healthd/healthd.cpp index c2dcc36f..1bccffa9 100644 --- a/healthd/healthd.cpp +++ b/healthd/healthd.cpp @@ -37,8 +37,15 @@ using namespace android; // Periodic chores intervals in seconds +#ifdef QCOM_HARDWARE #define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (60 * 10) +//For the designs without low battery detection,need to enable +//the default 60*10s wakeup timer to periodic check. +#define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW -1 +#else +#define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (60 * 1) #define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (60 * 10) +#endif static struct healthd_config healthd_config = { .periodic_chores_interval_fast = DEFAULT_PERIODIC_CHORES_INTERVAL_FAST, From bbdc54ac2ed731b9f32cc8fce77bea48366eeb63 Mon Sep 17 00:00:00 2001 From: Dragoslav Mitrinovic Date: Thu, 15 Jan 2015 09:29:43 -0600 Subject: [PATCH 157/243] logd: fix persistent blocking reader performance logd suffers major performance degradation when persistent (blocking) client reader connects to it (e.g. logcat). The root cause of the degradation is that each time when reader is notified of the arrival of new log entries, the reader commences its search for the new entries from the beginning of the linked list (oldest entries first). This commit alters the search to start from the end of the linked list and work backwards. This dramatically decreases logd CPU consumption when blocking reader is connected, and increases the maximum logging throughput (before the logs start getting lost) by a factor ~ 20. Change-Id: Ib60955ce05544e52a8b24acc3dcf5863e1e39c5c --- logd/LogBuffer.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index cd9ea209..161e8eea 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -449,7 +449,24 @@ log_time LogBuffer::flushTo( uid_t uid = reader->getUid(); pthread_mutex_lock(&mLogElementsLock); - for (it = mLogElements.begin(); it != mLogElements.end(); ++it) { + + if (start == LogTimeEntry::EPOCH) { + // client wants to start from the beginning + it = mLogElements.begin(); + } else { + // Client wants to start from some specified time. Chances are + // we are better off starting from the end of the time sorted list. + for (it = mLogElements.end(); it != mLogElements.begin(); /* do nothing */) { + --it; + LogBufferElement *element = *it; + if (element->getMonotonicTime() <= start) { + it++; + break; + } + } + } + + for (; it != mLogElements.end(); ++it) { LogBufferElement *element = *it; if (!privileged && (element->getUid() != uid)) { From c86e715be761781f0c803f8c41f8a49e22827269 Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Thu, 12 Feb 2015 01:39:47 +0200 Subject: [PATCH 158/243] healthd: charger: Make battery capacity in charging animation opt-in Change-Id: Ib3ba262be1babcbaa4db04d936c1b6b3f14c667f --- healthd/Android.mk | 4 ++++ healthd/healthd_mode_charger.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/healthd/Android.mk b/healthd/Android.mk index 0dac01d9..17e51d82 100644 --- a/healthd/Android.mk +++ b/healthd/Android.mk @@ -47,6 +47,10 @@ ifeq ($(strip $(BOARD_CHARGER_ENABLE_SUSPEND)),true) LOCAL_CFLAGS += -DCHARGER_ENABLE_SUSPEND endif +ifeq ($(strip $(BOARD_CHARGER_SHOW_PERCENTAGE)),true) +LOCAL_CFLAGS += -DCHARGER_SHOW_PERCENTAGE +endif + LOCAL_C_INCLUDES := $(call project-path-for,recovery) LOCAL_STATIC_LIBRARIES := libbatteryservice libbinder libminui libpng libz libutils libstdc++ libcutils liblog libm libc diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 9ad4bde0..2b71ce27 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -489,6 +489,7 @@ static void draw_battery(struct charger *charger) } } +#ifdef CHARGER_SHOW_PERCENTAGE #define STR_LEN 64 static void draw_capacity(struct charger *charger) { @@ -503,6 +504,7 @@ static void draw_capacity(struct charger *charger) android_green(); gr_text(x, y, cap_str, 0); } +#endif static void redraw_screen(struct charger *charger) { @@ -515,7 +517,9 @@ static void redraw_screen(struct charger *charger) draw_unknown(charger); } else { draw_battery(charger); +#ifdef CHARGER_SHOW_PERCENTAGE draw_capacity(charger); +#endif } gr_flip(); } From ee0f94afb149eb4a8160960a0fe258e406f1189d Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Sun, 15 Feb 2015 11:24:05 +0200 Subject: [PATCH 159/243] healthd: Stop logspam Change-Id: Ib4a4cb226f61f3e2a4a7c59ca0e0bae47b468d6a --- healthd/healthd_board_default.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/healthd/healthd_board_default.cpp b/healthd/healthd_board_default.cpp index 2084a700..3d073627 100644 --- a/healthd/healthd_board_default.cpp +++ b/healthd/healthd_board_default.cpp @@ -27,5 +27,5 @@ void healthd_board_init(struct healthd_config*) int healthd_board_battery_update(struct android::BatteryProperties*) { // return 0 to log periodic polled battery status to kernel log - return 0; + return 1; } From c8cafe05509559c9b0b13a2b350bb6d36731daec Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sun, 22 Mar 2015 01:42:28 -0700 Subject: [PATCH 160/243] healthd: Fix compilation issue Change-Id: I1e2c2ced2de198a662156fd90e510bbbb0347e5a --- healthd/healthd_mode_charger.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 0b640a95..a57f923d 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -88,6 +88,7 @@ char *locale; #define CHARGING_ENABLED_PATH "/sys/class/power_supply/battery/charging_enabled" #endif +#define LOGI(x...) do { KLOG_INFO("charger", x); } while (0) #define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0) #define LOGW(x...) do { KLOG_WARNING("charger", x); } while (0) #define LOGV(x...) do { KLOG_DEBUG("charger", x); } while (0) From cb944b2d483b670385a2e5dc52345ddabe8a0aac Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Sat, 21 Mar 2015 01:42:15 +0200 Subject: [PATCH 161/243] healthd: Update logging for 5.1 * According to ebeb0c0ea63af9fd8b2c8a7a20f919e48098ad9a logs should be LOGW to appear in the kernel messages Change-Id: I4f6c2772fe76a84383a1e0bc461df950e7551923 --- healthd/healthd_mode_charger.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index a57f923d..bc10d607 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -88,7 +88,6 @@ char *locale; #define CHARGING_ENABLED_PATH "/sys/class/power_supply/battery/charging_enabled" #endif -#define LOGI(x...) do { KLOG_INFO("charger", x); } while (0) #define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0) #define LOGW(x...) do { KLOG_WARNING("charger", x); } while (0) #define LOGV(x...) do { KLOG_DEBUG("charger", x); } while (0) @@ -273,7 +272,7 @@ static int set_backlight_on(void) if (access(BACKLIGHT_PATH, R_OK | W_OK) != 0) { - LOGI("Backlight control not support\n"); + LOGW("Backlight control not support\n"); return 0; } @@ -906,7 +905,7 @@ void healthd_mode_charger_init(struct healthd_config* config) ret = read_file_int(CHARGING_ENABLED_PATH, &charging_enabled); if (!ret && !charging_enabled) { /* if charging is disabled, reboot and exit power off charging */ - LOGI("android charging is disabled, exit!\n"); + LOGW("android charging is disabled, exit!\n"); android_reboot(ANDROID_RB_RESTART, 0, 0); } } From 354483f0260f531cd884c7fecb5c139702527841 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Fri, 19 Sep 2014 10:43:12 +0100 Subject: [PATCH 162/243] init: Let a device's init.rc redefine service entries In case of duplicate service definitions, init.rc's version always wins. This is a less-than-ideal situation and the main reason for some devices to override the default init.rc, which leads to out-of-sync situations whenever we happen to insert something into the main copy. So let services be overridden. To prevent accidental override of system services, use a specific keyword for this, "service_redefine" Change-Id: Ib1cab6bd3008956e9a2f61355781861ef8bcf8ca --- init/init_parser.c | 20 ++++++++++++++------ init/keywords.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/init/init_parser.c b/init/init_parser.c index bbdccf4c..5cbd75ff 100644 --- a/init/init_parser.c +++ b/init/init_parser.c @@ -42,7 +42,7 @@ struct import { const char *filename; }; -static void *parse_service(struct parse_state *state, int nargs, char **args); +static void *parse_service(struct parse_state *state, int nargs, char **args, bool redefine); static void parse_line_service(struct parse_state *state, int nargs, char **args); static void *parse_action(struct parse_state *state, int nargs, char **args); @@ -144,6 +144,7 @@ static int lookup_keyword(const char *s) case 's': if (!strcmp(s, "eclabel")) return K_seclabel; if (!strcmp(s, "ervice")) return K_service; + if (!strcmp(s, "ervice_redefine")) return K_service_redefine; if (!strcmp(s, "etcon")) return K_setcon; if (!strcmp(s, "etenforce")) return K_setenforce; if (!strcmp(s, "etenv")) return K_setenv; @@ -327,7 +328,8 @@ static void parse_new_section(struct parse_state *state, int kw, nargs > 1 ? args[1] : ""); switch(kw) { case K_service: - state->context = parse_service(state, nargs, args); + case K_service_redefine: + state->context = parse_service(state, nargs, args, (kw == K_service_redefine)); if (state->context) { state->parse_line = parse_line_service; return; @@ -673,7 +675,7 @@ int action_queue_empty() return list_empty(&action_queue); } -static void *parse_service(struct parse_state *state, int nargs, char **args) +static void *parse_service(struct parse_state *state, int nargs, char **args, bool redefine) { struct service *svc; if (nargs < 3) { @@ -686,13 +688,18 @@ static void *parse_service(struct parse_state *state, int nargs, char **args) } svc = service_find_by_name(args[1]); - if (svc) { + if (svc && !redefine) { parse_error(state, "ignored duplicate definition of service '%s'\n", args[1]); return 0; } nargs -= 2; - svc = calloc(1, sizeof(*svc) + sizeof(char*) * nargs); + + if (!svc) { + svc = calloc(1, sizeof(*svc) + sizeof(char*) * nargs); + redefine = false; + } + if (!svc) { parse_error(state, "out of memory\n"); return 0; @@ -704,7 +711,8 @@ static void *parse_service(struct parse_state *state, int nargs, char **args) svc->nargs = nargs; svc->onrestart.name = "onrestart"; list_init(&svc->onrestart.commands); - list_add_tail(&service_list, &svc->slist); + if (!redefine) + list_add_tail(&service_list, &svc->slist); return svc; } diff --git a/init/keywords.h b/init/keywords.h index e9d6469d..ae0f2a80 100644 --- a/init/keywords.h +++ b/init/keywords.h @@ -82,6 +82,7 @@ enum { KEYWORD(rmdir, COMMAND, 1, do_rmdir) KEYWORD(seclabel, OPTION, 0, 0) KEYWORD(service, SECTION, 0, 0) + KEYWORD(service_redefine, SECTION, 0, 0) KEYWORD(setcon, COMMAND, 1, do_setcon) KEYWORD(setenforce, COMMAND, 1, do_setenforce) KEYWORD(setenv, OPTION, 2, 0) From 0be62130acfcd608fa5f587477515b710e25c8a4 Mon Sep 17 00:00:00 2001 From: Janson Kang Date: Mon, 22 Dec 2014 09:34:07 +0800 Subject: [PATCH 163/243] Add permissions required for android keyboard gadget support --- rootdir/ueventd.rc | 1 + 1 file changed, 1 insertion(+) diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc index 4023ea6d..9b9bbcbf 100644 --- a/rootdir/ueventd.rc +++ b/rootdir/ueventd.rc @@ -37,6 +37,7 @@ subsystem adf /dev/uhid 0660 system net_bt_stack /dev/uinput 0660 system net_bt_stack /dev/alarm 0664 system radio +/dev/hidg* 0777 system system /dev/rtc0 0640 system system /dev/tty0 0660 root system /dev/graphics/* 0660 system graphics From cb9e4484747e31b427f772f4c6de996a1e69ab29 Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Thu, 30 Oct 2014 11:16:01 +0000 Subject: [PATCH 164/243] liblog: Forward xlog to regular android buffers on demand This may be useful when dealing with proprietary blobs like video where they spit a ton of useful debug information through xlog. Also, bring it up if MTKLogger is active Change-Id: I67bc397bfa935aa0716502f949fc7ab6c6b1dfd3 --- liblog/logd_write.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/liblog/logd_write.c b/liblog/logd_write.c index 520106e8..df077f79 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -35,7 +35,7 @@ #include #endif -#ifdef MOTOROLA_LOG +#if defined(MOTOROLA_LOG) || defined(MTK_HARDWARE) #if HAVE_LIBC_SYSTEM_PROPERTIES #include #endif @@ -609,3 +609,44 @@ int __android_log_bswrite(int32_t tag, const char *payload) return write_to_log(LOG_ID_EVENTS, vec, 4); } + +#ifdef MTK_HARDWARE +struct xlog_record { + const char *tag_str; + const char *fmt_str; + int prio; +}; + +void __attribute__((weak)) __xlog_buf_printf(int bufid, const struct xlog_record *xlog_record, ...) { + va_list args; + va_start(args, xlog_record); +#if HAVE_LIBC_SYSTEM_PROPERTIES + int len = 0; + int do_xlog = 0; + char results[PROP_VALUE_MAX]; + + + // MobileLog + len = __system_property_get ("debug.MB.running", results); + if (len && atoi(results)) + do_xlog = 1; + + // ModemLog + len = __system_property_get ("debug.mdlogger.Running", results); + if (len && atoi(results)) + do_xlog = 1; + + // Manual + len = __system_property_get ("persist.debug.xlog.enable", results); + if (len && atoi(results)) + do_xlog = 1; + + if (do_xlog > 0) +#endif + __android_log_vprint(xlog_record->prio, xlog_record->tag_str, xlog_record->fmt_str, args); + + // get rid of "unused parameter 'bufid'" + bufid = bufid; + return; +} +#endif From 5b3aa21bc70d42b3fcb1764a1be04ab8db5ebfb9 Mon Sep 17 00:00:00 2001 From: Chris Fries Date: Thu, 5 Sep 2013 13:19:21 -0500 Subject: [PATCH 165/243] fs_mgr: introduce fs_mgr_format to format wiped partitions Move fastboot's format logic into fs_mgr, to consolidate the knowledge about how to do this (and when to wipe metadata). Try to format these formattable paritions if they are wiped. If formatting fails, we will fall out to let recovery mode handle it. Bug: 20082763 Change-Id: I397cc197550e78d932e8a154fd234695c46dbe7b --- fs_mgr/Android.mk | 7 ++- fs_mgr/fs_mgr.c | 37 ++++++++++++- fs_mgr/fs_mgr_format.c | 119 ++++++++++++++++++++++++++++++++++++++++ fs_mgr/fs_mgr_fstab.c | 6 ++ fs_mgr/fs_mgr_priv.h | 1 + fs_mgr/include/fs_mgr.h | 4 ++ init/Android.mk | 4 +- init/devices.c | 2 +- init/util.c | 2 +- init/util.h | 2 +- 10 files changed, 177 insertions(+), 7 deletions(-) create mode 100644 fs_mgr/fs_mgr_format.c diff --git a/fs_mgr/Android.mk b/fs_mgr/Android.mk index 61bf1ee6..0ec6c4b1 100644 --- a/fs_mgr/Android.mk +++ b/fs_mgr/Android.mk @@ -4,8 +4,12 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= fs_mgr.c fs_mgr_verity.c fs_mgr_fstab.c +LOCAL_SRC_FILES += fs_mgr_format.c -LOCAL_C_INCLUDES := $(LOCAL_PATH)/include +LOCAL_C_INCLUDES := $(LOCAL_PATH)/include \ + system/vold \ + system/extras/ext4_utils \ + external/openssl/include LOCAL_MODULE:= libfs_mgr LOCAL_STATIC_LIBRARIES := liblogwrap libmincrypt libext4_utils_static @@ -35,6 +39,7 @@ LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/sbin LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED) LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils liblog libc libmincrypt libext4_utils_static +LOCAL_STATIC_LIBRARIES += libsparse_static libz libselinux LOCAL_CFLAGS := -Werror diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index ad029222..8533ff60 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -40,6 +40,9 @@ #include "mincrypt/sha.h" #include "mincrypt/sha256.h" +#include "ext4_utils.h" +#include "wipe.h" + #include "fs_mgr_priv.h" #include "fs_mgr_priv_verity.h" @@ -380,6 +383,8 @@ int fs_mgr_mount_all(struct fstab *fstab) } } int last_idx_inspected; + int top_idx = i; + mret = mount_with_alternatives(fstab, i, &last_idx_inspected, &attempted_idx); i = last_idx_inspected; mount_errno = errno; @@ -409,10 +414,38 @@ int fs_mgr_mount_all(struct fstab *fstab) continue; } - /* mount(2) returned an error, check if it's encryptable and deal with it */ + /* mount(2) returned an error, handle the encryptable/formattable case */ + bool wiped = partition_wiped(fstab->recs[top_idx].blk_device); + if (mret && mount_errno != EBUSY && mount_errno != EACCES && + fs_mgr_is_formattable(&fstab->recs[top_idx]) && wiped) { + /* top_idx and attempted_idx point at the same partition, but sometimes + * at two different lines in the fstab. Use the top one for formatting + * as that is the preferred one. + */ + ERROR("%s(): %s is wiped and %s %s is formattable. Format it.\n", __func__, + fstab->recs[top_idx].blk_device, fstab->recs[top_idx].mount_point, + fstab->recs[top_idx].fs_type); + if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) && + strcmp(fstab->recs[top_idx].key_loc, KEY_IN_FOOTER)) { + int fd = open(fstab->recs[top_idx].key_loc, O_WRONLY, 0644); + if (fd >= 0) { + INFO("%s(): also wipe %s\n", __func__, fstab->recs[top_idx].key_loc); + wipe_block_device(fd, get_file_size(fd)); + close(fd); + } else { + ERROR("%s(): %s wouldn't open (%s)\n", __func__, + fstab->recs[top_idx].key_loc, strerror(errno)); + } + } + if (fs_mgr_do_format(&fstab->recs[top_idx]) == 0) { + /* Let's replay the mount actions. */ + i = top_idx - 1; + continue; + } + } if (mret && mount_errno != EBUSY && mount_errno != EACCES && fs_mgr_is_encryptable(&fstab->recs[attempted_idx])) { - if(partition_wiped(fstab->recs[attempted_idx].blk_device)) { + if (wiped) { ERROR("%s(): %s is wiped and %s %s is encryptable. Suggest recovery...\n", __func__, fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point, fstab->recs[attempted_idx].fs_type); diff --git a/fs_mgr/fs_mgr_format.c b/fs_mgr/fs_mgr_format.c new file mode 100644 index 00000000..b5b92b53 --- /dev/null +++ b/fs_mgr/fs_mgr_format.c @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ext4_utils.h" +#include "ext4.h" +#include "make_ext4fs.h" +#include "fs_mgr_priv.h" + +extern struct fs_info info; /* magic global from ext4_utils */ +extern void reset_ext4fs_info(); + +static int format_ext4(char *fs_blkdev, char *fs_mnt_point) +{ + unsigned int nr_sec; + int fd, rc = 0; + + if ((fd = open(fs_blkdev, O_WRONLY, 0644)) < 0) { + ERROR("Cannot open block device. %s\n", strerror(errno)); + return -1; + } + + if ((ioctl(fd, BLKGETSIZE, &nr_sec)) == -1) { + ERROR("Cannot get block device size. %s\n", strerror(errno)); + close(fd); + return -1; + } + + /* Format the partition using the calculated length */ + reset_ext4fs_info(); + info.len = ((off64_t)nr_sec * 512); + + /* Use make_ext4fs_internal to avoid wiping an already-wiped partition. */ + rc = make_ext4fs_internal(fd, NULL, fs_mnt_point, 0, 0, 0, 0, 0, 0, 0, 0, NULL); + if (rc) { + ERROR("make_ext4fs returned %d.\n", rc); + } + close(fd); + + return rc; +} + +static int format_f2fs(char *fs_blkdev) +{ + char * args[3]; + int pid; + int rc = 0; + + args[0] = (char *)"/sbin/mkfs.f2fs"; + args[1] = fs_blkdev; + args[2] = (char *)0; + + pid = fork(); + if (pid < 0) { + return pid; + } + if (!pid) { + /* This doesn't return */ + execv("/sbin/mkfs.f2fs", args); + exit(1); + } + for(;;) { + pid_t p = waitpid(pid, &rc, 0); + if (p != pid) { + ERROR("Error waiting for child process - %d\n", p); + rc = -1; + break; + } + if (WIFEXITED(rc)) { + rc = WEXITSTATUS(rc); + INFO("%s done, status %d\n", args[0], rc); + if (rc) { + rc = -1; + } + break; + } + ERROR("Still waiting for %s...\n", args[0]); + } + + return rc; +} + +int fs_mgr_do_format(struct fstab_rec *fstab) +{ + int rc = -EINVAL; + + ERROR("%s: Format %s as '%s'.\n", __func__, fstab->blk_device, fstab->fs_type); + + if (!strncmp(fstab->fs_type, "f2fs", 4)) { + rc = format_f2fs(fstab->blk_device); + } else if (!strncmp(fstab->fs_type, "ext4", 4)) { + rc = format_ext4(fstab->blk_device, fstab->mount_point); + } else { + ERROR("File system type '%s' is not supported\n", fstab->fs_type); + } + + return rc; +} diff --git a/fs_mgr/fs_mgr_fstab.c b/fs_mgr/fs_mgr_fstab.c index ab8f128c..edd95911 100644 --- a/fs_mgr/fs_mgr_fstab.c +++ b/fs_mgr/fs_mgr_fstab.c @@ -68,6 +68,7 @@ static struct flag_list fs_mgr_flags[] = { { "zramsize=", MF_ZRAMSIZE }, { "verify", MF_VERIFY }, { "noemulatedsd", MF_NOEMULATEDSD }, + { "formattable", MF_FORMATTABLE }, { "defaults", 0 }, { 0, 0 }, }; @@ -432,3 +433,8 @@ int fs_mgr_is_noemulatedsd(struct fstab_rec *fstab) { return fstab->fs_mgr_flags & MF_NOEMULATEDSD; } + +int fs_mgr_is_formattable(struct fstab_rec *fstab) +{ + return fstab->fs_mgr_flags & (MF_FORMATTABLE); +} diff --git a/fs_mgr/fs_mgr_priv.h b/fs_mgr/fs_mgr_priv.h index 34938fad..fd583065 100644 --- a/fs_mgr/fs_mgr_priv.h +++ b/fs_mgr/fs_mgr_priv.h @@ -75,6 +75,7 @@ #define MF_FORCECRYPT 0x400 #define MF_NOEMULATEDSD 0x800 /* no emulated sdcard daemon, sd card is the only external storage */ +#define MF_FORMATTABLE 0x1000 #define DM_BUF_SIZE 4096 diff --git a/fs_mgr/include/fs_mgr.h b/fs_mgr/include/fs_mgr.h index 5e2ff416..5a6ad2d6 100644 --- a/fs_mgr/include/fs_mgr.h +++ b/fs_mgr/include/fs_mgr.h @@ -84,7 +84,11 @@ int fs_mgr_is_nonremovable(struct fstab_rec *fstab); int fs_mgr_is_verified(struct fstab_rec *fstab); int fs_mgr_is_encryptable(struct fstab_rec *fstab); int fs_mgr_is_noemulatedsd(struct fstab_rec *fstab); +int fs_mgr_is_formattable(struct fstab_rec *fstab); int fs_mgr_swapon_all(struct fstab *fstab); + +int fs_mgr_do_format(struct fstab_rec *fstab); + #ifdef __cplusplus } #endif diff --git a/init/Android.mk b/init/Android.mk index 489dc93e..228e645e 100644 --- a/init/Android.mk +++ b/init/Android.mk @@ -45,7 +45,9 @@ LOCAL_STATIC_LIBRARIES := \ libc \ libselinux \ libmincrypt \ - libext4_utils_static + libext4_utils_static \ + libsparse_static \ + libz LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk diff --git a/init/devices.c b/init/devices.c index 1012fee4..73fe223a 100644 --- a/init/devices.c +++ b/init/devices.c @@ -564,7 +564,7 @@ static void handle_device(const char *action, const char *devpath, make_device(devpath, path, block, major, minor, (const char **)links); if (links) { for (i = 0; links[i]; i++) - make_link(devpath, links[i]); + make_link_init(devpath, links[i]); } } diff --git a/init/util.c b/init/util.c index e1a3ee33..12cb11d6 100644 --- a/init/util.c +++ b/init/util.c @@ -335,7 +335,7 @@ void sanitize(char *s) } } -void make_link(const char *oldpath, const char *newpath) +void make_link_init(const char *oldpath, const char *newpath) { int ret; char buf[256]; diff --git a/init/util.h b/init/util.h index 04b8129b..a7e7c8b2 100644 --- a/init/util.h +++ b/init/util.h @@ -33,7 +33,7 @@ unsigned int decode_uid(const char *s); int mkdir_recursive(const char *pathname, mode_t mode); void sanitize(char *p); -void make_link(const char *oldpath, const char *newpath); +void make_link_init(const char *oldpath, const char *newpath); void remove_link(const char *oldpath, const char *newpath); int wait_for_file(const char *filename, int timeout); void open_devnull_stdio(void); From 52c51f96b57572babcd12984a0f67bb71faf6877 Mon Sep 17 00:00:00 2001 From: "Christopher R. Palmer" Date: Wed, 8 Apr 2015 20:45:22 -0400 Subject: [PATCH 166/243] init: Add a new keywork "log" that logs a message Change-Id: I41264fa6768d3c3720a55c9820073047d3fb1349 --- init/builtins.c | 8 ++++++++ init/init_parser.c | 1 + init/keywords.h | 2 ++ init/log.h | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/init/builtins.c b/init/builtins.c index 10a810ee..3ca0e9ce 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -954,6 +954,14 @@ int do_setsebool(int nargs, char **args) { return 0; } +int do_log(int nargs, char **args) { + int i; + for (i = 1; i < nargs; i++) { + ERROR("%s", args[i]); + } + return 0; +} + int do_loglevel(int nargs, char **args) { int log_level; char log_level_str[PROP_VALUE_MAX] = ""; diff --git a/init/init_parser.c b/init/init_parser.c index 5cbd75ff..179eb241 100644 --- a/init/init_parser.c +++ b/init/init_parser.c @@ -118,6 +118,7 @@ static int lookup_keyword(const char *s) if (!strcmp(s, "eycodes")) return K_keycodes; break; case 'l': + if (!strcmp(s, "og")) return K_log; if (!strcmp(s, "oglevel")) return K_loglevel; if (!strcmp(s, "oad_persist_props")) return K_load_persist_props; if (!strcmp(s, "oad_all_props")) return K_load_all_props; diff --git a/init/keywords.h b/init/keywords.h index ae0f2a80..1aae9b52 100644 --- a/init/keywords.h +++ b/init/keywords.h @@ -38,6 +38,7 @@ int do_write(int nargs, char **args); int do_copy(int nargs, char **args); int do_chown(int nargs, char **args); int do_chmod(int nargs, char **args); +int do_log(int nargs, char **args); int do_loglevel(int nargs, char **args); int do_load_persist_props(int nargs, char **args); int do_load_all_props(int nargs, char **args); @@ -103,6 +104,7 @@ enum { KEYWORD(copy, COMMAND, 2, do_copy) KEYWORD(chown, COMMAND, 2, do_chown) KEYWORD(chmod, COMMAND, 2, do_chmod) + KEYWORD(log, COMMAND, 1, do_log) KEYWORD(loglevel, COMMAND, 1, do_loglevel) KEYWORD(load_persist_props, COMMAND, 0, do_load_persist_props) KEYWORD(load_all_props, COMMAND, 0, do_load_all_props) diff --git a/init/log.h b/init/log.h index e9cb65a6..66b95e34 100644 --- a/init/log.h +++ b/init/log.h @@ -20,7 +20,7 @@ #include #define ERROR(x...) KLOG_ERROR("init", x) -#define NOTICE(x...) KLOG_NOTICE("init", x) +#define NOTICE(x...) KLOG_INFO("init", x) #define INFO(x...) KLOG_INFO("init", x) extern int log_callback(int type, const char *fmt, ...); From ab9423fdf310b294f56e06c6ec43060e1e5ac3b9 Mon Sep 17 00:00:00 2001 From: Tomasz Kondel Date: Thu, 6 Feb 2014 08:57:27 +0100 Subject: [PATCH 167/243] Close fd on error path in do_mount() This fix closes a file descriptor before returning error from do_mount() Change-Id: Ib370229f16bf9ac385162d6b163cc5b079a1e73e --- init/builtins.c | 1 + 1 file changed, 1 insertion(+) diff --git a/init/builtins.c b/init/builtins.c index 10a810ee..2a097136 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -489,6 +489,7 @@ int do_mount(int nargs, char **args) sprintf(tmp, "/dev/block/loop%d", n); loop = open(tmp, mode); if (loop < 0) { + close(fd); return -1; } From 1ccf3ce6ac3edad108899c93aca9d30d2f81acf6 Mon Sep 17 00:00:00 2001 From: Tomasz Kondel Date: Tue, 5 Nov 2013 13:17:45 +0100 Subject: [PATCH 168/243] Fix segfault in get_character_device_symlinks() A segmentation fault will occur when strchr function returns NULL. Change-Id: I76076acfff16056179bf24dff5df9f81d9a45125 --- init/devices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/devices.c b/init/devices.c index 9852eb42..4167f553 100644 --- a/init/devices.c +++ b/init/devices.c @@ -538,7 +538,7 @@ static char **get_character_device_symlinks(struct uevent *uevent) /* skip "/devices/platform/" */ parent = strchr(uevent->path + pdev->path_len, '/'); - if (!*parent) + if (!parent) goto err; if (!strncmp(parent, "/usb", 4)) { From 13403915dfce407cad04e2e456690d9365c8e88b Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 13 Nov 2014 14:54:10 -0800 Subject: [PATCH 169/243] Add LOCAL_MULTILIB := both to Darwin libbacktrace. This was previously set for libbacktrace_libc++, but apparently never was for libbacktrace. Change-Id: I85dc44b356710c6367f5cea3bc0a4d6c817ca202 --- libbacktrace/Android.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libbacktrace/Android.mk b/libbacktrace/Android.mk index 9588dd6d..81d15dc0 100755 --- a/libbacktrace/Android.mk +++ b/libbacktrace/Android.mk @@ -194,6 +194,8 @@ LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := \ BacktraceMap.cpp \ +LOCAL_MULTILIB := both + include $(BUILD_HOST_SHARED_LIBRARY) # Don't build for unbundled branches From 90d2a17c6e0778769f33ea9f90deec90707607bd Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Thu, 13 Nov 2014 15:50:17 -0800 Subject: [PATCH 170/243] System/core: Use memmove Should use memmove when you expect overlap. Change-Id: I268a173db40a4be54232958e37aa8a03c2a885ee --- libutils/String8.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libutils/String8.cpp b/libutils/String8.cpp index 9092cbc9..3323b82a 100644 --- a/libutils/String8.cpp +++ b/libutils/String8.cpp @@ -424,7 +424,7 @@ bool String8::removeAll(const char* other) { next = len; } - memcpy(buf + tail, buf + index + skip, next - index - skip); + memmove(buf + tail, buf + index + skip, next - index - skip); tail += next - index - skip; index = next; } From 44d81c90110ec6d4eda632e17b8ec01f408e231a Mon Sep 17 00:00:00 2001 From: Daisuke Okitsu Date: Mon, 5 Aug 2013 12:18:15 +0900 Subject: [PATCH 171/243] Sdcard: Initialize the padding output value Add initialization of the output value in handle_write. This value is referred to in FUSE so initialization is necessary. See also handle_open and handle_opendir. Change-Id: I6507f113da9f6823fbfa459624d6594fc20afa51 --- sdcard/sdcard.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c index 3b32612c..a89f0a82 100644 --- a/sdcard/sdcard.c +++ b/sdcard/sdcard.c @@ -1301,6 +1301,7 @@ static int handle_write(struct fuse* fuse, struct fuse_handler* handler, return -errno; } out.size = res; + out.padding = 0; fuse_reply(fuse, hdr->unique, &out, sizeof(out)); return NO_STATUS; } From c407795d0a1f0452464306b9347c65c2ec4058a3 Mon Sep 17 00:00:00 2001 From: Johan Redestig Date: Thu, 20 Nov 2014 14:26:16 +0100 Subject: [PATCH 172/243] notify: dynamically allocate filename buffer use asprintf to dynamically allocate filename buffer rather than just reserving 512 bytes on the stack to avoid potential overflow. Change-Id: Ieeb9c6c2e5f97a9574f8128d84eba0b8efdb7263 --- toolbox/notify.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/toolbox/notify.c b/toolbox/notify.c index c983ed56..8ce346c5 100644 --- a/toolbox/notify.c +++ b/toolbox/notify.c @@ -101,14 +101,17 @@ int notify_main(int argc, char *argv[]) else if(verbose >= 1) printf("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : ""); if(print_files && (event->mask & IN_MODIFY)) { - char filename[512]; + char* filename = file_names[event->wd + id_offset]; + char* alloc_buf = NULL; ssize_t read_len; char *display_name; int buflen; - strcpy(filename, file_names[event->wd + id_offset]); if(event->len) { - strcat(filename, "/"); - strcat(filename, event->name); + if(asprintf(&alloc_buf, "%s/%s", filename, event->name) < 0) { + fprintf(stderr, "asprintf failed, %s\n", strerror(errno)); + return 1; + } + filename = alloc_buf; } ffd = open(filename, O_RDONLY); display_name = (verbose >= 2 || event->len == 0) ? filename : event->name; @@ -132,6 +135,7 @@ int notify_main(int argc, char *argv[]) printf("%s: %s", display_name, buf); } close(ffd); + free(alloc_buf); } if(event_count && --event_count == 0) return 0; From 99ba5dd8d76991e526b948e9259221ef89e59ca3 Mon Sep 17 00:00:00 2001 From: Evisceration Date: Thu, 27 Nov 2014 17:19:30 +0100 Subject: [PATCH 173/243] init: remove flash_recovery service Change-Id: Id9c2afa370187b27900b5c2b6dc4b2f5c5070c52 --- rootdir/init.rc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rootdir/init.rc b/rootdir/init.rc index 029d7deb..8dbf2392 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -601,15 +601,15 @@ service installd /system/bin/installd class main socket installd stream 600 system system -service flash_recovery /system/bin/install-recovery.sh - class main - seclabel u:r:install_recovery:s0 - oneshot - disabled +#service flash_recovery /system/bin/install-recovery.sh +# class main +# seclabel u:r:install_recovery:s0 +# oneshot +# disabled # update recovery if enabled -on property:persist.sys.recovery_update=true - start flash_recovery +#on property:persist.sys.recovery_update=true +# start flash_recovery service racoon /system/bin/racoon class main From 426103e4ed5e3e422925023b710df6e3d1a88d08 Mon Sep 17 00:00:00 2001 From: Bao Haojun Date: Wed, 14 May 2014 21:03:48 +0800 Subject: [PATCH 174/243] Fix deadlocks. 1. Close pipe fds[1] as soon as possible. Otherwise it may block when reading from fds[0] even though the child process has exited early and closed its copy of fds[1]. 2. Waitpid after pipe is closed. Otherwise the screencap child process may block while writing fds[1], because the fds[0] is not closed yet. If we close fds[0] first, then the screencap child process will die because of SIGPIPE, and waitpid will return correctly. Change-Id: I433c95a5ba2eb3045727fc39a49fd9557fb1a1d1 Signed-off-by: Bao Haojun --- adb/framebuffer_service.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adb/framebuffer_service.c b/adb/framebuffer_service.c index 8cbe8403..61578aa5 100644 --- a/adb/framebuffer_service.c +++ b/adb/framebuffer_service.c @@ -76,6 +76,7 @@ void framebuffer_service(int fd, void *cookie) exit(1); } + close(fds[1]); fd_screencap = fds[0]; /* read w, h & format */ @@ -173,10 +174,9 @@ void framebuffer_service(int fd, void *cookie) } done: - TEMP_FAILURE_RETRY(waitpid(pid, NULL, 0)); - close(fds[0]); - close(fds[1]); + + TEMP_FAILURE_RETRY(waitpid(pid, NULL, 0)); pipefail: close(fd); } From 1a04c97bff743a8d86e814c58e354bfc24c837c0 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Wed, 10 Dec 2014 10:44:20 -0800 Subject: [PATCH 175/243] Allow updates for open file descriptors even if the calling process itself would not be able to open the file. Bug: 18688419 Change-Id: I640db19f19c1a677735fd0c14b7e2e38977d0f4d --- sdcard/sdcard.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c index a89f0a82..cb202dfe 100644 --- a/sdcard/sdcard.c +++ b/sdcard/sdcard.c @@ -936,7 +936,9 @@ static int handle_setattr(struct fuse* fuse, struct fuse_handler* handler, if (!node) { return -ENOENT; } - if (!check_caller_access_to_node(fuse, hdr, node, W_OK, has_rw)) { + + if (!(req->valid & FATTR_FH) && + !check_caller_access_to_node(fuse, hdr, node, W_OK, has_rw)) { return -EACCES; } From e3754970125040795eed74cd83a4264dd19b0632 Mon Sep 17 00:00:00 2001 From: Riley Andrews Date: Fri, 12 Dec 2014 13:12:36 -0800 Subject: [PATCH 176/243] fix memory leak in copy_remote_dir_local Bug https://code.google.com/p/android/issues/detail?id=82436 Change-Id: I4bfa865638742e1b7cedd17f5b33dcc10c7f711c --- adb/file_sync_client.c | 62 +++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/adb/file_sync_client.c b/adb/file_sync_client.c index ad59e817..7fb3e3b8 100644 --- a/adb/file_sync_client.c +++ b/adb/file_sync_client.c @@ -893,6 +893,21 @@ static int set_time_and_mode(const char *lpath, unsigned int time, unsigned int return r1 ? : r2; } +/* Return a copy of the path string with / appended if needed */ +static char *add_slash_to_path(const char *path) +{ + if (path[strlen(path) - 1] != '/') { + size_t len = strlen(path) + 2; + char *path_with_slash = malloc(len); + if (path_with_slash == NULL) + return NULL; + snprintf(path_with_slash, len, "%s/", path); + return path_with_slash; + } else { + return strdup(path); + } +} + static int copy_remote_dir_local(int fd, const char *rpath, const char *lpath, int copy_attrs) { @@ -900,28 +915,32 @@ static int copy_remote_dir_local(int fd, const char *rpath, const char *lpath, copyinfo *ci, *next; int pulled = 0; int skipped = 0; + char *rpath_clean = NULL; + char *lpath_clean = NULL; + int ret = 0; + + if (rpath[0] == '\0' || lpath[0] == '\0') { + ret = -1; + goto finish; + } /* Make sure that both directory paths end in a slash. */ - if (rpath[0] == 0 || lpath[0] == 0) return -1; - if (rpath[strlen(rpath) - 1] != '/') { - int tmplen = strlen(rpath) + 2; - char *tmp = malloc(tmplen); - if (tmp == 0) return -1; - snprintf(tmp, tmplen, "%s/", rpath); - rpath = tmp; + rpath_clean = add_slash_to_path(rpath); + if (!rpath_clean) { + ret = -1; + goto finish; } - if (lpath[strlen(lpath) - 1] != '/') { - int tmplen = strlen(lpath) + 2; - char *tmp = malloc(tmplen); - if (tmp == 0) return -1; - snprintf(tmp, tmplen, "%s/", lpath); - lpath = tmp; + lpath_clean = add_slash_to_path(lpath); + if (!lpath_clean) { + ret = -1; + goto finish; } - fprintf(stderr, "pull: building file list...\n"); /* Recursively build the list of files to copy. */ - if (remote_build_list(fd, &filelist, rpath, lpath)) { - return -1; + fprintf(stderr, "pull: building file list...\n"); + if (remote_build_list(fd, &filelist, rpath_clean, lpath_clean)) { + ret = -1; + goto finish; } for (ci = filelist; ci != 0; ci = next) { @@ -929,11 +948,13 @@ static int copy_remote_dir_local(int fd, const char *rpath, const char *lpath, if (ci->flag == 0) { fprintf(stderr, "pull: %s -> %s\n", ci->src, ci->dst); if (sync_recv(fd, ci->src, ci->dst, 0 /* no show progress */)) { - return 1; + ret = -1; + goto finish; } if (copy_attrs && set_time_and_mode(ci->dst, ci->time, ci->mode)) { - return 1; + ret = -1; + goto finish; } pulled++; } else { @@ -946,7 +967,10 @@ static int copy_remote_dir_local(int fd, const char *rpath, const char *lpath, pulled, (pulled == 1) ? "" : "s", skipped, (skipped == 1) ? "" : "s"); - return 0; +finish: + free(lpath_clean); + free(rpath_clean); + return ret; } int do_sync_pull(const char *rpath, const char *lpath, int show_progress, int copy_attrs) From ff29f4749252a43a5af12f933655d1ea75388652 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Fri, 30 Jan 2015 17:38:06 -0800 Subject: [PATCH 177/243] ensure /data/tombstones exists on all Android devices /data/tombstones is referenced by core platform code, but is not guaranteed to exist on all Android devices. Move the directory creation out of device specific files and into the core init.rc file. Bug: https://code.google.com/p/android/issues/detail?id=93207 Change-Id: I94ae5199a6a32c4fe555ca994fc4a8345e0c9690 --- rootdir/init.rc | 1 + 1 file changed, 1 insertion(+) diff --git a/rootdir/init.rc b/rootdir/init.rc index 8dbf2392..11ed9e27 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -285,6 +285,7 @@ on post-fs-data mkdir /data/app-lib 0771 system system mkdir /data/app 0771 system system mkdir /data/property 0700 root root + mkdir /data/tombstones 0771 system system # create dalvik-cache, so as to enforce our permissions mkdir /data/dalvik-cache 0771 root root From 1aeba47d42f3fb9f974776521566b02e6cb21fa5 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Thu, 5 Feb 2015 16:02:42 -0800 Subject: [PATCH 178/243] fs_mgr: error check umount calls / add retry logic Don't silently ignore umount errors. At a minimum, log them. Add strerror(errno) to another umount call, to make sure we get some actionable data. check_fs: try 5 times umounting the filesystem. It appears that the umount is failing, perhaps because some service is opening the file on the device or other error. Try unmounting it multiple times in case it's a transient problem and we can recover. Bug: 19199624 Bug: 19156134 Change-Id: I7213eb52d55116fb2419a36494d26d5e159981a7 --- fs_mgr/fs_mgr.c | 16 +++++++++++++--- fs_mgr/fs_mgr_priv.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index a190f09b..00d9f808 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -117,7 +117,17 @@ static void check_fs(char *blk_device, char *fs_type, char *target) ret = mount(blk_device, target, fs_type, tmpmnt_flags, tmpmnt_opts); INFO("%s(): mount(%s,%s,%s)=%d\n", __func__, blk_device, target, fs_type, ret); if (!ret) { - umount(target); + int i; + for (i = 0; i < 5; i++) { + // Try to umount 5 times before continuing on. + // Should we try rebooting if all attempts fail? + int result = umount(target); + if (result == 0) { + break; + } + ERROR("%s(): umount(%s)=%d: %s\n", __func__, target, result, strerror(errno)); + sleep(1); + } } /* @@ -412,8 +422,8 @@ int fs_mgr_mount_all(struct fstab *fstab) encryptable = FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED; } } else { - INFO("Could not umount %s - allow continue unencrypted\n", - fstab->recs[attempted_idx].mount_point); + WARNING("Could not umount %s (%s) - allow continue unencrypted\n", + fstab->recs[attempted_idx].mount_point, strerror(errno)); continue; } } diff --git a/fs_mgr/fs_mgr_priv.h b/fs_mgr/fs_mgr_priv.h index 34938fad..4ba6f92b 100644 --- a/fs_mgr/fs_mgr_priv.h +++ b/fs_mgr/fs_mgr_priv.h @@ -21,6 +21,7 @@ #include #define INFO(x...) KLOG_INFO("fs_mgr", x) +#define WARNING(x...) KLOG_WARNING("fs_mgr", x) #define ERROR(x...) KLOG_ERROR("fs_mgr", x) #define CRYPTO_TMPFS_OPTIONS "size=256m,mode=0771,uid=1000,gid=1000" From 4b19e0ce68946d05e80f0548090ac3b533798e30 Mon Sep 17 00:00:00 2001 From: SungHyun Kwon Date: Tue, 3 Mar 2015 13:56:42 +0900 Subject: [PATCH 179/243] Fix memory leak on jdwp_process_free() if many jdwp connection are created(), the memory will be leaked. When it deletes heap memory on jdwp_process_free(), the proc->fde just set to null. so it need to free() in fdevent_destory(). Change-Id: Ibc7475086a9509faae887b06c542d6c107d763aa --- adb/fdevent.c | 1 + 1 file changed, 1 insertion(+) diff --git a/adb/fdevent.c b/adb/fdevent.c index 43e600cb..0a5d1e9e 100644 --- a/adb/fdevent.c +++ b/adb/fdevent.c @@ -579,6 +579,7 @@ void fdevent_destroy(fdevent *fde) FATAL("fde %p not created by fdevent_create()\n", fde); } fdevent_remove(fde); + free(fde); } void fdevent_install(fdevent *fde, int fd, fd_func func, void *arg) From 32005433d04ffdb6239705f9959e5c205debc3b8 Mon Sep 17 00:00:00 2001 From: Scott Mertz Date: Sat, 21 Mar 2015 17:33:47 -0700 Subject: [PATCH 180/243] healthd: allow custom charger Change-Id: I1380bea300bfaa6819d50bdc813329c93050286a --- healthd/Android.mk | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/healthd/Android.mk b/healthd/Android.mk index 17e51d82..06f1fad3 100644 --- a/healthd/Android.mk +++ b/healthd/Android.mk @@ -15,10 +15,15 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ healthd.cpp \ healthd_mode_android.cpp \ - healthd_mode_charger.cpp \ BatteryMonitor.cpp \ BatteryPropertiesRegistrar.cpp +ifeq ($(strip $(BOARD_HEALTHD_CUSTOM_CHARGER)),) + LOCAL_SRC_FILES += healthd_mode_charger.cpp +else + LOCAL_SRC_FILES += ../../../$(BOARD_HEALTHD_CUSTOM_CHARGER) +endif + LOCAL_MODULE := healthd LOCAL_MODULE_TAGS := optional LOCAL_FORCE_STATIC_EXECUTABLE := true @@ -81,8 +86,13 @@ include $$(BUILD_PREBUILT) endef _img_modules := +ifeq ($(strip $(BOARD_HEALTHD_CUSTOM_CHARGER_RES)),) +IMAGES_DIR := images +else +IMAGES_DIR := ../../../$(BOARD_HEALTHD_CUSTOM_CHARGER_RES) +endif _images := -$(foreach _img, $(call find-subdir-subdir-files, "images", "*.png"), \ +$(foreach _img, $(call find-subdir-subdir-files, "$(IMAGES_DIR)", "*.png"), \ $(eval $(call _add-charger-image,$(_img)))) include $(CLEAR_VARS) From fc0122f8d2b147c9e7a3c07c35ffc6673a4981d2 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Thu, 26 Mar 2015 14:04:13 -0700 Subject: [PATCH 181/243] libaudit: limit to 5 selinux denials per sec watchdog is triggering on shamu. This may be due to an excessive number of SELinux denials. Drop the limit from 20/sec to 5/sec. Bug: 19950451 Bug: 19949988 Change-Id: I979f11e17c241ff2ebda4dec9694ef441dc5d0ed --- logd/libaudit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logd/libaudit.c b/logd/libaudit.c index d00d5795..cf76305d 100644 --- a/logd/libaudit.c +++ b/logd/libaudit.c @@ -177,7 +177,7 @@ int audit_setup(int fd, uint32_t pid) */ status.pid = pid; status.mask = AUDIT_STATUS_PID | AUDIT_STATUS_RATE_LIMIT; - status.rate_limit = 20; // audit entries per second + status.rate_limit = 5; // audit entries per second /* Let the kernel know this pid will be registering for audit events */ rc = audit_send(fd, AUDIT_SET, &status, sizeof(status)); From 68248e178eaf12793d1976af211653ca156176c8 Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Fri, 17 Apr 2015 05:25:03 -0700 Subject: [PATCH 182/243] fastboot: Add lz4 libs * Required by transparent compresssion in make_ext4fs. Change-Id: I408b5374524b5b8abaf008cf8f4c10ff90376d3e --- fastboot/Android.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastboot/Android.mk b/fastboot/Android.mk index e11691fb..1aba42b2 100644 --- a/fastboot/Android.mk +++ b/fastboot/Android.mk @@ -55,7 +55,8 @@ LOCAL_STATIC_LIBRARIES := \ libunz \ libext4_utils_host \ libsparse_host \ - libz + libz \ + liblz4-host ifneq ($(HOST_OS),windows) LOCAL_STATIC_LIBRARIES += libselinux From 3f51506d7292dc12ab12630bdc8280b3e48ffb8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Szymczyk?= Date: Thu, 15 Jan 2015 14:21:54 +0100 Subject: [PATCH 183/243] Reserve space on disk using fallocate There were crashes when android failed to extract zip archives due to out of free space on disk, with stacks like: #00 pc 00000000000156b0 /system/lib64/libc.so (memcpy+176) #01 pc 000000000002e5b8 /system/lib64/libandroidfw.so #02 pc 000000000002f488 /system/lib64/libandroidfw.so (ExtractToMemory+328) #03 pc 000000000002f5c8 /system/lib64/libandroidfw.so (ExtractEntryToFile+268) #04 pc 00000000000287d8 /system/lib64/libandroidfw.so (android::ZipFileRO::\ uncompressEntry(void*, int) const+12) Space for the file is now allocated using fallocate rather than ftruncate, since ftruncate dont actually reserve space on disk. When writes to the mmaped pointer fails to be realized due to out of space SIGBUS is the result. With this change we make sure that there is space available before mmaping the pointer. Change-Id: Ic5e8c33dbe729edb57919dacff73811b34cc2dc2 --- libziparchive/zip_archive.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index 87dac0e7..7ecab04a 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc @@ -1124,7 +1124,22 @@ int32_t ExtractEntryToFile(ZipArchiveHandle handle, return kIoError; } - int result = TEMP_FAILURE_RETRY(ftruncate(fd, declared_length + current_offset)); + int result = 0; +#if defined(__linux__) + // Make sure we have enough space on the volume to extract the compressed + // entry. Note that the call to ftruncate below will change the file size but + // will not allocate space on disk. + if (declared_length > 0) { + result = TEMP_FAILURE_RETRY(fallocate(fd, 0, current_offset, declared_length)); + if (result == -1) { + ALOGW("Zip: unable to allocate space for file to %" PRId64 ": %s", + static_cast(declared_length + current_offset), strerror(errno)); + return kIoError; + } + } +#endif // defined(__linux__) + + result = TEMP_FAILURE_RETRY(ftruncate(fd, declared_length + current_offset)); if (result == -1) { ALOGW("Zip: unable to truncate file to %" PRId64 ": %s", (int64_t)(declared_length + current_offset), strerror(errno)); From 2ded621e638644e618bf86f10957269b010ff76d Mon Sep 17 00:00:00 2001 From: Nikhilesh Reddy Date: Thu, 11 Dec 2014 13:17:06 -0800 Subject: [PATCH 184/243] Allocate a new AIDs for RFS module Allocate new AIDs to allow the RFS module to run as after dropping privelages from ROOT and to enforce strict permissions on shared and private RFS files. Change-Id: Ic4febd565df9f232f6c7571355ec10d8fd2e21bd --- include/private/android_filesystem_config.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index 3db6da2a..44cb4ba0 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -102,6 +102,8 @@ #define AID_QCOM_DIAG 3009 /* can read/write /dev/diag */ #define AID_IMS 3010 /* can read/write /dev/socket/imsrtp */ #define AID_SENSORS 3011 /* access to /dev/socket/sensor_ctl_socket & QCCI/QCSI */ +#define AID_RFS 3012 /* Remote Filesystem for peripheral processors */ +#define AID_RFS_SHARED 3013 /* Shared files for Remote Filesystem for peripheral processors */ #endif #define AID_EVERYBODY 9997 /* shared between all apps in the same profile */ @@ -192,6 +194,8 @@ static const struct android_id_info android_ids[] = { { "qcom_diag", AID_QCOM_DIAG, }, #if !defined(QCOM_LEGACY_UIDS) { "sensors", AID_SENSORS, }, + { "rfs", AID_RFS, }, + { "rfs_shared", AID_RFS_SHARED, }, #endif { "everybody", AID_EVERYBODY, }, { "misc", AID_MISC, }, From 0df4553938d4927b1e69d3b9b8056476736c0b67 Mon Sep 17 00:00:00 2001 From: tobitege Date: Thu, 23 Apr 2015 08:01:33 +0200 Subject: [PATCH 185/243] findParam: don't check empty param name Change-Id: Ie02bf706c1c0899dc2584b365894a1b6ce9caa8d Patchset: 1 http://review.cyanogenmod.org/#/c/95913/ --- libsysutils/src/NetlinkEvent.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp index 9d596ef5..72bf4239 100644 --- a/libsysutils/src/NetlinkEvent.cpp +++ b/libsysutils/src/NetlinkEvent.cpp @@ -597,6 +597,9 @@ bool NetlinkEvent::decode(char *buffer, int size, int format) { const char *NetlinkEvent::findParam(const char *paramName) { size_t len = strlen(paramName); + if (len == 0) { + return NULL; + } for (int i = 0; i < NL_PARAMS_MAX && mParams[i] != NULL; ++i) { const char *ptr = mParams[i] + len; if (!strncmp(mParams[i], paramName, len) && *ptr == '=') From 01e3a95295ea8f1e93ee1fea0e951dcac643deef Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Thu, 13 Nov 2014 15:50:17 -0800 Subject: [PATCH 186/243] System/core: Use memmove Should use memmove when you expect overlap. Change-Id: I268a173db40a4be54232958e37aa8a03c2a885ee --- libutils/String8.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libutils/String8.cpp b/libutils/String8.cpp index 9092cbc9..3323b82a 100644 --- a/libutils/String8.cpp +++ b/libutils/String8.cpp @@ -424,7 +424,7 @@ bool String8::removeAll(const char* other) { next = len; } - memcpy(buf + tail, buf + index + skip, next - index - skip); + memmove(buf + tail, buf + index + skip, next - index - skip); tail += next - index - skip; index = next; } From 11303d37ca752ceb518f06974dad4b35b869ca0a Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 25 Apr 2015 11:49:04 -0700 Subject: [PATCH 187/243] Improve toolbox SIGPIPE behavior. None of our tools -- except for top, which I'd fixed previously -- handles SIGPIE correctly. Let's just handle SIGPIPE in the driver. Bug: https://code.google.com/p/android/issues/detail?id=157920 Change-Id: I322ea411f53c71585a64118c217d54389f675d4e --- toolbox/toolbox.c | 15 +++++++++++++++ toolbox/top.c | 6 ------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/toolbox/toolbox.c b/toolbox/toolbox.c index 0eac390e..915da440 100644 --- a/toolbox/toolbox.c +++ b/toolbox/toolbox.c @@ -1,6 +1,8 @@ +#include #include #include #include +#include int main(int, char **); @@ -31,11 +33,24 @@ static struct { 0, 0 }, }; +static void SIGPIPE_handler(int signal) { + // Those desktop Linux tools that catch SIGPIPE seem to agree that it's + // a successful way to exit, not a failure. (Which makes sense --- we were + // told to stop by a reader, rather than failing to continue ourselves.) + _exit(0); +} + int main(int argc, char **argv) { int i; char *name = argv[0]; + // Let's assume that none of this code handles broken pipes. At least ls, + // ps, and top were broken (though I'd previously added this fix locally + // to top). We exit rather than use SIG_IGN because tools like top will + // just keep on writing to nowhere forever if we don't stop them. + signal(SIGPIPE, SIGPIPE_handler); + if((argc > 1) && (argv[1][0] == '@')) { name = argv[1] + 1; argc--; diff --git a/toolbox/top.c b/toolbox/top.c index b1a275c1..1e99d4cc 100644 --- a/toolbox/top.c +++ b/toolbox/top.c @@ -109,15 +109,9 @@ static int proc_thr_cmp(const void *a, const void *b); static int numcmp(long long a, long long b); static void usage(char *cmd); -static void exit_top(int signal) { - exit(EXIT_FAILURE); -} - int top_main(int argc, char *argv[]) { num_used_procs = num_free_procs = 0; - signal(SIGPIPE, exit_top); - max_procs = 0; delay = 3; iterations = -1; From 35493c4c327406a46c32a219db4be30cad5a0256 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Mon, 20 Apr 2015 17:19:46 +0200 Subject: [PATCH 188/243] Disable backlight when blanking panel. This used to be the behaviour up to and including cm-11.0 (see e.g. commit f7ce72ca), but in newer versions the backlight is only turned on and never off (see commit 1e961c04). Fix it. Change-Id: I6c3bf6abbb4e11dc010c360ecfe9f3bb3e2f3548 --- healthd/healthd_mode_charger.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index bc10d607..75f001d0 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -265,7 +265,7 @@ static int set_battery_soc_leds(int soc) } #define BACKLIGHT_ON_LEVEL 100 -static int set_backlight_on(void) +static int set_backlight(bool on) { int fd; char buffer[10]; @@ -283,7 +283,7 @@ static int set_backlight_on(void) return 0; } LOGV("Enabling backlight\n"); - snprintf(buffer, sizeof(buffer), "%d\n", BACKLIGHT_ON_LEVEL); + snprintf(buffer, sizeof(buffer), "%d\n", on ? BACKLIGHT_ON_LEVEL : 0); if (write(fd, buffer,strlen(buffer)) < 0) { LOGE("Could not write to backlight node : %s\n", strerror(errno)); } @@ -565,6 +565,7 @@ static void update_screen_state(struct charger *charger, int64_t now) if (batt_anim->cur_cycle == batt_anim->num_cycles) { reset_animation(batt_anim); charger->next_screen_transition = -1; + set_backlight(false); gr_fb_blank(true); LOGV("[%" PRId64 "] animation done\n", now); if (charger->charger_connected) @@ -599,7 +600,7 @@ static void update_screen_state(struct charger *charger, int64_t now) /* unblank the screen on first cycle */ if (batt_anim->cur_cycle == 0) { gr_fb_blank(false); - set_backlight_on(); + set_backlight(true); } /* draw the new frame (@ cur_frame) */ @@ -733,6 +734,7 @@ static void process_key(struct charger *charger, int code, int64_t now) } else { reset_animation(batt_anim); charger->next_screen_transition = -1; + set_backlight(false); gr_fb_blank(true); if (charger->charger_connected) request_suspend(true); @@ -779,6 +781,7 @@ static void handle_power_supply_state(struct charger *charger, int64_t now) request_suspend(false); if (charger->next_pwr_check == -1) { if (mode == QUICKBOOT) { + set_backlight(false); gr_fb_blank(true); request_suspend(true); /* exit here. There is no need to keep running when charger From 87d7d6758636d62740e37c686c18d4e38b011523 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 20 Nov 2014 10:47:55 -0800 Subject: [PATCH 189/243] Add a pre-C++11 constexpr compatibility macro. Needed for cases where something should be constexpr if possible, but not being constexpr is fine if in pre-C++11 code (such as a const static float member variable). Bug: 18466763 Change-Id: I635d062575ba2fbc4cbe3a89f730128c404d95e1 Signed-off-by: arter97 --- include/utils/Compat.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/utils/Compat.h b/include/utils/Compat.h index fb7748ea..eb8fa46d 100644 --- a/include/utils/Compat.h +++ b/include/utils/Compat.h @@ -47,6 +47,17 @@ static inline ssize_t pread64(int fd, void* buf, size_t nbytes, off64_t offset) # define ZD_TYPE long #endif +/* + * Needed for cases where something should be constexpr if possible, but not + * being constexpr is fine if in pre-C++11 code (such as a const static float + * member variable). + */ +#if __cplusplus >= 201103L +#define CONSTEXPR constexpr +#else +#define CONSTEXPR +#endif + /* * TEMP_FAILURE_RETRY is defined by some, but not all, versions of * . (Alas, it is not as standard as we'd hoped!) So, if it's From 90623627498cd7a0d1e4524ce1110fbd1b21b133 Mon Sep 17 00:00:00 2001 From: arter97 Date: Thu, 30 Apr 2015 16:34:17 +0900 Subject: [PATCH 190/243] libcutils: fix compilation errors By removing -Werror and enforcing GNU C89 standards Signed-off-by: arter97 --- libcutils/Android.mk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libcutils/Android.mk b/libcutils/Android.mk index bee2bd75..5a803f83 100644 --- a/libcutils/Android.mk +++ b/libcutils/Android.mk @@ -79,7 +79,7 @@ LOCAL_SRC_FILES := $(commonSources) $(commonHostSources) dlmalloc_stubs.c LOCAL_STATIC_LIBRARIES := liblog LOCAL_CFLAGS += $(hostSmpFlag) ifneq ($(HOST_OS),windows) -LOCAL_CFLAGS += -Werror +LOCAL_CFLAGS += -std=gnu89 endif LOCAL_MULTILIB := both LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk @@ -92,7 +92,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := tst_str_parms LOCAL_CFLAGS += -DTEST_STR_PARMS ifneq ($(HOST_OS),windows) -LOCAL_CFLAGS += -Werror +LOCAL_CFLAGS += -std=gnu89 endif LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c LOCAL_STATIC_LIBRARIES := liblog @@ -151,7 +151,7 @@ endif LOCAL_C_INCLUDES := $(libcutils_c_includes) LOCAL_STATIC_LIBRARIES := liblog -LOCAL_CFLAGS += $(targetSmpFlag) -Werror +LOCAL_CFLAGS += $(targetSmpFlag) -std=gnu89 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk include $(BUILD_STATIC_LIBRARY) @@ -161,14 +161,14 @@ LOCAL_MODULE := libcutils # liblog symbols present in libcutils. LOCAL_WHOLE_STATIC_LIBRARIES := libcutils liblog LOCAL_SHARED_LIBRARIES := liblog -LOCAL_CFLAGS += $(targetSmpFlag) -Werror +LOCAL_CFLAGS += $(targetSmpFlag) -std=gnu89 LOCAL_C_INCLUDES := $(libcutils_c_includes) LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := tst_str_parms -LOCAL_CFLAGS += -DTEST_STR_PARMS -Werror +LOCAL_CFLAGS += -DTEST_STR_PARMS -std=gnu89 LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c LOCAL_SHARED_LIBRARIES := liblog LOCAL_MODULE_TAGS := optional From fde032f93a0d32129c71aac9fd4ab584f8650847 Mon Sep 17 00:00:00 2001 From: arter97 Date: Thu, 30 Apr 2015 16:35:21 +0900 Subject: [PATCH 191/243] logd: enable -Os and GNU C89 back Aggressive -O2, -O3 optimizations on GCC 5.1 and GNU C11 standards causes a seg-fault on logd. Signed-off-by: arter97 --- logd/Android.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/logd/Android.mk b/logd/Android.mk index 188511f0..6739f84d 100644 --- a/logd/Android.mk +++ b/logd/Android.mk @@ -27,6 +27,7 @@ LOCAL_SHARED_LIBRARIES := \ libutils LOCAL_CFLAGS := -Werror $(shell sed -n 's/^\([0-9]*\)[ \t]*auditd[ \t].*/-DAUDITD_LOG_TAG=\1/p' $(LOCAL_PATH)/event.logtags) +LOCAL_CFLAGS += -Os -std=gnu89 include $(BUILD_EXECUTABLE) From a7984d970a88a19ce3e03694fb5b98dfb1ca9735 Mon Sep 17 00:00:00 2001 From: tobitege Date: Thu, 23 Apr 2015 08:01:33 +0200 Subject: [PATCH 192/243] findParam: don't check empty param name Change-Id: Ie02bf706c1c0899dc2584b365894a1b6ce9caa8d --- libsysutils/src/NetlinkEvent.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp index 9d596ef5..72bf4239 100644 --- a/libsysutils/src/NetlinkEvent.cpp +++ b/libsysutils/src/NetlinkEvent.cpp @@ -597,6 +597,9 @@ bool NetlinkEvent::decode(char *buffer, int size, int format) { const char *NetlinkEvent::findParam(const char *paramName) { size_t len = strlen(paramName); + if (len == 0) { + return NULL; + } for (int i = 0; i < NL_PARAMS_MAX && mParams[i] != NULL; ++i) { const char *ptr = mParams[i] + len; if (!strncmp(mParams[i], paramName, len) && *ptr == '=') From 985287bfb15fef12cf90cd68c8b7206c3061bded Mon Sep 17 00:00:00 2001 From: quanganh2627 Date: Wed, 15 Apr 2015 02:15:13 +0700 Subject: [PATCH 193/243] Rename libext2_uuid -> libext2_uuid_static lib Change-Id: I2dd416558321c424bca97efa973ee5a68b742a64 --- fs_mgr/Android.mk | 4 ++-- init/Android.mk | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs_mgr/Android.mk b/fs_mgr/Android.mk index e1d20299..b004f6e4 100644 --- a/fs_mgr/Android.mk +++ b/fs_mgr/Android.mk @@ -8,7 +8,7 @@ LOCAL_SRC_FILES:= fs_mgr.c fs_mgr_verity.c fs_mgr_fstab.c LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_MODULE:= libfs_mgr -LOCAL_STATIC_LIBRARIES := liblogwrap libmincrypt libext4_utils_static libext2_blkid libext2_uuid +LOCAL_STATIC_LIBRARIES := liblogwrap libmincrypt libext4_utils_static libext2_blkid libext2_uuid_static LOCAL_C_INCLUDES += system/extras/ext4_utils external/e2fsprogs/lib LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include LOCAL_CFLAGS := -Werror @@ -34,7 +34,7 @@ LOCAL_FORCE_STATIC_EXECUTABLE := true LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/sbin LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED) -LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils liblog libc libmincrypt libext4_utils_static libext2_blkid libext2_uuid +LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils liblog libc libmincrypt libext4_utils_static libext2_blkid libext2_uuid_static LOCAL_CFLAGS := -Werror diff --git a/init/Android.mk b/init/Android.mk index db000c22..61ae6c25 100755 --- a/init/Android.mk +++ b/init/Android.mk @@ -62,7 +62,7 @@ LOCAL_STATIC_LIBRARIES := \ libmincrypt \ libext4_utils_static \ libext2_blkid \ - libext2_uuid + libext2_uuid_static LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk ifneq ($(strip $(TARGET_PLATFORM_DEVICE_BASE)),) From 5cccf81c7d360841007621dea6068b9cf6f5e7f4 Mon Sep 17 00:00:00 2001 From: Chao Chen Date: Wed, 29 Apr 2015 14:59:52 -0700 Subject: [PATCH 194/243] fastboot: Add MMX fastboot USB ID Change-Id: I9cdbac6054e7f081411c34f641874e2aa65049a6 (cherry picked from commit 2e5c51a7597a53405349d11586524948f55c434a) --- fastboot/fastboot.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c index 4d83f4f4..bbbd8073 100644 --- a/fastboot/fastboot.c +++ b/fastboot/fastboot.c @@ -216,7 +216,8 @@ int match_fastboot_with_serial(usb_ifc_info *info, const char *local_serial) (info->dev_vendor != 0x0b05) && // Asus (info->dev_vendor != 0x0bb4) && // HTC (info->dev_vendor != 0x0421) && // Nokia - (info->dev_vendor != 0x1ebf)) // Coolpad + (info->dev_vendor != 0x1ebf) && // Coolpad + (info->dev_vendor != 0x2a96)) // MMX return -1; if(info->ifc_class != 0xff) return -1; if(info->ifc_subclass != 0x42) return -1; From a3ceca4db320894b1bd2572855bdcb14bd24c27f Mon Sep 17 00:00:00 2001 From: arter97 Date: Sat, 16 May 2015 19:05:05 +0900 Subject: [PATCH 195/243] init: force SELinux to be permissive on all builds - Less secure, yes. - But also, much stable ROM, too. And realistically, every temasek ROM users use with root access. Come on, there's no need to enforce SELinux here. Signed-off-by: arter97 --- init/Android.mk | 4 +--- init/init.c | 25 +------------------------ 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/init/Android.mk b/init/Android.mk index 61ae6c25..15dc7e36 100755 --- a/init/Android.mk +++ b/init/Android.mk @@ -25,9 +25,7 @@ LOCAL_SRC_FILES += bootchart.c LOCAL_CFLAGS += -DBOOTCHART=1 endif -ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) -LOCAL_CFLAGS += -DALLOW_LOCAL_PROP_OVERRIDE=1 -DALLOW_DISABLE_SELINUX=1 -endif +LOCAL_CFLAGS += -DALLOW_LOCAL_PROP_OVERRIDE=1 # Enable ueventd logging #LOCAL_CFLAGS += -DLOG_UEVENTS=1 diff --git a/init/init.c b/init/init.c index 7a68e628..3207ed45 100644 --- a/init/init.c +++ b/init/init.c @@ -917,29 +917,6 @@ static bool selinux_is_disabled(void) return false; } -static bool selinux_is_enforcing(void) -{ -#ifdef ALLOW_DISABLE_SELINUX - char tmp[PROP_VALUE_MAX]; - - if (property_get("ro.boot.selinux", tmp) == 0) { - /* Property is not set. Assume enforcing */ - return true; - } - - if (strcmp(tmp, "permissive") == 0) { - /* SELinux is in the kernel, but we've been told to go into permissive mode */ - return false; - } - - if (strcmp(tmp, "enforcing") != 0) { - ERROR("SELinux: Unknown value of ro.boot.selinux. Got: \"%s\". Assuming enforcing.\n", tmp); - } - -#endif - return true; -} - int selinux_reload_policy(void) { if (selinux_is_disabled()) { @@ -1003,7 +980,7 @@ static void selinux_initialize(void) } selinux_init_all_handles(); - bool is_enforcing = selinux_is_enforcing(); + bool is_enforcing = false; INFO("SELinux: security_setenforce(%d)\n", is_enforcing); security_setenforce(is_enforcing); } From 6148f9ac5d62100270f81d74b38cc08894961b48 Mon Sep 17 00:00:00 2001 From: W4TCH0UT Date: Tue, 2 Jun 2015 19:25:46 +0530 Subject: [PATCH 196/243] core: Radium-ify Change-Id: I7a6862e46de4af2c6bd66fe9710563ab27e6af32 --- adb/services.c | 6 +++--- rootdir/init.rc | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/adb/services.c b/adb/services.c index ff691e3f..48ca7eea 100644 --- a/adb/services.c +++ b/adb/services.c @@ -62,7 +62,7 @@ void restart_root_service(int fd, void *cookie) char buf[100]; char value[PROPERTY_VALUE_MAX]; char build_type[PROPERTY_VALUE_MAX]; - char cm_version[PROPERTY_VALUE_MAX]; + char radium_version[PROPERTY_VALUE_MAX]; if (getuid() == 0) { snprintf(buf, sizeof(buf), "adbd is already running as root\n"); @@ -79,9 +79,9 @@ void restart_root_service(int fd, void *cookie) property_get("persist.sys.root_access", value, "0"); property_get("ro.build.type", build_type, ""); - property_get("ro.cm.version", cm_version, ""); + property_get("ro.radium.version", radium_version, ""); - if (strlen(cm_version) > 0 && strcmp(build_type, "eng") != 0 && (atoi(value) & 2) != 2) { + if (strlen(radium_version) > 0 && strcmp(build_type, "eng") != 0 && (atoi(value) & 2) != 2) { snprintf(buf, sizeof(buf), "root access is disabled by system setting - enable in settings -> development options\n"); writex(fd, buf, strlen(buf)); adb_close(fd); diff --git a/rootdir/init.rc b/rootdir/init.rc index 029d7deb..8e416cc9 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -9,8 +9,8 @@ import /init.usb.rc import /init.${ro.hardware}.rc import /init.${ro.zygote}.rc import /init.trace.rc -# Include CM's extra init file -import /init.cm.rc +# Include RADIUM's extra init file +import /init.radium.rc on early-init From 346e202030fe804d1b51f7ef6c69ed2a09b2d89b Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Thu, 4 Jun 2015 14:42:34 -0700 Subject: [PATCH 197/243] liblog: add Amazon logging functions for prebuilt compatibility Most prebuilt binaries from the Kindle Fire HDX devices link to these functions. Adding them here with opt-in CFLAG: AMAZON_LOG libcutils needs an external reference to these functions as well liblog implementation follows the same pattern as MOTOROLA_LOG and HTCLOG Change-Id: If7afb80405b2c444cddf9e17884a20b090b13012 --- libcutils/klog.c | 5 +++++ liblog/logd_write.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/libcutils/klog.c b/libcutils/klog.c index fbb7b724..66d5aeef 100644 --- a/libcutils/klog.c +++ b/libcutils/klog.c @@ -25,6 +25,11 @@ #include +#ifdef AMAZON_LOG +extern int lab126_log_write(int bufID, int prio, const char *tag, const char *fmt, ...); +extern int __vitals_log_print(int bufID, int prio, const char *tag, const char *fmt, ...); +#endif // AMAZON_LOG + static int klog_fd = -1; static int klog_level = KLOG_DEFAULT_LEVEL; diff --git a/liblog/logd_write.c b/liblog/logd_write.c index df077f79..ee10d580 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -421,6 +421,50 @@ static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr) return write_to_log(log_id, vec, nr); } +#ifdef AMAZON_LOG +int lab126_log_write(int bufID, int prio, const char *tag, const char *fmt, ...) +{ + va_list ap; + char buf[LOG_BUF_SIZE]; + int _a = bufID; + int _b = prio; + + // skip flooding logs + if (!tag) + { + tag = ""; + } + if( strncmp(tag, "Sensors", 7) == 0 + || strncmp(tag, "qcom_se", 7) == 0 ) + { + return 0; + } + // skip flooding logs + + va_start(ap, fmt); + vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); + va_end(ap); + + char new_tag[128]; + snprintf(new_tag, sizeof(new_tag), "AMZ-%s", tag); + + return __android_log_buf_write(LOG_ID_MAIN, ANDROID_LOG_DEBUG, new_tag, buf); +} + +int __vitals_log_print(int bufID, int prio, const char *tag, const char *fmt, ...) +{ + va_list ap; + char buf[LOG_BUF_SIZE]; + int _a = bufID; + int _b = prio; + + va_start(ap, fmt); + va_end(ap); + + return __android_log_write(ANDROID_LOG_DEBUG, tag, "__vitals_log_print not implemented"); +} +#endif + int __android_log_write(int prio, const char *tag, const char *msg) { struct iovec vec[3]; From e3465bf684c208e7beb1ccfe5e28065779ddc589 Mon Sep 17 00:00:00 2001 From: Arne Coucheron Date: Sun, 31 May 2015 23:29:55 -0400 Subject: [PATCH 198/243] audio: fix incall music ifdefs (1/3) Change-Id: Ie5627d9892335d8f3174d72ceff00c09d7427e1c --- include/system/audio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/system/audio.h b/include/system/audio.h index 1af31fce..093da96e 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -71,7 +71,7 @@ typedef enum { AUDIO_STREAM_REROUTING = 11, /* For dynamic policy output mixes */ AUDIO_STREAM_PATCH = 12, /* For internal audio flinger tracks. Fixed volume */ AUDIO_STREAM_PUBLIC_CNT = AUDIO_STREAM_TTS + 1, -#ifdef QCOM_HARDWARE +#if defined(QCOM_HARDWARE) && !defined(QCOM_DIRECTTRACK) AUDIO_STREAM_INCALL_MUSIC = 13, AUDIO_STREAM_CNT = AUDIO_STREAM_INCALL_MUSIC + 1, #else From cd2426086a840d7d7aa755e92e4cbae89e7e80d7 Mon Sep 17 00:00:00 2001 From: Pete Delaney Date: Thu, 4 Jun 2015 17:33:14 -0700 Subject: [PATCH 199/243] Provide better advice on using gdb with debuggerd on crashed applications. Let CyanogenMod developers know of a Cyanogen enhancement made by Clark Scheff and Steve Kondik where the graphical debugger interface ddd can be used with crashed applications. The new in-line function, dddclient, is now available in addition to the std Google gdbclient interface. Also, let users know that they have set their property debug.db.uid too low to enable debuggerd to wait for gdb to attach. If they haven't set debug.db.uid; let them know; and offer a hint on how to do it, without their having to Google for the web page. Change-Id: I467d861c0fffe34e8532a8bc7cf7bfdab9f56447 Signed-off-by: Pete Delaney --- debuggerd/debuggerd.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/debuggerd/debuggerd.cpp b/debuggerd/debuggerd.cpp index 8b95920a..5eef93ff 100644 --- a/debuggerd/debuggerd.cpp +++ b/debuggerd/debuggerd.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#define LOG_TAG "DEBUG" + #include #include #include @@ -75,11 +77,13 @@ static void wait_for_user_action(const debugger_request_t &request) { "* and start gdbclient:\n" "*\n" "* gdbclient %s :5039 %d\n" + "* or\n" + "* dddclient %s :5039 %d\n" "*\n" "* Wait for gdb to start, then press the VOLUME DOWN key\n" "* to let the process continue crashing.\n" "********************************************************", - request.pid, exe, request.tid); + request.pid, exe, request.tid, exe, request.tid); // Wait for VOLUME DOWN. if (init_getevent() == 0) { @@ -278,7 +282,19 @@ static bool should_attach_gdb(debugger_request_t* request) { char value[PROPERTY_VALUE_MAX]; property_get("debug.db.uid", value, "-1"); int debug_uid = atoi(value); - return debug_uid >= 0 && request->uid <= (uid_t)debug_uid; + if (debug_uid >= 0 && request->uid <= (uid_t)debug_uid) { + return true; + } else { + /* External docs say to use 10,000 but more is likely needed; be helpful. */ + if (request->uid > (uid_t)debug_uid) { + ALOGI("request->uid:%d > property debug.db.uid:%d; NOT waiting for gdb.", + request->uid, debug_uid); + } else { + ALOGI("property debug.db.uid not set; NOT waiting for gdb."); + ALOGI("HINT: adb shell setprop debug.db.uid 100000"); + ALOGI("HINT: adb forward tcp:5039 tcp:5039"); + } + } } return false; } From 655650d476ddc06dc9a0b633caec8b9d6407dea8 Mon Sep 17 00:00:00 2001 From: Jesse Hall Date: Tue, 23 Dec 2014 14:00:29 -0800 Subject: [PATCH 200/243] Mutex: add timedLock() method This is not available for host builds because OSX doesn't have pthread_mutex_timedlock() or equivalent. Bug: 18842510 Change-Id: I072e74ab1a6f770fd245828b39c5f954dda1113b --- include/utils/Mutex.h | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/include/utils/Mutex.h b/include/utils/Mutex.h index dd201c89..4fdd27ff 100644 --- a/include/utils/Mutex.h +++ b/include/utils/Mutex.h @@ -26,6 +26,7 @@ #endif #include +#include // --------------------------------------------------------------------------- namespace android { @@ -45,7 +46,7 @@ class Mutex { PRIVATE = 0, SHARED = 1 }; - + Mutex(); Mutex(const char* name); Mutex(int type, const char* name = NULL); @@ -58,6 +59,16 @@ class Mutex { // lock if possible; returns 0 on success, error otherwise status_t tryLock(); +#if HAVE_ANDROID_OS + // lock the mutex, but don't wait longer than timeoutMilliseconds. + // Returns 0 on success, TIMED_OUT for failure due to timeout expiration. + // + // OSX doesn't have pthread_mutex_timedlock() or equivalent. To keep + // capabilities consistent across host OSes, this method is only available + // when building Android binaries. + status_t timedLock(nsecs_t timeoutMilliseconds); +#endif + // Manages the mutex automatically. It'll be locked when Autolock is // constructed and released when Autolock goes out of scope. class Autolock { @@ -71,11 +82,11 @@ class Mutex { private: friend class Condition; - + // A mutex cannot be copied Mutex(const Mutex&); Mutex& operator = (const Mutex&); - + #if defined(HAVE_PTHREADS) pthread_mutex_t mMutex; #else @@ -117,6 +128,15 @@ inline void Mutex::unlock() { inline status_t Mutex::tryLock() { return -pthread_mutex_trylock(&mMutex); } +#if HAVE_ANDROID_OS +inline status_t Mutex::timedLock(nsecs_t timeoutNs) { + const struct timespec ts = { + /* .tv_sec = */ timeoutNs / 1000000000, + /* .tv_nsec = */ timeoutNs % 1000000000, + }; + return -pthread_mutex_timedlock(&mMutex, &ts); +} +#endif #endif // HAVE_PTHREADS @@ -127,7 +147,7 @@ inline status_t Mutex::tryLock() { * When the function returns, it will go out of scope, and release the * mutex. */ - + typedef Mutex::Autolock AutoMutex; // --------------------------------------------------------------------------- From b6ebd65cd36d06daa5cf33f031d7e03b0bd674c6 Mon Sep 17 00:00:00 2001 From: Scott Mertz Date: Sat, 21 Mar 2015 17:33:47 -0700 Subject: [PATCH 201/243] healthd: allow custom charger Change-Id: I1380bea300bfaa6819d50bdc813329c93050286a (cherry picked from commit 92d5ea9c997964d5568688e817e9c7972aa2ab2e) --- healthd/Android.mk | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/healthd/Android.mk b/healthd/Android.mk index 17e51d82..06f1fad3 100644 --- a/healthd/Android.mk +++ b/healthd/Android.mk @@ -15,10 +15,15 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ healthd.cpp \ healthd_mode_android.cpp \ - healthd_mode_charger.cpp \ BatteryMonitor.cpp \ BatteryPropertiesRegistrar.cpp +ifeq ($(strip $(BOARD_HEALTHD_CUSTOM_CHARGER)),) + LOCAL_SRC_FILES += healthd_mode_charger.cpp +else + LOCAL_SRC_FILES += ../../../$(BOARD_HEALTHD_CUSTOM_CHARGER) +endif + LOCAL_MODULE := healthd LOCAL_MODULE_TAGS := optional LOCAL_FORCE_STATIC_EXECUTABLE := true @@ -81,8 +86,13 @@ include $$(BUILD_PREBUILT) endef _img_modules := +ifeq ($(strip $(BOARD_HEALTHD_CUSTOM_CHARGER_RES)),) +IMAGES_DIR := images +else +IMAGES_DIR := ../../../$(BOARD_HEALTHD_CUSTOM_CHARGER_RES) +endif _images := -$(foreach _img, $(call find-subdir-subdir-files, "images", "*.png"), \ +$(foreach _img, $(call find-subdir-subdir-files, "$(IMAGES_DIR)", "*.png"), \ $(eval $(call _add-charger-image,$(_img)))) include $(CLEAR_VARS) From 429e98c3eb528f5b6e227daee53615c3f8224896 Mon Sep 17 00:00:00 2001 From: Ethan Chen Date: Wed, 1 Jul 2015 10:14:52 -0700 Subject: [PATCH 202/243] Add Wileyfox VID Change-Id: I9693e38000394dbf96b6332ec1a50309147cbc1c --- adb/usb_vendors.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c index 19bcae41..51ebfcba 100755 --- a/adb/usb_vendors.c +++ b/adb/usb_vendors.c @@ -187,6 +187,8 @@ #define VENDOR_ID_VIZIO 0xE040 // Wacom's USB Vendor ID #define VENDOR_ID_WACOM 0x0531 +// Wileyfox's USB Vendor ID +#define VENDOR_ID_WILEYFOX 0x2970 // Xiaomi's USB Vendor ID #define VENDOR_ID_XIAOMI 0x2717 // YotaDevices's USB Vendor ID From e05665ab82cedce18e47a45a15b6ad71f06e69fc Mon Sep 17 00:00:00 2001 From: Ethan Chen Date: Wed, 1 Jul 2015 12:15:30 -0700 Subject: [PATCH 203/243] Add Wileyfox VID part 2 Change-Id: I82d3452f79b9121a11dc3e48a232eb05d1f042fa --- adb/usb_vendors.c | 1 + 1 file changed, 1 insertion(+) diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c index 51ebfcba..88495726 100755 --- a/adb/usb_vendors.c +++ b/adb/usb_vendors.c @@ -276,6 +276,7 @@ int builtInVendorIds[] = { VENDOR_ID_UNOWHY, VENDOR_ID_VIZIO, VENDOR_ID_WACOM, + VENDOR_ID_WILEYFOX, VENDOR_ID_XIAOMI, VENDOR_ID_YOTADEVICES, VENDOR_ID_YULONG_COOLPAD, From a213c369278444eab0bebef5e50d7532a1a59fba Mon Sep 17 00:00:00 2001 From: Chao Chen Date: Tue, 30 Jun 2015 12:25:48 -0700 Subject: [PATCH 204/243] Charger: Add font to show real battery capacity in charger mode. The font needs to be under res/images directory for minui. Move charger asset from res/images/charger to res/images for cm charger. Change-Id: I8cfe27f31facf04039ee14ff1fa5fd419912e289 --- healthd/Android.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/healthd/Android.mk b/healthd/Android.mk index 06f1fad3..71fd8f36 100644 --- a/healthd/Android.mk +++ b/healthd/Android.mk @@ -81,7 +81,11 @@ _img_modules += $$(LOCAL_MODULE) LOCAL_SRC_FILES := $1 LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := ETC +ifeq ($(strip $(BOARD_HEALTHD_CUSTOM_CHARGER_RES)),) LOCAL_MODULE_PATH := $$(TARGET_ROOT_OUT)/res/images/charger +else +LOCAL_MODULE_PATH := $$(TARGET_ROOT_OUT)/res/images +endif include $$(BUILD_PREBUILT) endef From fe93cfb26724eb60e2527f7b43c80e95068184f3 Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Sun, 28 Jun 2015 00:55:25 +0200 Subject: [PATCH 205/243] healthd: dock battery Change-Id: I2ad09e5e87d55c47af4d1efc14cc585cc08e2dce Require: topic:dock_battery Signed-off-by: Jorge Ruesga --- healthd/BatteryMonitor.cpp | 285 ++++++++++++++++++++++++- healthd/BatteryMonitor.h | 7 +- healthd/BatteryPropertiesRegistrar.cpp | 5 + healthd/BatteryPropertiesRegistrar.h | 2 + healthd/healthd.cpp | 17 ++ healthd/healthd.h | 34 +++ 6 files changed, 342 insertions(+), 8 deletions(-) diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 7a34da1a..c0e98744 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -136,6 +137,8 @@ BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String { "USB_ACA", ANDROID_POWER_SUPPLY_TYPE_AC }, { "Wireless", ANDROID_POWER_SUPPLY_TYPE_WIRELESS }, { "Wipower", ANDROID_POWER_SUPPLY_TYPE_WIRELESS }, + { "DockBattery", ANDROID_POWER_SUPPLY_TYPE_DOCK_BATTERY }, + { "DockAC", ANDROID_POWER_SUPPLY_TYPE_DOCK_AC }, { NULL, 0 }, }; @@ -180,8 +183,11 @@ bool BatteryMonitor::update(void) { props.chargerAcOnline = false; props.chargerUsbOnline = false; props.chargerWirelessOnline = false; + props.chargerDockAcOnline = false; props.batteryStatus = BATTERY_STATUS_UNKNOWN; props.batteryHealth = BATTERY_HEALTH_UNKNOWN; + props.dockBatteryStatus = BATTERY_STATUS_UNKNOWN; + props.dockBatteryHealth = BATTERY_HEALTH_UNKNOWN; if (!mHealthdConfig->batteryPresentPath.isEmpty()) props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); @@ -210,6 +216,32 @@ bool BatteryMonitor::update(void) { if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0) props.batteryTechnology = String8(buf); + props.dockBatterySupported = mHealthdConfig->dockBatterySupported; + if (props.dockBatterySupported) { + if (!mHealthdConfig->dockBatteryPresentPath.isEmpty()) + props.dockBatteryPresent = getBooleanField(mHealthdConfig->dockBatteryPresentPath); + else + props.dockBatteryPresent = mDockBatteryDevicePresent; + + props.dockBatteryLevel = mBatteryFixedCapacity ? + mBatteryFixedCapacity : + getIntField(mHealthdConfig->dockBatteryCapacityPath); + props.dockBatteryVoltage = getIntField(mHealthdConfig->dockBatteryVoltagePath) / 1000; + + props.dockBatteryTemperature = mBatteryFixedTemperature ? + mBatteryFixedTemperature : + getIntField(mHealthdConfig->dockBatteryTemperaturePath); + + if (readFromFile(mHealthdConfig->dockBatteryStatusPath, buf, SIZE) > 0) + props.dockBatteryStatus = getBatteryStatus(buf); + + if (readFromFile(mHealthdConfig->dockBatteryHealthPath, buf, SIZE) > 0) + props.dockBatteryHealth = getBatteryHealth(buf); + + if (readFromFile(mHealthdConfig->dockBatteryTechnologyPath, buf, SIZE) > 0) + props.dockBatteryTechnology = String8(buf); + } + // reinitialize the mChargerNames vector everytime there is an update String8 path; DIR* dir = opendir(POWER_SUPPLY_SYSFS_PATH); @@ -230,6 +262,7 @@ bool BatteryMonitor::update(void) { path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name); switch(readPowerSupplyType(path)) { case ANDROID_POWER_SUPPLY_TYPE_BATTERY: + case ANDROID_POWER_SUPPLY_TYPE_DOCK_BATTERY: break; default: path.clear(); @@ -251,6 +284,10 @@ bool BatteryMonitor::update(void) { case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: props.chargerWirelessOnline = true; break; + case ANDROID_POWER_SUPPLY_TYPE_DOCK_AC: + if (mHealthdConfig->dockBatterySupported) { + props.chargerDockAcOnline = true; + } default: KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", name); @@ -268,10 +305,11 @@ bool BatteryMonitor::update(void) { if (logthis) { char dmesgline[256]; + char dmesglinedock[256]; if (props.batteryPresent) { snprintf(dmesgline, sizeof(dmesgline), - "battery l=%d v=%d t=%s%d.%d h=%d st=%d", + "battery [l=%d v=%d t=%s%d.%d h=%d st=%d]", props.batteryLevel, props.batteryVoltage, props.batteryTemperature < 0 ? "-" : "", abs(props.batteryTemperature / 10), @@ -290,15 +328,37 @@ bool BatteryMonitor::update(void) { "battery none"); } - KLOG_WARNING(LOG_TAG, "%s chg=%s%s%s\n", dmesgline, + if (props.dockBatteryPresent) { + snprintf(dmesglinedock, sizeof(dmesglinedock), + "dock-battery [l=%d v=%d t=%s%d.%d h=%d st=%d]", + props.dockBatteryLevel, props.dockBatteryVoltage, + props.dockBatteryTemperature < 0 ? "-" : "", + abs(props.dockBatteryTemperature / 10), + abs(props.dockBatteryTemperature % 10), props.dockBatteryHealth, + props.dockBatteryStatus); + + if (!mHealthdConfig->dockBatteryCurrentNowPath.isEmpty()) { + int c = getIntField(mHealthdConfig->dockBatteryCurrentNowPath); + char b[20]; + + snprintf(b, sizeof(b), " c=%d", c / 1000); + strlcat(dmesglinedock, b, sizeof(dmesglinedock)); + } + } else { + snprintf(dmesglinedock, sizeof(dmesglinedock), + "dock-battery none"); + } + + KLOG_WARNING(LOG_TAG, "%s %s chg=%s%s%s%s\n", dmesgline, dmesglinedock, props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "", - props.chargerWirelessOnline ? "w" : ""); + props.chargerWirelessOnline ? "w" : "", + props.chargerDockAcOnline ? "d" : ""); } healthd_mode_ops->battery_update(&props); return props.chargerAcOnline | props.chargerUsbOnline | - props.chargerWirelessOnline; + props.chargerWirelessOnline | props.chargerDockAcOnline; } status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) { @@ -362,13 +422,77 @@ status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) { return ret; } +status_t BatteryMonitor::getDockProperty(int id, struct BatteryProperty *val) { + status_t ret = BAD_VALUE; + if (!mHealthdConfig->dockBatterySupported) { + return ret; + } + + val->valueInt64 = LONG_MIN; + + switch(id) { + case BATTERY_PROP_CHARGE_COUNTER: + if (!mHealthdConfig->dockBatteryChargeCounterPath.isEmpty()) { + val->valueInt64 = + getIntField(mHealthdConfig->dockBatteryChargeCounterPath); + ret = NO_ERROR; + } else { + ret = NAME_NOT_FOUND; + } + break; + + case BATTERY_PROP_CURRENT_NOW: + if (!mHealthdConfig->dockBatteryCurrentNowPath.isEmpty()) { + val->valueInt64 = + getIntField(mHealthdConfig->dockBatteryCurrentNowPath); + ret = NO_ERROR; + } else { + ret = NAME_NOT_FOUND; + } + break; + + case BATTERY_PROP_CURRENT_AVG: + if (!mHealthdConfig->dockBatteryCurrentAvgPath.isEmpty()) { + val->valueInt64 = + getIntField(mHealthdConfig->dockBatteryCurrentAvgPath); + ret = NO_ERROR; + } else { + ret = NAME_NOT_FOUND; + } + break; + + case BATTERY_PROP_CAPACITY: + if (!mHealthdConfig->dockBatteryCapacityPath.isEmpty()) { + val->valueInt64 = + getIntField(mHealthdConfig->dockBatteryCapacityPath); + ret = NO_ERROR; + } else { + ret = NAME_NOT_FOUND; + } + break; + + case BATTERY_PROP_ENERGY_COUNTER: + if (mHealthdConfig->dockEnergyCounter) { + ret = mHealthdConfig->dockEnergyCounter(&val->valueInt64); + } else { + ret = NAME_NOT_FOUND; + } + break; + + default: + break; + } + + return ret; +} + void BatteryMonitor::dumpState(int fd) { int v; char vs[128]; - snprintf(vs, sizeof(vs), "ac: %d usb: %d wireless: %d\n", + snprintf(vs, sizeof(vs), "ac: %d usb: %d wireless: %d dock-ac: %d\n", props.chargerAcOnline, props.chargerUsbOnline, - props.chargerWirelessOnline); + props.chargerWirelessOnline, props.chargerDockAcOnline); write(fd, vs, strlen(vs)); snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n", props.batteryStatus, props.batteryHealth, props.batteryPresent); @@ -395,6 +519,34 @@ void BatteryMonitor::dumpState(int fd) { snprintf(vs, sizeof(vs), "charge counter: %d\n", v); write(fd, vs, strlen(vs)); } + + if (mHealthdConfig->dockBatterySupported) { + snprintf(vs, sizeof(vs), "dock-status: %d dock-health: %d dock-present: %d\n", + props.dockBatteryStatus, props.dockBatteryHealth, props.dockBatteryPresent); + write(fd, vs, strlen(vs)); + snprintf(vs, sizeof(vs), "dock-level: %d dock-voltage: %d dock-temp: %d\n", + props.dockBatteryLevel, props.dockBatteryVoltage, + props.dockBatteryTemperature); + write(fd, vs, strlen(vs)); + + if (!mHealthdConfig->dockBatteryCurrentNowPath.isEmpty()) { + v = getIntField(mHealthdConfig->dockBatteryCurrentNowPath); + snprintf(vs, sizeof(vs), "dock-current now: %d\n", v); + write(fd, vs, strlen(vs)); + } + + if (!mHealthdConfig->dockBatteryCurrentAvgPath.isEmpty()) { + v = getIntField(mHealthdConfig->dockBatteryCurrentAvgPath); + snprintf(vs, sizeof(vs), "dock-current avg: %d\n", v); + write(fd, vs, strlen(vs)); + } + + if (!mHealthdConfig->dockBatteryChargeCounterPath.isEmpty()) { + v = getIntField(mHealthdConfig->dockBatteryChargeCounterPath); + snprintf(vs, sizeof(vs), "dock-charge counter: %d\n", v); + write(fd, vs, strlen(vs)); + } + } } void BatteryMonitor::init(struct healthd_config *hc) { @@ -422,6 +574,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { case ANDROID_POWER_SUPPLY_TYPE_AC: case ANDROID_POWER_SUPPLY_TYPE_USB: case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: + case ANDROID_POWER_SUPPLY_TYPE_DOCK_AC: path.clear(); path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name); if (access(path.string(), R_OK) == 0) @@ -527,6 +680,107 @@ void BatteryMonitor::init(struct healthd_config *hc) { break; + case ANDROID_POWER_SUPPLY_TYPE_DOCK_BATTERY: + if (mHealthdConfig->dockBatterySupported) { + mDockBatteryDevicePresent = true; + + if (mHealthdConfig->dockBatteryStatusPath.isEmpty()) { + path.clear(); + path.appendFormat("%s/%s/status", POWER_SUPPLY_SYSFS_PATH, + name); + if (access(path, R_OK) == 0) + mHealthdConfig->dockBatteryStatusPath = path; + } + + if (mHealthdConfig->dockBatteryHealthPath.isEmpty()) { + path.clear(); + path.appendFormat("%s/%s/health", POWER_SUPPLY_SYSFS_PATH, + name); + if (access(path, R_OK) == 0) + mHealthdConfig->dockBatteryHealthPath = path; + } + + if (mHealthdConfig->dockBatteryPresentPath.isEmpty()) { + path.clear(); + path.appendFormat("%s/%s/present", POWER_SUPPLY_SYSFS_PATH, + name); + if (access(path, R_OK) == 0) + mHealthdConfig->dockBatteryPresentPath = path; + } + + if (mHealthdConfig->dockBatteryCapacityPath.isEmpty()) { + path.clear(); + path.appendFormat("%s/%s/capacity", POWER_SUPPLY_SYSFS_PATH, + name); + if (access(path, R_OK) == 0) + mHealthdConfig->dockBatteryCapacityPath = path; + } + + if (mHealthdConfig->dockBatteryVoltagePath.isEmpty()) { + path.clear(); + path.appendFormat("%s/%s/voltage_now", + POWER_SUPPLY_SYSFS_PATH, name); + if (access(path, R_OK) == 0) { + mHealthdConfig->dockBatteryVoltagePath = path; + } else { + path.clear(); + path.appendFormat("%s/%s/batt_vol", + POWER_SUPPLY_SYSFS_PATH, name); + if (access(path, R_OK) == 0) + mHealthdConfig->dockBatteryVoltagePath = path; + } + } + + if (mHealthdConfig->dockBatteryCurrentNowPath.isEmpty()) { + path.clear(); + path.appendFormat("%s/%s/current_now", + POWER_SUPPLY_SYSFS_PATH, name); + if (access(path, R_OK) == 0) + mHealthdConfig->dockBatteryCurrentNowPath = path; + } + + if (mHealthdConfig->dockBatteryCurrentAvgPath.isEmpty()) { + path.clear(); + path.appendFormat("%s/%s/current_avg", + POWER_SUPPLY_SYSFS_PATH, name); + if (access(path, R_OK) == 0) + mHealthdConfig->dockBatteryCurrentAvgPath = path; + } + + if (mHealthdConfig->dockBatteryChargeCounterPath.isEmpty()) { + path.clear(); + path.appendFormat("%s/%s/charge_counter", + POWER_SUPPLY_SYSFS_PATH, name); + if (access(path, R_OK) == 0) + mHealthdConfig->dockBatteryChargeCounterPath = path; + } + + if (mHealthdConfig->dockBatteryTemperaturePath.isEmpty()) { + path.clear(); + path.appendFormat("%s/%s/temp", POWER_SUPPLY_SYSFS_PATH, + name); + if (access(path, R_OK) == 0) { + mHealthdConfig->dockBatteryTemperaturePath = path; + } else { + path.clear(); + path.appendFormat("%s/%s/batt_temp", + POWER_SUPPLY_SYSFS_PATH, name); + if (access(path, R_OK) == 0) + mHealthdConfig->dockBatteryTemperaturePath = path; + } + } + + if (mHealthdConfig->dockBatteryTechnologyPath.isEmpty()) { + path.clear(); + path.appendFormat("%s/%s/technology", + POWER_SUPPLY_SYSFS_PATH, name); + if (access(path, R_OK) == 0) + mHealthdConfig->dockBatteryTechnologyPath = path; + } + } + + break; + case ANDROID_POWER_SUPPLY_TYPE_UNKNOWN: break; } @@ -536,7 +790,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { if (!mChargerNames.size()) KLOG_ERROR(LOG_TAG, "No charger supplies found\n"); - if (!mBatteryDevicePresent) { + if (!mBatteryDevicePresent && !mDockBatteryDevicePresent) { KLOG_WARNING(LOG_TAG, "No battery devices found\n"); hc->periodic_chores_interval_fast = -1; hc->periodic_chores_interval_slow = -1; @@ -555,6 +809,23 @@ void BatteryMonitor::init(struct healthd_config *hc) { KLOG_WARNING(LOG_TAG, "BatteryTemperaturePath not found\n"); if (mHealthdConfig->batteryTechnologyPath.isEmpty()) KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n"); + + if (mHealthdConfig->dockBatterySupported) { + if (mHealthdConfig->dockBatteryStatusPath.isEmpty()) + KLOG_WARNING(LOG_TAG, "DockBatteryStatusPath not found\n"); + if (mHealthdConfig->dockBatteryHealthPath.isEmpty()) + KLOG_WARNING(LOG_TAG, "DockBatteryHealthPath not found\n"); + if (mHealthdConfig->dockBatteryPresentPath.isEmpty()) + KLOG_WARNING(LOG_TAG, "DockBatteryPresentPath not found\n"); + if (mHealthdConfig->dockBatteryCapacityPath.isEmpty()) + KLOG_WARNING(LOG_TAG, "DockBatteryCapacityPath not found\n"); + if (mHealthdConfig->dockBatteryVoltagePath.isEmpty()) + KLOG_WARNING(LOG_TAG, "DockBatteryVoltagePath not found\n"); + if (mHealthdConfig->dockBatteryTemperaturePath.isEmpty()) + KLOG_WARNING(LOG_TAG, "DockBatteryTemperaturePath not found\n"); + if (mHealthdConfig->dockBatteryTechnologyPath.isEmpty()) + KLOG_WARNING(LOG_TAG, "DockBatteryTechnologyPath not found\n"); + } } if (property_get("ro.boot.fake_battery", pval, NULL) > 0 diff --git a/healthd/BatteryMonitor.h b/healthd/BatteryMonitor.h index 3425f277..6e3ec987 100644 --- a/healthd/BatteryMonitor.h +++ b/healthd/BatteryMonitor.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,18 +35,22 @@ class BatteryMonitor { ANDROID_POWER_SUPPLY_TYPE_AC, ANDROID_POWER_SUPPLY_TYPE_USB, ANDROID_POWER_SUPPLY_TYPE_WIRELESS, - ANDROID_POWER_SUPPLY_TYPE_BATTERY + ANDROID_POWER_SUPPLY_TYPE_BATTERY, + ANDROID_POWER_SUPPLY_TYPE_DOCK_AC, + ANDROID_POWER_SUPPLY_TYPE_DOCK_BATTERY }; void init(struct healthd_config *hc); bool update(void); status_t getProperty(int id, struct BatteryProperty *val); + status_t getDockProperty(int id, struct BatteryProperty *val); void dumpState(int fd); private: struct healthd_config *mHealthdConfig; Vector mChargerNames; bool mBatteryDevicePresent; + bool mDockBatteryDevicePresent; int mBatteryFixedCapacity; int mBatteryFixedTemperature; struct BatteryProperties props; diff --git a/healthd/BatteryPropertiesRegistrar.cpp b/healthd/BatteryPropertiesRegistrar.cpp index 74bcbfde..6152b165 100644 --- a/healthd/BatteryPropertiesRegistrar.cpp +++ b/healthd/BatteryPropertiesRegistrar.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,6 +77,10 @@ status_t BatteryPropertiesRegistrar::getProperty(int id, struct BatteryProperty return healthd_get_property(id, val); } +status_t BatteryPropertiesRegistrar::getDockProperty(int id, struct BatteryProperty *val) { + return healthd_get_dock_property(id, val); +} + status_t BatteryPropertiesRegistrar::dump(int fd, const Vector& /*args*/) { IPCThreadState* self = IPCThreadState::self(); const int pid = self->getCallingPid(); diff --git a/healthd/BatteryPropertiesRegistrar.h b/healthd/BatteryPropertiesRegistrar.h index 88538744..5ca4fc1c 100644 --- a/healthd/BatteryPropertiesRegistrar.h +++ b/healthd/BatteryPropertiesRegistrar.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +41,7 @@ class BatteryPropertiesRegistrar : public BnBatteryPropertiesRegistrar, void registerListener(const sp& listener); void unregisterListener(const sp& listener); status_t getProperty(int id, struct BatteryProperty *val); + status_t getDockProperty(int id, struct BatteryProperty *val); status_t dump(int fd, const Vector& args); void binderDied(const wp& who); }; diff --git a/healthd/healthd.cpp b/healthd/healthd.cpp index 79d9e39a..e172e254 100644 --- a/healthd/healthd.cpp +++ b/healthd/healthd.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,6 +63,18 @@ static struct healthd_config healthd_config = { .batteryChargeCounterPath = String8(String8::kEmptyString), .energyCounter = NULL, .screen_on = NULL, + .dockBatterySupported = false, + .dockBatteryStatusPath = String8(String8::kEmptyString), + .dockBatteryHealthPath = String8(String8::kEmptyString), + .dockBatteryPresentPath = String8(String8::kEmptyString), + .dockBatteryCapacityPath = String8(String8::kEmptyString), + .dockBatteryVoltagePath = String8(String8::kEmptyString), + .dockBatteryTemperaturePath = String8(String8::kEmptyString), + .dockBatteryTechnologyPath = String8(String8::kEmptyString), + .dockBatteryCurrentNowPath = String8(String8::kEmptyString), + .dockBatteryCurrentAvgPath = String8(String8::kEmptyString), + .dockBatteryChargeCounterPath = String8(String8::kEmptyString), + .dockEnergyCounter = NULL, }; static int eventct; @@ -188,6 +201,10 @@ status_t healthd_get_property(int id, struct BatteryProperty *val) { return gBatteryMonitor->getProperty(id, val); } +status_t healthd_get_dock_property(int id, struct BatteryProperty *val) { + return gBatteryMonitor->getDockProperty(id, val); +} + void healthd_battery_update(void) { // Fast wake interval when on charger (watch for overheat); // slow wake interval when on battery (watch for drained battery). diff --git a/healthd/healthd.h b/healthd/healthd.h index 3b51b312..2cbdabf3 100644 --- a/healthd/healthd.h +++ b/healthd/healthd.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,8 +49,25 @@ // batteryTemperaturePath: battery temperature (POWER_SUPPLY_PROP_TEMP) // batteryTechnologyPath: battery technology (POWER_SUPPLY_PROP_TECHNOLOGY) // batteryCurrentNowPath: battery current (POWER_SUPPLY_PROP_CURRENT_NOW) +// batteryCurrentAvgPath: battery average (POWER_SUPPLY_PROP_CURRENT_AVG) // batteryChargeCounterPath: battery accumulated charge // (POWER_SUPPLY_PROP_CHARGE_COUNTER) +// +// dockBatteryStatusPath: dock charging status (POWER_SUPPLY_PROP_STATUS) +// dockBatteryHealthPath: dock battery health (POWER_SUPPLY_PROP_HEALTH) +// dockBatteryPresentPath: dock battery present (POWER_SUPPLY_PROP_PRESENT) +// dockBatteryCapacityPath: remaining dock capacity (POWER_SUPPLY_PROP_CAPACITY) +// dockBatteryVoltagePath: dock battery voltage (POWER_SUPPLY_PROP_VOLTAGE_NOW) +// dockBatteryTemperaturePath: dock battery temperature (POWER_SUPPLY_PROP_TEMP) +// dockBatteryTechnologyPath: dock battery technology (POWER_SUPPLY_PROP_TECHNOLOGY) +// dockBatteryCurrentNowPath: dock battery current (POWER_SUPPLY_PROP_CURRENT_NOW) +// dockBatteryCurrentAvgPath: dock battery average (POWER_SUPPLY_PROP_CURRENT_AVG) +// dockBatteryChargeCounterPath: dock battery accumulated charge +// (POWER_SUPPLY_PROP_CHARGE_COUNTER) +// +// The dockBatterySupported property indicates whether a dock battery is supported +// by the device, and whether this module should fetch dock battery values. +// Defaults is to false. struct healthd_config { int periodic_chores_interval_fast; @@ -68,6 +86,20 @@ struct healthd_config { int (*energyCounter)(int64_t *); bool (*screen_on)(android::BatteryProperties *props); + + bool dockBatterySupported; + android::String8 dockBatteryStatusPath; + android::String8 dockBatteryHealthPath; + android::String8 dockBatteryPresentPath; + android::String8 dockBatteryCapacityPath; + android::String8 dockBatteryVoltagePath; + android::String8 dockBatteryTemperaturePath; + android::String8 dockBatteryTechnologyPath; + android::String8 dockBatteryCurrentNowPath; + android::String8 dockBatteryCurrentAvgPath; + android::String8 dockBatteryChargeCounterPath; + + int (*dockEnergyCounter)(int64_t *); }; // Global helper functions @@ -76,6 +108,8 @@ int healthd_register_event(int fd, void (*handler)(uint32_t)); void healthd_battery_update(); android::status_t healthd_get_property(int id, struct android::BatteryProperty *val); +android::status_t healthd_get_dock_property(int id, + struct android::BatteryProperty *val); void healthd_dump_battery_state(int fd); struct healthd_mode_ops { From b0161ae79bc410e3acfac84e5a5493386a479570 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Tue, 23 Jun 2015 22:45:47 -0700 Subject: [PATCH 206/243] libutils: Improve support for POSIX timers * Don't repeatedly try to open nonexistent devices where possible. Change-Id: Id1f18d05943a66978d430556fa16ed761e8e464b --- libutils/SystemClock.cpp | 59 ++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/libutils/SystemClock.cpp b/libutils/SystemClock.cpp index dbad581f..3de0e940 100644 --- a/libutils/SystemClock.cpp +++ b/libutils/SystemClock.cpp @@ -40,6 +40,9 @@ namespace android { +static pthread_mutex_t clock_lock = PTHREAD_MUTEX_INITIALIZER; +static int clock_method = -1; + /* * native public static long uptimeMillis(); */ @@ -119,29 +122,47 @@ int64_t elapsedRealtimeNano() static int s_fd = -1; - if (s_fd == -1) { - int fd = open("/dev/alarm", O_RDONLY); - if (android_atomic_cmpxchg(-1, fd, &s_fd)) { - close(fd); - } + if (clock_method < 0) { + pthread_mutex_lock(&clock_lock); } - result = ioctl(s_fd, - ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &ts); + if (clock_method < 0 || clock_method == METHOD_IOCTL) { + if (s_fd == -1) { + int fd = open("/dev/alarm", O_RDONLY); + if (android_atomic_cmpxchg(-1, fd, &s_fd)) { + close(fd); + } + } - if (result == 0) { - timestamp = seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; - checkTimeStamps(timestamp, &prevTimestamp, &prevMethod, METHOD_IOCTL); - return timestamp; + if (s_fd > -1) { + result = ioctl(s_fd, + ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &ts); + + if (result == 0) { + timestamp = seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; + checkTimeStamps(timestamp, &prevTimestamp, &prevMethod, METHOD_IOCTL); + if (clock_method < 0) { + clock_method = METHOD_IOCTL; + pthread_mutex_unlock(&clock_lock); + } + return timestamp; + } + } } // /dev/alarm doesn't exist, fallback to CLOCK_BOOTTIME - result = clock_gettime(CLOCK_BOOTTIME, &ts); - if (result == 0) { - timestamp = seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; - checkTimeStamps(timestamp, &prevTimestamp, &prevMethod, - METHOD_CLOCK_GETTIME); - return timestamp; + if (clock_method < 0 || clock_method == METHOD_CLOCK_GETTIME) { + result = clock_gettime(CLOCK_BOOTTIME, &ts); + if (result == 0) { + timestamp = seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; + checkTimeStamps(timestamp, &prevTimestamp, &prevMethod, + METHOD_CLOCK_GETTIME); + if (clock_method < 0) { + clock_method = METHOD_CLOCK_GETTIME; + pthread_mutex_unlock(&clock_lock); + } + return timestamp; + } } // XXX: there was an error, probably because the driver didn't @@ -150,6 +171,10 @@ int64_t elapsedRealtimeNano() timestamp = systemTime(SYSTEM_TIME_MONOTONIC); checkTimeStamps(timestamp, &prevTimestamp, &prevMethod, METHOD_SYSTEMTIME); + if (clock_method < 0) { + clock_method = METHOD_SYSTEMTIME; + pthread_mutex_unlock(&clock_lock); + } return timestamp; #else return systemTime(SYSTEM_TIME_MONOTONIC); From 813e0a052359f6ef8881bd3f3d9ee86292bc9f13 Mon Sep 17 00:00:00 2001 From: Tony Layher Date: Sat, 1 Jan 2011 12:45:18 -0500 Subject: [PATCH 207/243] Added umount to init Change-Id: I0ef73be781d4e6bf7d127b4ef83d0e86ef52e70a --- init/builtins.c | 5 +++++ init/init_parser.c | 1 + init/keywords.h | 2 ++ 3 files changed, 8 insertions(+) diff --git a/init/builtins.c b/init/builtins.c index 3ca0e9ce..50651cff 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -1008,3 +1008,8 @@ int do_wait(int nargs, char **args) } else return -1; } + +int do_umount(int nargs, char **args) { + return umount(args[1]); +} + diff --git a/init/init_parser.c b/init/init_parser.c index 179eb241..eec90902 100644 --- a/init/init_parser.c +++ b/init/init_parser.c @@ -165,6 +165,7 @@ static int lookup_keyword(const char *s) break; case 'u': if (!strcmp(s, "ser")) return K_user; + if (!strcmp(s, "mount")) return K_umount; break; case 'w': if (!strcmp(s, "rite")) return K_write; diff --git a/init/keywords.h b/init/keywords.h index 1aae9b52..224a505d 100644 --- a/init/keywords.h +++ b/init/keywords.h @@ -43,6 +43,7 @@ int do_loglevel(int nargs, char **args); int do_load_persist_props(int nargs, char **args); int do_load_all_props(int nargs, char **args); int do_wait(int nargs, char **args); +int do_umount(int nargs, char **args); #define __MAKE_KEYWORD_ENUM__ #define KEYWORD(symbol, flags, nargs, func) K_##symbol, enum { @@ -109,6 +110,7 @@ enum { KEYWORD(load_persist_props, COMMAND, 0, do_load_persist_props) KEYWORD(load_all_props, COMMAND, 0, do_load_all_props) KEYWORD(ioprio, OPTION, 0, 0) + KEYWORD(umount, COMMAND, 1, do_umount) #ifdef __MAKE_KEYWORD_ENUM__ KEYWORD_COUNT, }; From 58e24e4c060f75a70a47550c9a995f6adf794b03 Mon Sep 17 00:00:00 2001 From: Chao Chen Date: Tue, 14 Jul 2015 15:49:05 -0700 Subject: [PATCH 208/243] healthd: Support QC2.0 type charger Change-Id: I838ef54ac358ac9ce851a93c47e87030b4219c1c --- healthd/BatteryMonitor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index c0e98744..66c4e8e4 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -139,6 +139,7 @@ BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String { "Wipower", ANDROID_POWER_SUPPLY_TYPE_WIRELESS }, { "DockBattery", ANDROID_POWER_SUPPLY_TYPE_DOCK_BATTERY }, { "DockAC", ANDROID_POWER_SUPPLY_TYPE_DOCK_AC }, + { "USB_HVDCP", ANDROID_POWER_SUPPLY_TYPE_AC }, { NULL, 0 }, }; From 498858473db350521c1ab71bab15be0cfd49c66d Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Thu, 23 Jul 2015 17:35:19 -0700 Subject: [PATCH 209/243] init: Add a "starting" state for services * We might want to trigger something before actually execing the service in question in order to do some pre-flight tasks. * This lets you do the following: on property:init.svc.awesomed=starting write /sys/module/awesomemod/parameters/everything_is_awesome 1 ..and when awesomed starts, it will run this trigger before forking. Change-Id: I9756b46eafd884d367fe8304b859de2152bdfeb4 --- init/init.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/init/init.c b/init/init.c index 7a68e628..8a7427d0 100644 --- a/init/init.c +++ b/init/init.c @@ -256,6 +256,9 @@ void service_start(struct service *svc, const char *dynamic_args) NOTICE("starting '%s'\n", svc->name); + if (properties_inited()) + notify_service_state(svc->name, "starting"); + pid = fork(); if (pid == 0) { From d2d26ffc5cc1cba8e563259b6e15384024cc9224 Mon Sep 17 00:00:00 2001 From: Mrcl1450 Date: Thu, 30 Jul 2015 18:03:09 +0100 Subject: [PATCH 210/243] healthd: Add secondary backlight path support Some devices require two backlight brightness paths to turn off the screen. Change-Id: Ibf2ee853657c602158af219de0ba132f29dc4571 Signed-off-by: Mrcl1450 --- healthd/Android.mk | 1 + healthd/healthd_mode_charger.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/healthd/Android.mk b/healthd/Android.mk index 71fd8f36..cd2f1705 100644 --- a/healthd/Android.mk +++ b/healthd/Android.mk @@ -36,6 +36,7 @@ HEALTHD_CHARGER_DEFINES := RED_LED_PATH \ GREEN_LED_PATH \ BLUE_LED_PATH \ BACKLIGHT_PATH \ + SECONDARY_BACKLIGHT_PATH \ CHARGING_ENABLED_PATH $(foreach healthd_charger_define,$(HEALTHD_CHARGER_DEFINES), \ diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp index 75f001d0..4e6586d0 100644 --- a/healthd/healthd_mode_charger.cpp +++ b/healthd/healthd_mode_charger.cpp @@ -289,6 +289,25 @@ static int set_backlight(bool on) } close(fd); +#ifdef SECONDARY_BACKLIGHT_PATH + if (access(SECONDARY_BACKLIGHT_PATH, R_OK | W_OK) != 0) + { + LOGW("Secondary Backlight control not support\n"); + return 0; + } + + fd = open(SECONDARY_BACKLIGHT_PATH, O_RDWR); + if (fd < 0) { + LOGE("Could not open secondary backlight node : %s\n", strerror(errno)); + return 0; + } + LOGV("Enabling secondary backlight\n"); + if (write(fd, buffer,strlen(buffer)) < 0) { + LOGE("Could not write to secondary backlight node : %s\n", strerror(errno)); + } + close(fd); +#endif + return 0; } From 9008630fad5a0fef462abaff77e3aa7ecf47e1ef Mon Sep 17 00:00:00 2001 From: Chris Fries Date: Fri, 13 Mar 2015 10:04:09 -0500 Subject: [PATCH 211/243] init: Add support for gzipped firmware files In case no matching firmware is found, re-search the paths for [path][firmware].gz and use that instead if found. Reviewed-on: http://gerrit.mot.com/724787 SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Wen-Long Che SME-Granted: Gerrit Application Reviewed-by: Christopher Fries Submit-Approved: Jira Key Change-Id: I74e42ab3c77eb7722c58042489d7bd4856f3be63 --- init/Android.mk | 2 ++ init/devices.c | 87 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/init/Android.mk b/init/Android.mk index 8312e492..c6863bfb 100755 --- a/init/Android.mk +++ b/init/Android.mk @@ -78,6 +78,8 @@ ifneq ($(strip $(TARGET_PROP_PATH_FACTORY)),) LOCAL_CFLAGS += -DOVERRIDE_PROP_PATH_FACTORY=\"$(TARGET_PROP_PATH_FACTORY)\" endif +LOCAL_C_INCLUDES += external/zlib + include $(BUILD_EXECUTABLE) # Make a symlink from /sbin/ueventd and /sbin/watchdogd to /init diff --git a/init/devices.c b/init/devices.c index 089b7806..05f0aef0 100644 --- a/init/devices.c +++ b/init/devices.c @@ -47,6 +47,7 @@ #include "ueventd_parser.h" #include "util.h" #include "log.h" +#include #define UNUSED __attribute__((__unused__)) @@ -942,23 +943,20 @@ static void handle_device_event(struct uevent *uevent) } } -static int load_firmware(int fw_fd, int loading_fd, int data_fd) +static int load_firmware(int fw_fd, gzFile gz_fd, int loading_fd, int data_fd) { - struct stat st; - long len_to_copy; int ret = 0; - if(fstat(fw_fd, &st) < 0) - return -1; - len_to_copy = st.st_size; - write(loading_fd, "1", 1); /* start transfer */ - while (len_to_copy > 0) { + while (1) { char buf[PAGE_SIZE]; ssize_t nr; - nr = read(fw_fd, buf, sizeof(buf)); + if (gz_fd) + nr = gzread(gz_fd, buf, sizeof(buf)); + else + nr = read(fw_fd, buf, sizeof(buf)); if(!nr) break; if(nr < 0) { @@ -966,7 +964,6 @@ static int load_firmware(int fw_fd, int loading_fd, int data_fd) break; } - len_to_copy -= nr; while (nr > 0) { ssize_t nw = 0; @@ -982,8 +979,10 @@ static int load_firmware(int fw_fd, int loading_fd, int data_fd) out: if(!ret) write(loading_fd, "0", 1); /* successful end of transfer */ - else + else { + ERROR("%s: aborted transfer\n", __func__); write(loading_fd, "-1", 2); /* abort transfer */ + } return ret; } @@ -993,11 +992,47 @@ static int is_booting(void) return access("/dev/.booting", F_OK) == 0; } +gzFile fw_gzopen(const char *fname, const char *mode) +{ + char *file1 = NULL, *file2 = NULL, *file3 = NULL; + int l; + gzFile gz_fd = NULL; + + l = asprintf(&file1, FIRMWARE_DIR1"/%s.gz", fname); + if (l == -1) + goto out; + + l = asprintf(&file2, FIRMWARE_DIR2"/%s.gz", fname); + if (l == -1) + goto file1_free_out; + + l = asprintf(&file3, FIRMWARE_DIR3"/%s.gz", fname); + if (l == -1) + goto file2_free_out; + + gz_fd = gzopen(file1, mode); + if(!gz_fd) { + gz_fd = gzopen(file2, mode); + if (!gz_fd) { + gz_fd = gzopen(file3, mode); + } + } + + free(file3); +file2_free_out: + free(file2); +file1_free_out: + free(file1); +out: + return gz_fd; +} + static void process_firmware_event(struct uevent *uevent) { char *root, *loading, *data, *file1 = NULL, *file2 = NULL, *file3 = NULL; int l, loading_fd, data_fd, fw_fd; int booting = is_booting(); + gzFile gz_fd = NULL; INFO("firmware: loading '%s' for '%s'\n", uevent->firmware, uevent->path); @@ -1041,27 +1076,33 @@ static void process_firmware_event(struct uevent *uevent) if (fw_fd < 0) { fw_fd = open(file3, O_RDONLY); if (fw_fd < 0) { - if (booting) { - /* If we're not fully booted, we may be missing - * filesystems needed for firmware, wait and retry. - */ - usleep(100000); - booting = is_booting(); - goto try_loading_again; + gz_fd = fw_gzopen(uevent->firmware, "rb"); + if (!gz_fd) { + if (booting || (access("/system/etc/firmware", F_OK) != 0)) { + /* If we're not fully booted, we may be missing + * filesystems needed for firmware, wait and retry. + */ + usleep(100000); + booting = is_booting(); + goto try_loading_again; + } + INFO("firmware: could not open '%s' %d\n", uevent->firmware, errno); + write(loading_fd, "-1", 2); + goto data_close_out; } - INFO("firmware: could not open '%s' %d\n", uevent->firmware, errno); - write(loading_fd, "-1", 2); - goto data_close_out; } } } - if(!load_firmware(fw_fd, loading_fd, data_fd)) + if(!load_firmware(fw_fd, gz_fd, loading_fd, data_fd)) INFO("firmware: copy success { '%s', '%s' }\n", root, uevent->firmware); else INFO("firmware: copy failure { '%s', '%s' }\n", root, uevent->firmware); - close(fw_fd); + if (gz_fd) + gzclose(gz_fd); + else + close(fw_fd); data_close_out: close(data_fd); loading_close_out: From 12a43e2d5f30d7bbc5a5791fd96c32a775f50925 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Mon, 27 Apr 2015 12:13:33 -0700 Subject: [PATCH 212/243] Prevent integer overflow when allocating native_handle_t User specified values of numInts and numFds can overflow and cause malloc to allocate less than we expect, causing heap corruption in subsequent operations on the allocation. Bug: 19334482 Change-Id: I43c75f536ea4c08f14ca12ca6288660fd2d1ec55 (cherry picked from commit 07edc3b3b3caef7829850633f928ae05f6d49f3a) --- libcutils/native_handle.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libcutils/native_handle.c b/libcutils/native_handle.c index 9a4a5bb3..61fa38ed 100644 --- a/libcutils/native_handle.c +++ b/libcutils/native_handle.c @@ -25,11 +25,17 @@ #include #include +static const int kMaxNativeFds = 1024; +static const int kMaxNativeInts = 1024; + native_handle_t* native_handle_create(int numFds, int numInts) { - native_handle_t* h = malloc( - sizeof(native_handle_t) + sizeof(int)*(numFds+numInts)); + if (numFds < 0 || numInts < 0 || numFds > kMaxNativeFds || numInts > kMaxNativeInts) { + return NULL; + } + size_t mallocSize = sizeof(native_handle_t) + (sizeof(int) * (numFds + numInts)); + native_handle_t* h = malloc(mallocSize); if (h) { h->version = sizeof(native_handle_t); h->numFds = numFds; From db9755285b074d5bce3b940bf477e91c17fd0873 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Mon, 27 Apr 2015 12:13:33 -0700 Subject: [PATCH 213/243] Prevent integer overflow when allocating native_handle_t User specified values of numInts and numFds can overflow and cause malloc to allocate less than we expect, causing heap corruption in subsequent operations on the allocation. Bug: 19334482 Change-Id: I43c75f536ea4c08f14ca12ca6288660fd2d1ec55 --- libcutils/native_handle.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libcutils/native_handle.c b/libcutils/native_handle.c index 9a4a5bb3..61fa38ed 100644 --- a/libcutils/native_handle.c +++ b/libcutils/native_handle.c @@ -25,11 +25,17 @@ #include #include +static const int kMaxNativeFds = 1024; +static const int kMaxNativeInts = 1024; + native_handle_t* native_handle_create(int numFds, int numInts) { - native_handle_t* h = malloc( - sizeof(native_handle_t) + sizeof(int)*(numFds+numInts)); + if (numFds < 0 || numInts < 0 || numFds > kMaxNativeFds || numInts > kMaxNativeInts) { + return NULL; + } + size_t mallocSize = sizeof(native_handle_t) + (sizeof(int) * (numFds + numInts)); + native_handle_t* h = malloc(mallocSize); if (h) { h->version = sizeof(native_handle_t); h->numFds = numFds; From 12c2caef2f3d1f7a3b7968c8ccfd448dbbebeb37 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Thu, 5 Mar 2015 10:59:57 -0800 Subject: [PATCH 214/243] Revert "fs_mgr: let fsck.f2fs actually attempt a fix" fsck.f2fs will correctly fix when it's required, without the -f flag. This reverts commit eb6036ac6be82dcc6e110de22574972631c8f83e. Change-Id: Iec9ca5e593b61f24b02db30bff7089fafee7635e Reviewed-on: http://gerrit.mot.com/721774 SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Christopher Fries Submit-Approved: Jira Key --- fs_mgr/fs_mgr.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index b2ec0b00..858b768d 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -153,12 +153,12 @@ static void check_fs(char *blk_device, char *fs_type, char *target) } } } else if (!strcmp(fs_type, "f2fs")) { - char *f2fs_fsck_argv[] = { - F2FS_FSCK_BIN, - "-f", - blk_device - }; - INFO("Running %s -f %s\n", F2FS_FSCK_BIN, blk_device); + char *f2fs_fsck_argv[] = { + F2FS_FSCK_BIN, + "-a", + blk_device + }; + INFO("Running %s on %s\n", F2FS_FSCK_BIN, blk_device); ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), f2fs_fsck_argv, &status, true, LOG_KLOG | LOG_FILE, From f9c2d58a440ddfc696ffd1ca895662f29630ef45 Mon Sep 17 00:00:00 2001 From: Park Ju Hyung Date: Thu, 20 Aug 2015 17:30:00 +0900 Subject: [PATCH 215/243] logd: apply correct std flag logd project contains both .c and .cpp files. As reported by many 64-bit builders, enforcing C std flag on cpp files breaks build. Fix this by separating CONLYFLAGS and CPPFLAGS. Signed-off-by: Park Ju Hyung --- logd/Android.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/logd/Android.mk b/logd/Android.mk index 6739f84d..8bdaf186 100644 --- a/logd/Android.mk +++ b/logd/Android.mk @@ -27,7 +27,10 @@ LOCAL_SHARED_LIBRARIES := \ libutils LOCAL_CFLAGS := -Werror $(shell sed -n 's/^\([0-9]*\)[ \t]*auditd[ \t].*/-DAUDITD_LOG_TAG=\1/p' $(LOCAL_PATH)/event.logtags) -LOCAL_CFLAGS += -Os -std=gnu89 +LOCAL_CFLAGS += -Os + +LOCAL_CONLYFLAGS += -std=gnu89 +LOCAL_CPPFLAGS += -std=gnu++03 include $(BUILD_EXECUTABLE) From e575b4ab70d0524a1faf6c2e768aa409382cec22 Mon Sep 17 00:00:00 2001 From: Thomas Wendt Date: Wed, 20 May 2015 20:42:01 +0200 Subject: [PATCH 216/243] libcutils/liblog: Add functions required by Huawei g620_a2 binaries Change-Id: I58604686008340ef4e10f3f67dc329fe7bd864cc --- include/cutils/huawei.h | 30 ++++++++++++++ libcutils/Android.mk | 4 ++ libcutils/huawei.c | 89 +++++++++++++++++++++++++++++++++++++++++ liblog/Android.mk | 4 ++ liblog/logd_write.c | 5 +++ 5 files changed, 132 insertions(+) create mode 100644 include/cutils/huawei.h create mode 100644 libcutils/huawei.c diff --git a/include/cutils/huawei.h b/include/cutils/huawei.h new file mode 100644 index 00000000..f3798c97 --- /dev/null +++ b/include/cutils/huawei.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2006 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 __CUTILS_HUAWEI_H +#define __CUTILS_HUAWEI_H + +#ifdef __cplusplus +extern "C" { +#endif + + int get_app_info(char* key, char* value); + +#ifdef __cplusplus +} +#endif + +#endif /* __CUTILS_HUAWEI_H */ diff --git a/libcutils/Android.mk b/libcutils/Android.mk index bee2bd75..1431034d 100644 --- a/libcutils/Android.mk +++ b/libcutils/Android.mk @@ -71,6 +71,10 @@ ifneq ($(WINDOWS_HOST_ONLY),1) endif +ifeq ($(TARGET_USES_HUAWEI_APP_INFO),true) + commonSources += \ + huawei.c +endif # Static library for host # ======================================================== diff --git a/libcutils/huawei.c b/libcutils/huawei.c new file mode 100644 index 00000000..5ab5e9e2 --- /dev/null +++ b/libcutils/huawei.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2015 The CyanogenMod 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 "app_info" + +#include +#include + +#include +#include +#include +#include + +int get_app_info(char* key, char* value) { + int ret = 0; + size_t end = 0; + char* buf; + size_t n; + FILE* fd; + + ALOGI("Getting App Info for %s", key); + + if(key == NULL) { + ALOGE("Key is null"); + return -1; + } + + buf = (char*) malloc(4096); + if(buf == NULL) { + ALOGE("Failed to allocate App Info buffer"); + return -2; + } + + fd = fopen("/proc/app_info", "r"); + if(fd == NULL) { + ALOGE("Failed to open /proc/app_info: %s", strerror(errno)); + ret = -3; + goto exit_free; + } + + n = fread(buf, 1, 4096, fd); + fclose(fd); + + /* Find key in app_info */ + buf = strstr(buf, key); + if(buf == NULL) { + ret = -4; + goto exit_free; + } + + /* Move to next : */ + buf = strstr(buf, ":"); + if(buf == NULL) { + return -5; + goto exit_free; + } + + /* Skip whitespace */ + while(buf[0] == ' ') { + buf++; + } + + /* Find trailing newline */ + while(buf[end] != ' ') { + end++; + } + + strncpy(value, buf, end); + + ALOGI("%s=%s", key, value); + + exit_free: + free(buf); + exit: + return ret; +} diff --git a/liblog/Android.mk b/liblog/Android.mk index bbcae54f..581cf7d6 100644 --- a/liblog/Android.mk +++ b/liblog/Android.mk @@ -74,6 +74,10 @@ ifeq ($(TARGET_USES_MOTOROLA_LOG),true) LIBLOG_CFLAGS := -DMOTOROLA_LOG endif +ifeq ($(TARGET_USES_HUAWEI_LOG),true) +LIBLOG_CFLAGS := -DHUAWEI_LOG +endif + # Shared and static library for target # ======================================================== include $(CLEAR_VARS) diff --git a/liblog/logd_write.c b/liblog/logd_write.c index ee10d580..1ebf2821 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -195,6 +195,11 @@ int __android_log_loggable(int prio, const char *tag) } #endif +#ifdef HUAWEI_LOG +void __android_logPower_print(void) { +} +#endif + #if !FAKE_LOG_DEVICE /* give up, resources too limited */ static int __write_to_log_null(log_id_t log_fd __unused, struct iovec *vec __unused, From 71b40a776f89be442f9a9e8d67f391448c82f43f Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Thu, 5 Mar 2015 10:59:57 -0800 Subject: [PATCH 217/243] Revert "fs_mgr: let fsck.f2fs actually attempt a fix" fsck.f2fs will correctly fix when it's required, without the -f flag. This reverts commit eb6036ac6be82dcc6e110de22574972631c8f83e. Change-Id: Iec9ca5e593b61f24b02db30bff7089fafee7635e Reviewed-on: http://gerrit.mot.com/721774 SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Christopher Fries Submit-Approved: Jira Key --- fs_mgr/fs_mgr.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index d1f1a1b8..6453e378 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -143,12 +143,12 @@ static void check_fs(char *blk_device, char *fs_type, char *target) } } } else if (!strcmp(fs_type, "f2fs")) { - char *f2fs_fsck_argv[] = { - F2FS_FSCK_BIN, - "-f", - blk_device - }; - INFO("Running %s -f %s\n", F2FS_FSCK_BIN, blk_device); + char *f2fs_fsck_argv[] = { + F2FS_FSCK_BIN, + "-a", + blk_device + }; + INFO("Running %s on %s\n", F2FS_FSCK_BIN, blk_device); ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), f2fs_fsck_argv, &status, true, LOG_KLOG | LOG_FILE, From 9755cd16a015533b004982d3a332b95cd380a896 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Fri, 28 Aug 2015 06:40:23 -0700 Subject: [PATCH 218/243] VectorImpl.cpp: fix benign multiplication overflow j is a ssize_t, which can go negative. If it goes negative, the resulting multiplication of mItemSize*j doesn't make any sense. Since the value is never used, just don't perform the calculation if j < 0. Bug: 23607865 Change-Id: I14f6f6506645d582f7d67a2e2d60ead3cb18b957 --- libutils/VectorImpl.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libutils/VectorImpl.cpp b/libutils/VectorImpl.cpp index c4944cf8..8886f781 100644 --- a/libutils/VectorImpl.cpp +++ b/libutils/VectorImpl.cpp @@ -198,7 +198,10 @@ status_t VectorImpl::sort(VectorImpl::compar_r_t cmp, void* state) _do_copy(next, curr, 1); next = curr; --j; - curr = reinterpret_cast(array) + mItemSize*(j); + curr = NULL; + if (j >= 0) { + curr = reinterpret_cast(array) + mItemSize*(j); + } } while (j>=0 && (cmp(curr, temp, state) > 0)); _do_destroy(next, 1); From 4c1fa45c92580d76a4678623d5bfd91bc83d0b0e Mon Sep 17 00:00:00 2001 From: Johan Redestig Date: Sat, 24 Jan 2015 19:00:39 +0100 Subject: [PATCH 219/243] sdcard: Turn on noatime for fuse mounted sdcard This provides symmetry with /data and /cache that are typically mounted with noatime. Change-Id: I6fe1bead368b52632424b03b50d4081852824cdb --- sdcard/sdcard.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c index 3b32612c..ec394df5 100644 --- a/sdcard/sdcard.c +++ b/sdcard/sdcard.c @@ -1840,7 +1840,8 @@ static int run(const char* source_path, const char* dest_path, uid_t uid, "fd=%i,rootmode=40000,default_permissions,allow_other,user_id=%d,group_id=%d", fd, uid, gid); - res = mount("/dev/fuse", dest_path, "fuse", MS_NOSUID | MS_NODEV | MS_NOEXEC, opts); + res = mount("/dev/fuse", dest_path, "fuse", MS_NOSUID | MS_NODEV | MS_NOEXEC | + MS_NOATIME, opts); if (res < 0) { ERROR("cannot mount fuse filesystem: %s\n", strerror(errno)); goto error; From 8af7057f0dc10db086cb526e3c39f8926833c230 Mon Sep 17 00:00:00 2001 From: Krzysztof Adamski Date: Wed, 16 Jul 2014 08:34:30 +0200 Subject: [PATCH 220/243] sdcard: Properly handle deleted nodes The sdcard fuse deamon is not properly handling deleted nodes that are still in use (opened by some process). Typically Linux filesystems makes it possible to open a file, unlink it and then still use it. In case of a storage emulated by sdcard deamon this does not work as expected - other process are not able to recreate file/dir with the same name until all references to deleted file are closed. The easiest way to trigger this problem is: process1: mkdir /sdcard/test1; cd /sdcard/test1 process2: rm -r /sdcard/test1 process2: mkdir /sdcard/test1 After that, process2 will get an error: mkdir failed for /sdcard/test1, Device or resource busy There is exactly the same problem with files as directories. This may case issues for example with directories that are automatically recreated when they are missing (like DCIM directory). If some process holds file opened inside of such directory but that directory is removed, process trying to recreate the directory will get EBUSY error and possibly crash. Verified on the Z Ultra GPE. Change-Id: I1cbf0bec135e6aaafba0ce8e5bb594e3639e0007 --- sdcard/sdcard.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c index ec394df5..a29462ce 100644 --- a/sdcard/sdcard.c +++ b/sdcard/sdcard.c @@ -198,6 +198,8 @@ struct node { * position. Used to support things like OBB. */ char* graft_path; size_t graft_pathlen; + + bool deleted; }; static int str_hash(void *key) { @@ -630,6 +632,8 @@ struct node *create_node_locked(struct fuse* fuse, node->ino = fuse->inode_ctr++; node->gen = fuse->next_generation++; + node->deleted = false; + derive_permissions_locked(fuse, parent, node); acquire_node_locked(node); add_node_to_parent_locked(node, parent); @@ -703,7 +707,7 @@ static struct node *lookup_child_by_name_locked(struct node *node, const char *n * must be considered distinct even if they refer to the same * underlying file as otherwise operations such as "mv x x" * will not work because the source and target nodes are the same. */ - if (!strcmp(name, node->name)) { + if (!strcmp(name, node->name) && !node->deleted) { return node; } } @@ -1067,6 +1071,7 @@ static int handle_unlink(struct fuse* fuse, struct fuse_handler* handler, { bool has_rw; struct node* parent_node; + struct node* child_node; char parent_path[PATH_MAX]; char child_path[PATH_MAX]; @@ -1088,6 +1093,12 @@ static int handle_unlink(struct fuse* fuse, struct fuse_handler* handler, if (unlink(child_path) < 0) { return -errno; } + pthread_mutex_lock(&fuse->lock); + child_node = lookup_child_by_name_locked(parent_node, name); + if (child_node) { + child_node->deleted = true; + } + pthread_mutex_unlock(&fuse->lock); return 0; } @@ -1095,6 +1106,7 @@ static int handle_rmdir(struct fuse* fuse, struct fuse_handler* handler, const struct fuse_in_header* hdr, const char* name) { bool has_rw; + struct node* child_node; struct node* parent_node; char parent_path[PATH_MAX]; char child_path[PATH_MAX]; @@ -1117,6 +1129,12 @@ static int handle_rmdir(struct fuse* fuse, struct fuse_handler* handler, if (rmdir(child_path) < 0) { return -errno; } + pthread_mutex_lock(&fuse->lock); + child_node = lookup_child_by_name_locked(parent_node, name); + if (child_node) { + child_node->deleted = true; + } + pthread_mutex_unlock(&fuse->lock); return 0; } From 979ef7f19c9fe3fe358bc3643281f293e74e88b6 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Mon, 7 Sep 2015 13:32:21 -0700 Subject: [PATCH 221/243] init: Fire a trigger when a class is started/stopped * This allows us to react to these events without messing with the master config. Change-Id: Ifc72efc7b4cc0718838c711395f5fdc3b043827a --- init/builtins.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/init/builtins.c b/init/builtins.c index 50651cff..9ceebb39 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -202,23 +202,35 @@ int do_chroot(int nargs, char **args) int do_class_start(int nargs, char **args) { - /* Starting a class does not start services - * which are explicitly disabled. They must - * be started individually. - */ + char prop[PROP_NAME_MAX]; + snprintf(prop, PROP_NAME_MAX, "class_start:%s", args[1]); + + /* Starting a class does not start services + * which are explicitly disabled. They must + * be started individually. + */ service_for_each_class(args[1], service_start_if_not_disabled); + action_for_each_trigger(prop, action_add_queue_tail); return 0; } int do_class_stop(int nargs, char **args) { + char prop[PROP_NAME_MAX]; + snprintf(prop, PROP_NAME_MAX, "class_stop:%s", args[1]); + service_for_each_class(args[1], service_stop); + action_for_each_trigger(prop, action_add_queue_tail); return 0; } int do_class_reset(int nargs, char **args) { + char prop[PROP_NAME_MAX]; + snprintf(prop, PROP_NAME_MAX, "class_reset:%s", args[1]); + service_for_each_class(args[1], service_reset); + action_for_each_trigger(prop, action_add_queue_tail); return 0; } From 0e9caa6bd1c1eff907652c5722bb49aec30ffb5d Mon Sep 17 00:00:00 2001 From: Keith Mok Date: Tue, 8 Sep 2015 00:01:57 -0700 Subject: [PATCH 222/243] Fix build break for multiple definition Remove unneeded library linked Change-Id: Ice26d83a73c59460d717340ca57ee898d002dc54 --- fastboot/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastboot/Android.mk b/fastboot/Android.mk index 1aba42b2..8a42b54a 100644 --- a/fastboot/Android.mk +++ b/fastboot/Android.mk @@ -69,7 +69,7 @@ LOCAL_LDFLAGS += -ldl -rdynamic -Wl,-rpath,. LOCAL_REQUIRED_MODULES := libf2fs_fmt_host_dyn # The following libf2fs_* are from system/extras/f2fs_utils, # and do not use code in external/f2fs-tools. -LOCAL_STATIC_LIBRARIES += libf2fs_utils_host libf2fs_ioutils_host libf2fs_dlutils_host +LOCAL_STATIC_LIBRARIES += libf2fs_utils_host libf2fs_dlutils_host endif include $(BUILD_HOST_EXECUTABLE) From 180c1d08f5295e09a24f77344464d44f3880553f Mon Sep 17 00:00:00 2001 From: Keith Mok Date: Tue, 8 Sep 2015 00:01:57 -0700 Subject: [PATCH 223/243] Fix build break for multiple definition Remove unneeded library linked Change-Id: Ice26d83a73c59460d717340ca57ee898d002dc54 --- fastboot/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastboot/Android.mk b/fastboot/Android.mk index 1aba42b2..8a42b54a 100644 --- a/fastboot/Android.mk +++ b/fastboot/Android.mk @@ -69,7 +69,7 @@ LOCAL_LDFLAGS += -ldl -rdynamic -Wl,-rpath,. LOCAL_REQUIRED_MODULES := libf2fs_fmt_host_dyn # The following libf2fs_* are from system/extras/f2fs_utils, # and do not use code in external/f2fs-tools. -LOCAL_STATIC_LIBRARIES += libf2fs_utils_host libf2fs_ioutils_host libf2fs_dlutils_host +LOCAL_STATIC_LIBRARIES += libf2fs_utils_host libf2fs_dlutils_host endif include $(BUILD_HOST_EXECUTABLE) From d551b518bdcdb9c71510d8dbe52dc1ba0375502e Mon Sep 17 00:00:00 2001 From: Sultan Qasim Khan Date: Mon, 7 Sep 2015 01:30:17 -0400 Subject: [PATCH 224/243] fs_mgr: zram: allow specifying stream count This parameter allows specifying the number of parallel streams to be used in compression and decompression. This option was added in Linux 3.15, so it is not very common among devices currently on the market, but it has been backported to some kernels. This option must be set before zRAM is activated, as the kernel does not allow switching from single stream to multistream compression once zRAM is active. Change-Id: I3f5ad96a65b3b4a6915d2700c398a236ea8931b0 --- fs_mgr/fs_mgr.c | 9 +++++++++ fs_mgr/fs_mgr_fstab.c | 6 ++++++ fs_mgr/fs_mgr_priv.h | 1 + fs_mgr/include/fs_mgr.h | 1 + 4 files changed, 17 insertions(+) diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index 6453e378..bb96f3f3 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -57,6 +57,7 @@ #define FSCK_LOG_FILE "/dev/fscklogs/log" #define ZRAM_CONF_DEV "/sys/block/zram0/disksize" +#define ZRAM_STREAMS "/sys/block/zram0/max_comp_streams" #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) @@ -650,6 +651,14 @@ int fs_mgr_swapon_all(struct fstab *fstab) */ FILE *zram_fp; + /* The stream count parameter is only available on new kernels. + * It must be set before the disk size. */ + zram_fp = fopen(ZRAM_STREAMS, "r+"); + if (zram_fp) { + fprintf(zram_fp, "%d\n", fstab->recs[i].zram_streams); + fclose(zram_fp); + } + zram_fp = fopen(ZRAM_CONF_DEV, "r+"); if (zram_fp == NULL) { ERROR("Unable to open zram conf device %s\n", ZRAM_CONF_DEV); diff --git a/fs_mgr/fs_mgr_fstab.c b/fs_mgr/fs_mgr_fstab.c index edd95911..77580621 100644 --- a/fs_mgr/fs_mgr_fstab.c +++ b/fs_mgr/fs_mgr_fstab.c @@ -29,6 +29,7 @@ struct fs_mgr_flag_values { int partnum; int swap_prio; unsigned int zram_size; + unsigned int zram_streams; }; struct flag_list { @@ -69,6 +70,7 @@ static struct flag_list fs_mgr_flags[] = { { "verify", MF_VERIFY }, { "noemulatedsd", MF_NOEMULATEDSD }, { "formattable", MF_FORMATTABLE }, + { "zramstreams=",MF_ZRAMSTREAMS }, { "defaults", 0 }, { 0, 0 }, }; @@ -88,6 +90,7 @@ static int parse_flags(char *flags, struct flag_list *fl, memset(flag_vals, 0, sizeof(*flag_vals)); flag_vals->partnum = -1; flag_vals->swap_prio = -1; /* negative means it wasn't specified. */ + flag_vals->zram_streams = 1; } /* initialize fs_options to the null string */ @@ -147,6 +150,8 @@ static int parse_flags(char *flags, struct flag_list *fl, flag_vals->swap_prio = strtoll(strchr(p, '=') + 1, NULL, 0); } else if ((fl[i].flag == MF_ZRAMSIZE) && flag_vals) { flag_vals->zram_size = strtoll(strchr(p, '=') + 1, NULL, 0); + } else if ((fl[i].flag == MF_ZRAMSTREAMS) && flag_vals) { + flag_vals->zram_streams = strtoll(strchr(p, '=') + 1, NULL, 0); } break; } @@ -297,6 +302,7 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path) fstab->recs[cnt].partnum = flag_vals.partnum; fstab->recs[cnt].swap_prio = flag_vals.swap_prio; fstab->recs[cnt].zram_size = flag_vals.zram_size; + fstab->recs[cnt].zram_streams = flag_vals.zram_streams; cnt++; } fclose(fstab_file); diff --git a/fs_mgr/fs_mgr_priv.h b/fs_mgr/fs_mgr_priv.h index fd583065..fe960ba7 100644 --- a/fs_mgr/fs_mgr_priv.h +++ b/fs_mgr/fs_mgr_priv.h @@ -76,6 +76,7 @@ #define MF_NOEMULATEDSD 0x800 /* no emulated sdcard daemon, sd card is the only external storage */ #define MF_FORMATTABLE 0x1000 +#define MF_ZRAMSTREAMS 0x2000 #define DM_BUF_SIZE 4096 diff --git a/fs_mgr/include/fs_mgr.h b/fs_mgr/include/fs_mgr.h index 509b3271..0d92c562 100644 --- a/fs_mgr/include/fs_mgr.h +++ b/fs_mgr/include/fs_mgr.h @@ -56,6 +56,7 @@ struct fstab_rec { int partnum; int swap_prio; unsigned int zram_size; + unsigned int zram_streams; }; struct fstab *fs_mgr_read_fstab(const char *fstab_path); From 3e09a0747605844c3917752192f5a9f8e804c48b Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Mon, 7 Sep 2015 14:30:31 +0100 Subject: [PATCH 225/243] fs_mgr: When formating ext4 volumes, respect the length parameter When formatting a volume because it is marked as formattable, the length parameter is discarded which makes fs_mgr write a filesystem to the full length of the block device. This patch adds length semantics to ext4 formatting, if the length is greater than zero, use that, if it isn't subtract that size from the block size. Change-Id: I4d18d5161360f8de0e571352e705678682e61332 Ticket: CYNGNOS-931 --- fs_mgr/fs_mgr_format.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs_mgr/fs_mgr_format.c b/fs_mgr/fs_mgr_format.c index f39e0e46..2e8f2aee 100644 --- a/fs_mgr/fs_mgr_format.c +++ b/fs_mgr/fs_mgr_format.c @@ -31,7 +31,7 @@ extern struct fs_info info; /* magic global from ext4_utils */ extern void reset_ext4fs_info(); -static int format_ext4(char *fs_blkdev, char *fs_mnt_point) +static int format_ext4(char *fs_blkdev, char *fs_mnt_point, long long fs_length) { unsigned int nr_sec; int fd, rc = 0; @@ -51,6 +51,12 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point) reset_ext4fs_info(); info.len = ((off64_t)nr_sec * 512); + if (fs_length > 0) { + info.len = fs_length; + } else if (fs_length < 0) { + info.len += fs_length; + } + /* Use make_ext4fs_internal to avoid wiping an already-wiped partition. */ rc = make_ext4fs_internal(fd, NULL, fs_mnt_point, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL); if (rc) { @@ -110,7 +116,7 @@ int fs_mgr_do_format(struct fstab_rec *fstab) if (!strncmp(fstab->fs_type, "f2fs", 4)) { rc = format_f2fs(fstab->blk_device); } else if (!strncmp(fstab->fs_type, "ext4", 4)) { - rc = format_ext4(fstab->blk_device, fstab->mount_point); + rc = format_ext4(fstab->blk_device, fstab->mount_point, fstab->length); } else { ERROR("File system type '%s' is not supported\n", fstab->fs_type); } From 6306b5ec197f559cfbd016073a731e286d7b333b Mon Sep 17 00:00:00 2001 From: Vijay Kumar Tumati Date: Wed, 22 Apr 2015 13:40:22 +0530 Subject: [PATCH 226/243] Camera: Longshot with Burst Functionality. New Longshot stop command is sent after receiving all the required YUV callbacks or releasing the shutter before reaching Max number. Change-Id: Ifc9db1f27ce8b23df4b007ae6231299c5ab412f6 --- include/system/camera.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/system/camera.h b/include/system/camera.h index 5f2a9efb..bfaf210c 100644 --- a/include/system/camera.h +++ b/include/system/camera.h @@ -196,6 +196,7 @@ enum { CAMERA_CMD_HISTOGRAM_SEND_DATA = 13, CAMERA_CMD_LONGSHOT_ON = 14, CAMERA_CMD_LONGSHOT_OFF = 15, + CAMERA_CMD_STOP_LONGSHOT = 16, CAMERA_CMD_METADATA_ON = 100, CAMERA_CMD_METADATA_OFF = 101, }; From b767d5d80f28dfa37044754d3e5859937ed6a5e4 Mon Sep 17 00:00:00 2001 From: Ethan Chen Date: Thu, 10 Sep 2015 08:58:13 -0700 Subject: [PATCH 227/243] Revert "Charger: Add font to show real battery capacity in charger mode." This reverts commit a213c369278444eab0bebef5e50d7532a1a59fba. Change-Id: Id294aedce4393e16052f4047980b75439de8650f --- healthd/Android.mk | 4 ---- 1 file changed, 4 deletions(-) diff --git a/healthd/Android.mk b/healthd/Android.mk index cd2f1705..37e5490c 100644 --- a/healthd/Android.mk +++ b/healthd/Android.mk @@ -82,11 +82,7 @@ _img_modules += $$(LOCAL_MODULE) LOCAL_SRC_FILES := $1 LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := ETC -ifeq ($(strip $(BOARD_HEALTHD_CUSTOM_CHARGER_RES)),) LOCAL_MODULE_PATH := $$(TARGET_ROOT_OUT)/res/images/charger -else -LOCAL_MODULE_PATH := $$(TARGET_ROOT_OUT)/res/images -endif include $$(BUILD_PREBUILT) endef From 8ce6fe3ba40899d8b2023b04352d73be67bb0a92 Mon Sep 17 00:00:00 2001 From: Rob Shannon Date: Wed, 9 Sep 2015 15:52:27 -0700 Subject: [PATCH 228/243] Revert "libcutils/liblog: Add functions required by Huawei g620_a2 binaries" This reverts commit e575b4ab70d0524a1faf6c2e768aa409382cec22. Change-Id: I4c7f9c64cb44e599947c7aa85c9e3aa22d9e3131 --- include/cutils/huawei.h | 30 -------------- libcutils/Android.mk | 4 -- libcutils/huawei.c | 89 ----------------------------------------- liblog/Android.mk | 4 -- liblog/logd_write.c | 5 --- 5 files changed, 132 deletions(-) delete mode 100644 include/cutils/huawei.h delete mode 100644 libcutils/huawei.c diff --git a/include/cutils/huawei.h b/include/cutils/huawei.h deleted file mode 100644 index f3798c97..00000000 --- a/include/cutils/huawei.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2006 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 __CUTILS_HUAWEI_H -#define __CUTILS_HUAWEI_H - -#ifdef __cplusplus -extern "C" { -#endif - - int get_app_info(char* key, char* value); - -#ifdef __cplusplus -} -#endif - -#endif /* __CUTILS_HUAWEI_H */ diff --git a/libcutils/Android.mk b/libcutils/Android.mk index 1431034d..bee2bd75 100644 --- a/libcutils/Android.mk +++ b/libcutils/Android.mk @@ -71,10 +71,6 @@ ifneq ($(WINDOWS_HOST_ONLY),1) endif -ifeq ($(TARGET_USES_HUAWEI_APP_INFO),true) - commonSources += \ - huawei.c -endif # Static library for host # ======================================================== diff --git a/libcutils/huawei.c b/libcutils/huawei.c deleted file mode 100644 index 5ab5e9e2..00000000 --- a/libcutils/huawei.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2015 The CyanogenMod 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 "app_info" - -#include -#include - -#include -#include -#include -#include - -int get_app_info(char* key, char* value) { - int ret = 0; - size_t end = 0; - char* buf; - size_t n; - FILE* fd; - - ALOGI("Getting App Info for %s", key); - - if(key == NULL) { - ALOGE("Key is null"); - return -1; - } - - buf = (char*) malloc(4096); - if(buf == NULL) { - ALOGE("Failed to allocate App Info buffer"); - return -2; - } - - fd = fopen("/proc/app_info", "r"); - if(fd == NULL) { - ALOGE("Failed to open /proc/app_info: %s", strerror(errno)); - ret = -3; - goto exit_free; - } - - n = fread(buf, 1, 4096, fd); - fclose(fd); - - /* Find key in app_info */ - buf = strstr(buf, key); - if(buf == NULL) { - ret = -4; - goto exit_free; - } - - /* Move to next : */ - buf = strstr(buf, ":"); - if(buf == NULL) { - return -5; - goto exit_free; - } - - /* Skip whitespace */ - while(buf[0] == ' ') { - buf++; - } - - /* Find trailing newline */ - while(buf[end] != ' ') { - end++; - } - - strncpy(value, buf, end); - - ALOGI("%s=%s", key, value); - - exit_free: - free(buf); - exit: - return ret; -} diff --git a/liblog/Android.mk b/liblog/Android.mk index 581cf7d6..bbcae54f 100644 --- a/liblog/Android.mk +++ b/liblog/Android.mk @@ -74,10 +74,6 @@ ifeq ($(TARGET_USES_MOTOROLA_LOG),true) LIBLOG_CFLAGS := -DMOTOROLA_LOG endif -ifeq ($(TARGET_USES_HUAWEI_LOG),true) -LIBLOG_CFLAGS := -DHUAWEI_LOG -endif - # Shared and static library for target # ======================================================== include $(CLEAR_VARS) diff --git a/liblog/logd_write.c b/liblog/logd_write.c index 1ebf2821..ee10d580 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -195,11 +195,6 @@ int __android_log_loggable(int prio, const char *tag) } #endif -#ifdef HUAWEI_LOG -void __android_logPower_print(void) { -} -#endif - #if !FAKE_LOG_DEVICE /* give up, resources too limited */ static int __write_to_log_null(log_id_t log_fd __unused, struct iovec *vec __unused, From fbb3be9993baeb125cb4b782ee89ed8ff4500bcc Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Wed, 9 Sep 2015 02:16:37 -0700 Subject: [PATCH 229/243] rootdir: Set ioprio for SurfaceFlinger * Run SurfaceFlinger with realtime priority 7. * Improves responsiveness of the entire UI. Change-Id: Ib4f44910e50f12980f070c23a30e0495e5f7495b --- rootdir/init.rc | 1 + 1 file changed, 1 insertion(+) diff --git a/rootdir/init.rc b/rootdir/init.rc index 029d7deb..6d6c6c09 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -563,6 +563,7 @@ service surfaceflinger /system/bin/surfaceflinger class core user system group graphics drmrpc + ioprio rt 6 onrestart restart zygote service drm /system/bin/drmserver From eeaeeb6979d137c81c40d7af3512cd1cb2516f92 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Tue, 8 Sep 2015 02:23:41 -0700 Subject: [PATCH 230/243] cutils: Add support for BFQIO cgroups * Add support for a custom hierarchy of cgroups on top of the BFQ IO scheduler. This allows us to place every thread into the right class (realtime/best-effort/idle) with a set up priority buckets depending on use case. * The benefit of doing this is pretty incredible from an interactivity standpoint. Realtime users (display/audio) benefit the most, resulting in glitch-free audio and jank-free video. Dexopting in the background no longer causes active harm to foreground tasks. Other tasks such as account syncing become invisible from the user's perspective. * Magic bullet? Perhaps. Change-Id: I4eb911395364ce46d6dcbff43e94286ded03a97d --- include/cutils/iosched_policy.h | 2 + libcutils/iosched_policy.c | 114 ++++++++++++++++++++++++++++++++ libutils/Threads.cpp | 12 +++- 3 files changed, 127 insertions(+), 1 deletion(-) diff --git a/include/cutils/iosched_policy.h b/include/cutils/iosched_policy.h index 07c5d1fc..1b06f2cd 100644 --- a/include/cutils/iosched_policy.h +++ b/include/cutils/iosched_policy.h @@ -31,6 +31,8 @@ typedef enum { extern int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio); extern int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio); +extern int android_set_bfqio_prio(int pid, int prio); + #ifdef __cplusplus } #endif diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.c index a6da9cac..b14f3cbc 100644 --- a/libcutils/iosched_policy.c +++ b/libcutils/iosched_policy.c @@ -22,10 +22,13 @@ #include #include +#define LOG_TAG "iosched_policy" +#include #ifdef HAVE_ANDROID_OS #include #include +#include #define __android_unused #else #define __android_unused __attribute__((__unused__)) @@ -56,3 +59,114 @@ int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *iopri #endif return 0; } + +#ifdef HAVE_ANDROID_OS +static int __bfqio_cgroup_supported = -1; +static int rt_cgroup_fd = -1; +static int ui_cgroup_fd = -1; +static int hipri_cgroup_fd = -1; +static int fg_cgroup_fd = -1; +static int bg_cgroup_fd = -1; +static int idle_cgroup_fd = -1; +static pthread_once_t the_once = PTHREAD_ONCE_INIT; + +static void __initialize_bfqio(void) { + if (!access("/sys/fs/cgroup/bfqio/tasks", F_OK)) { + __bfqio_cgroup_supported = 1; + } else { + __bfqio_cgroup_supported = 0; + } +} + +static int __get_bfqio_fd(int prio) { + + if (__bfqio_cgroup_supported != 1) { + return -1; + } + + if (prio <= -18) { + if (rt_cgroup_fd < 0) { + rt_cgroup_fd = open("/sys/fs/cgroup/bfqio/rt/tasks", O_WRONLY | O_CLOEXEC); + } + return rt_cgroup_fd; + } else if (prio <= -8) { + if (ui_cgroup_fd < 0) { + ui_cgroup_fd = open("/sys/fs/cgroup/bfqio/ui/tasks", O_WRONLY | O_CLOEXEC); + } + return ui_cgroup_fd; + } else if (prio >= 18) { + if (idle_cgroup_fd < 0) { + idle_cgroup_fd = open("/sys/fs/cgroup/bfqio/idle/tasks", O_WRONLY | O_CLOEXEC); + } + return idle_cgroup_fd; + } else if (prio >= 10) { + if (bg_cgroup_fd < 0) { + bg_cgroup_fd = open("/sys/fs/cgroup/bfqio/bg/tasks", O_WRONLY | O_CLOEXEC); + } + return bg_cgroup_fd; + } + + if (fg_cgroup_fd < 0) { + fg_cgroup_fd = open("/sys/fs/cgroup/bfqio/tasks", O_WRONLY | O_CLOEXEC); + } + return fg_cgroup_fd; +} + +int android_set_bfqio_prio(int tid __android_unused, int prio __android_unused) +{ + struct stat st; + int fd; + + pthread_once(&the_once, __initialize_bfqio); + + if (__bfqio_cgroup_supported == 0) + return -1; + + if (prio < -19 || prio > 20) { + return -1; + } + + fd = __get_bfqio_fd(prio); + if (fd < 0) + return -1; + +#ifdef HAVE_GETTID + if (tid == 0) { + tid = gettid(); + } +#endif + + if (tid < 200) + return -1; + + // specialized itoa -- works for tid > 0 + char text[22]; + char *end = text + sizeof(text) - 1; + char *ptr = end; + *ptr = '\0'; + while (tid > 0) { + *--ptr = '0' + (tid % 10); + tid = tid / 10; + } + + if (write(fd, ptr, end - ptr) < 0) { + /* + * If the thread is in the process of exiting, + * don't flag an error + */ + if (errno == ESRCH) + return 0; + SLOGV("android_set_bfqio_prio failed to write '%s' (%s); fd=%d\n", + ptr, strerror(errno), fd); + return -1; + } + + return 0; +} + +#else +int android_set_bfqio_prio(int tid __android_unused, int prio __android_unused) +{ + return 0; +} +#endif diff --git a/libutils/Threads.cpp b/libutils/Threads.cpp index b09d5106..59418d53 100644 --- a/libutils/Threads.cpp +++ b/libutils/Threads.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #ifdef HAVE_ANDROID_OS @@ -98,6 +99,7 @@ struct thread_data_t { androidSetThreadName(name); free(name); } + return f(u); } }; @@ -338,8 +340,10 @@ int androidSetThreadPriority(pid_t tid, int pri) } else { errno = lasterr; } + + android_set_bfqio_prio(tid, pri); #endif - + return rc; } @@ -728,6 +732,12 @@ status_t Thread::run(const char* name, int32_t priority, size_t stack) return UNKNOWN_ERROR; } +#ifdef HAVE_ANDROID_OS + pid_t tid = __pthread_gettid(android_thread_id_t_to_pthread(mThread)); + if (tid >= 200) + android_set_bfqio_prio(tid, priority); +#endif + // Do not refer to mStatus here: The thread is already running (may, in fact // already have exited with a valid mStatus result). The NO_ERROR indication // here merely indicates successfully starting the thread and does not From 54521d04bbfe40f7f3d916943d7ccfc28280f67e Mon Sep 17 00:00:00 2001 From: Matt Mower Date: Tue, 15 Sep 2015 00:16:47 -0500 Subject: [PATCH 231/243] Revert "Add HTC Logging functions to support newer HTC props." This reverts commit 17417fff22477c9b699d16b4aaa1c49f441e0e31. Conflicts: liblog/logd_write.c liblog/logd_write_kern.c Change-Id: Ic2604afcef8431c5516151fe6be7f6f4b33fc342 --- liblog/logd_write.c | 17 ----------------- liblog/logd_write_kern.c | 17 ----------------- 2 files changed, 34 deletions(-) diff --git a/liblog/logd_write.c b/liblog/logd_write.c index ee10d580..4b9c7c7f 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -89,23 +89,6 @@ int __android_log_dev_available(void) return (g_log_status == kLogAvailable); } -#ifdef HTCLOG -signed int __htclog_read_masks(char *buf __unused, signed int len __unused) -{ - return 0; -} - -int __htclog_init_mask(const char *a1 __unused, unsigned int a2 __unused, int a3 __unused) -{ - return 0; -} - -int __htclog_print_private(int a1 __unused, const char *a2 __unused, const char *fmt __unused, ...) -{ - return 0; -} -#endif - #ifdef MOTOROLA_LOG /* Fallback when there is neither log.tag. nor log.tag.DEFAULT. * this is compile-time defaulted to "info". The log startup code diff --git a/liblog/logd_write_kern.c b/liblog/logd_write_kern.c index 34fcb1c7..a7bd61c1 100644 --- a/liblog/logd_write_kern.c +++ b/liblog/logd_write_kern.c @@ -93,23 +93,6 @@ int __android_log_dev_available(void) return (g_log_status == kLogAvailable); } -#ifdef HTCLOG -signed int __htclog_read_masks(char *buf __unused, signed int len __unused) -{ - return 0; -} - -int __htclog_init_mask(const char *a1 __unused, unsigned int a2 __unused, int a3 __unused) -{ - return 0; -} - -int __htclog_print_private(int a1 __unused, const char *a2 __unused, const char *fmt __unused, ...) -{ - return 0; -} -#endif - #ifdef MOTOROLA_LOG /* Fallback when there is neither log.tag. nor log.tag.DEFAULT. * this is compile-time defaulted to "info". The log startup code From d666fed4243fc7df63e254ed0d818c9245bb8ac4 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sat, 19 Sep 2015 12:43:40 -0700 Subject: [PATCH 232/243] cutils: Fix copypasta in ioprio code Change-Id: I976693be4a6913ed2090fa32d0f8e4c93657e7e7 --- libcutils/iosched_policy.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.c index b14f3cbc..1e8d6aea 100644 --- a/libcutils/iosched_policy.c +++ b/libcutils/iosched_policy.c @@ -62,8 +62,9 @@ int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *iopri #ifdef HAVE_ANDROID_OS static int __bfqio_cgroup_supported = -1; -static int rt_cgroup_fd = -1; -static int ui_cgroup_fd = -1; +static int rt_audio_cgroup_fd = -1; +static int rt_display_cgroup_fd = -1; +static int display_cgroup_fd = -1; static int hipri_cgroup_fd = -1; static int fg_cgroup_fd = -1; static int bg_cgroup_fd = -1; @@ -84,16 +85,26 @@ static int __get_bfqio_fd(int prio) { return -1; } - if (prio <= -18) { - if (rt_cgroup_fd < 0) { - rt_cgroup_fd = open("/sys/fs/cgroup/bfqio/rt/tasks", O_WRONLY | O_CLOEXEC); + if (prio < -17) { + if (rt_audio_cgroup_fd < 0) { + rt_audio_cgroup_fd = open("/sys/fs/cgroup/bfqio/rt-audio/tasks", O_WRONLY | O_CLOEXEC); } - return rt_cgroup_fd; - } else if (prio <= -8) { - if (ui_cgroup_fd < 0) { - ui_cgroup_fd = open("/sys/fs/cgroup/bfqio/ui/tasks", O_WRONLY | O_CLOEXEC); + return rt_audio_cgroup_fd; + } else if (prio < -7) { + if (rt_display_cgroup_fd < 0) { + rt_display_cgroup_fd = open("/sys/fs/cgroup/bfqio/rt-display/tasks", O_WRONLY | O_CLOEXEC); } - return ui_cgroup_fd; + return rt_display_cgroup_fd; + } else if (prio < -2) { + if (display_cgroup_fd < 0) { + display_cgroup_fd = open("/sys/fs/cgroup/bfqio/display/tasks", O_WRONLY | O_CLOEXEC); + } + return display_cgroup_fd; + } else if (prio < 1) { + if (hipri_cgroup_fd < 0) { + hipri_cgroup_fd = open("/sys/fs/cgroup/bfqio/hipri/tasks", O_WRONLY | O_CLOEXEC); + } + return hipri_cgroup_fd; } else if (prio >= 18) { if (idle_cgroup_fd < 0) { idle_cgroup_fd = open("/sys/fs/cgroup/bfqio/idle/tasks", O_WRONLY | O_CLOEXEC); From a6424305ff5823dbf210e96e614fdecab8987bd8 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sun, 20 Sep 2015 01:08:07 -0700 Subject: [PATCH 233/243] cutils: Fix display ioprio * A few unwanted items are sneaking into this class resulting in system slowdowns. Fixit. Change-Id: I29033a38adf2c65535f916135d395d5147afe323 --- libcutils/iosched_policy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.c index 1e8d6aea..f3969596 100644 --- a/libcutils/iosched_policy.c +++ b/libcutils/iosched_policy.c @@ -90,7 +90,7 @@ static int __get_bfqio_fd(int prio) { rt_audio_cgroup_fd = open("/sys/fs/cgroup/bfqio/rt-audio/tasks", O_WRONLY | O_CLOEXEC); } return rt_audio_cgroup_fd; - } else if (prio < -7) { + } else if (prio < -8) { if (rt_display_cgroup_fd < 0) { rt_display_cgroup_fd = open("/sys/fs/cgroup/bfqio/rt-display/tasks", O_WRONLY | O_CLOEXEC); } From 3328ca3bc5f389e4d3b728300d260e6717e6ae1b Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sun, 20 Sep 2015 03:00:54 -0700 Subject: [PATCH 234/243] cutils: Clean up ioprio grouping * It's now better understood what's happening system-wide due to these changes, so clean up the stuff which is not necessary and/or potentially harmful. Change-Id: I72178770844c1ac388a0b424b12cdc49042aec87 --- libcutils/iosched_policy.c | 18 ++++-------------- rootdir/init.rc | 1 - 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.c index f3969596..bd91382f 100644 --- a/libcutils/iosched_policy.c +++ b/libcutils/iosched_policy.c @@ -95,16 +95,6 @@ static int __get_bfqio_fd(int prio) { rt_display_cgroup_fd = open("/sys/fs/cgroup/bfqio/rt-display/tasks", O_WRONLY | O_CLOEXEC); } return rt_display_cgroup_fd; - } else if (prio < -2) { - if (display_cgroup_fd < 0) { - display_cgroup_fd = open("/sys/fs/cgroup/bfqio/display/tasks", O_WRONLY | O_CLOEXEC); - } - return display_cgroup_fd; - } else if (prio < 1) { - if (hipri_cgroup_fd < 0) { - hipri_cgroup_fd = open("/sys/fs/cgroup/bfqio/hipri/tasks", O_WRONLY | O_CLOEXEC); - } - return hipri_cgroup_fd; } else if (prio >= 18) { if (idle_cgroup_fd < 0) { idle_cgroup_fd = open("/sys/fs/cgroup/bfqio/idle/tasks", O_WRONLY | O_CLOEXEC); @@ -117,10 +107,10 @@ static int __get_bfqio_fd(int prio) { return bg_cgroup_fd; } - if (fg_cgroup_fd < 0) { - fg_cgroup_fd = open("/sys/fs/cgroup/bfqio/tasks", O_WRONLY | O_CLOEXEC); - } - return fg_cgroup_fd; +// if (fg_cgroup_fd < 0) { +// fg_cgroup_fd = open("/sys/fs/cgroup/bfqio/tasks", O_WRONLY | O_CLOEXEC); +// } + return -1; } int android_set_bfqio_prio(int tid __android_unused, int prio __android_unused) diff --git a/rootdir/init.rc b/rootdir/init.rc index 6d6c6c09..029d7deb 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -563,7 +563,6 @@ service surfaceflinger /system/bin/surfaceflinger class core user system group graphics drmrpc - ioprio rt 6 onrestart restart zygote service drm /system/bin/drmserver From 8df64c7afe30ec131d3c559bb67d16e538b23182 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Sun, 20 Sep 2015 17:36:54 -0700 Subject: [PATCH 235/243] cutils: Remove ioprio magic * ..and replace it with something we can call explictly where it is required in order to achieve the same goodness without the badness. Change-Id: I605b3acbc56ce82663dd6f1c9f3320d0ab75e178 --- include/cutils/iosched_policy.h | 2 +- libcutils/iosched_policy.c | 127 +++++++++++--------------------- libutils/Threads.cpp | 9 --- 3 files changed, 45 insertions(+), 93 deletions(-) diff --git a/include/cutils/iosched_policy.h b/include/cutils/iosched_policy.h index 1b06f2cd..25b87bac 100644 --- a/include/cutils/iosched_policy.h +++ b/include/cutils/iosched_policy.h @@ -31,7 +31,7 @@ typedef enum { extern int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio); extern int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio); -extern int android_set_bfqio_prio(int pid, int prio); +extern int android_set_rt_ioprio(int pid, int rt); #ifdef __cplusplus } diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.c index bd91382f..e1f1b1d8 100644 --- a/libcutils/iosched_policy.c +++ b/libcutils/iosched_policy.c @@ -1,9 +1,10 @@ /* ** Copyright 2007-2014, The Android Open Source Project +** Copyright 2015, The CyanogenMod 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 +** 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 ** @@ -25,26 +26,24 @@ #define LOG_TAG "iosched_policy" #include +#define __android_unused __attribute__((__unused__)) + #ifdef HAVE_ANDROID_OS #include #include #include -#define __android_unused -#else -#define __android_unused __attribute__((__unused__)) -#endif + +static int __rtio_cgroup_supported = -1; +static pthread_once_t __rtio_init_once = PTHREAD_ONCE_INIT; int android_set_ioprio(int pid __android_unused, IoSchedClass clazz __android_unused, int ioprio __android_unused) { -#ifdef HAVE_ANDROID_OS if (syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, pid, ioprio | (clazz << IOPRIO_CLASS_SHIFT))) { return -1; } -#endif return 0; } int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *ioprio) { -#ifdef HAVE_ANDROID_OS int rc; if ((rc = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, pid)) < 0) { @@ -53,93 +52,42 @@ int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *iopri *clazz = (rc >> IOPRIO_CLASS_SHIFT); *ioprio = (rc & 0xff); -#else - *clazz = IoSchedClass_NONE; - *ioprio = 0; -#endif return 0; } -#ifdef HAVE_ANDROID_OS -static int __bfqio_cgroup_supported = -1; -static int rt_audio_cgroup_fd = -1; -static int rt_display_cgroup_fd = -1; -static int display_cgroup_fd = -1; -static int hipri_cgroup_fd = -1; -static int fg_cgroup_fd = -1; -static int bg_cgroup_fd = -1; -static int idle_cgroup_fd = -1; -static pthread_once_t the_once = PTHREAD_ONCE_INIT; - -static void __initialize_bfqio(void) { - if (!access("/sys/fs/cgroup/bfqio/tasks", F_OK)) { - __bfqio_cgroup_supported = 1; +static void __initialize_rtio(void) { + if (!access("/sys/fs/cgroup/bfqio/tasks", W_OK) || + !access("/sys/fs/cgroup/bfqio/rt-display/tasks", W_OK)) { + __rtio_cgroup_supported = 1; } else { - __bfqio_cgroup_supported = 0; + __rtio_cgroup_supported = 0; } } -static int __get_bfqio_fd(int prio) { +int android_set_rt_ioprio(int tid, int rt) { + int fd = -1, rc = -1; - if (__bfqio_cgroup_supported != 1) { + pthread_once(&__rtio_init_once, __initialize_rtio); + if (__rtio_cgroup_supported != 1) { return -1; } - if (prio < -17) { - if (rt_audio_cgroup_fd < 0) { - rt_audio_cgroup_fd = open("/sys/fs/cgroup/bfqio/rt-audio/tasks", O_WRONLY | O_CLOEXEC); - } - return rt_audio_cgroup_fd; - } else if (prio < -8) { - if (rt_display_cgroup_fd < 0) { - rt_display_cgroup_fd = open("/sys/fs/cgroup/bfqio/rt-display/tasks", O_WRONLY | O_CLOEXEC); - } - return rt_display_cgroup_fd; - } else if (prio >= 18) { - if (idle_cgroup_fd < 0) { - idle_cgroup_fd = open("/sys/fs/cgroup/bfqio/idle/tasks", O_WRONLY | O_CLOEXEC); - } - return idle_cgroup_fd; - } else if (prio >= 10) { - if (bg_cgroup_fd < 0) { - bg_cgroup_fd = open("/sys/fs/cgroup/bfqio/bg/tasks", O_WRONLY | O_CLOEXEC); - } - return bg_cgroup_fd; + if (rt) { + fd = open("/sys/fs/cgroup/bfqio/rt-display/tasks", O_WRONLY | O_CLOEXEC); + } else { + fd = open("/sys/fs/cgroup/bfqio/tasks", O_WRONLY | O_CLOEXEC); } -// if (fg_cgroup_fd < 0) { -// fg_cgroup_fd = open("/sys/fs/cgroup/bfqio/tasks", O_WRONLY | O_CLOEXEC); -// } - return -1; -} - -int android_set_bfqio_prio(int tid __android_unused, int prio __android_unused) -{ - struct stat st; - int fd; - - pthread_once(&the_once, __initialize_bfqio); - - if (__bfqio_cgroup_supported == 0) - return -1; - - if (prio < -19 || prio > 20) { + if (fd < 0) { return -1; } - fd = __get_bfqio_fd(prio); - if (fd < 0) - return -1; - #ifdef HAVE_GETTID if (tid == 0) { tid = gettid(); } #endif - if (tid < 200) - return -1; - // specialized itoa -- works for tid > 0 char text[22]; char *end = text + sizeof(text) - 1; @@ -150,23 +98,36 @@ int android_set_bfqio_prio(int tid __android_unused, int prio __android_unused) tid = tid / 10; } - if (write(fd, ptr, end - ptr) < 0) { + rc = write(fd, ptr, end - ptr); + if (rc < 0) { /* * If the thread is in the process of exiting, * don't flag an error */ - if (errno == ESRCH) - return 0; - SLOGV("android_set_bfqio_prio failed to write '%s' (%s); fd=%d\n", - ptr, strerror(errno), fd); - return -1; + if (errno == ESRCH) { + rc = 0; + } else { + SLOGV("android_set_rt_ioprio failed to write '%s' (%s); fd=%d\n", + ptr, strerror(errno), fd); + } } - return 0; + close(fd); + return rc; } #else -int android_set_bfqio_prio(int tid __android_unused, int prio __android_unused) +int android_set_ioprio(int pid __android_unused, IoSchedClass clazz __android_unused, int ioprio __android_unused) { + return 0; +} + +int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *ioprio) { + *clazz = IoSchedClass_NONE; + *ioprio = 0; + return 0; +} + +int android_set_rt_ioprio(int tid __android_unused, int rt __android_unused) { return 0; } diff --git a/libutils/Threads.cpp b/libutils/Threads.cpp index 59418d53..ab5f3c5f 100644 --- a/libutils/Threads.cpp +++ b/libutils/Threads.cpp @@ -45,7 +45,6 @@ #include #include -#include #include #ifdef HAVE_ANDROID_OS @@ -340,8 +339,6 @@ int androidSetThreadPriority(pid_t tid, int pri) } else { errno = lasterr; } - - android_set_bfqio_prio(tid, pri); #endif return rc; @@ -731,12 +728,6 @@ status_t Thread::run(const char* name, int32_t priority, size_t stack) return UNKNOWN_ERROR; } - -#ifdef HAVE_ANDROID_OS - pid_t tid = __pthread_gettid(android_thread_id_t_to_pthread(mThread)); - if (tid >= 200) - android_set_bfqio_prio(tid, priority); -#endif // Do not refer to mStatus here: The thread is already running (may, in fact // already have exited with a valid mStatus result). The NO_ERROR indication From 6215f54f7cac6f88b22fa33e2aec6a32e3945057 Mon Sep 17 00:00:00 2001 From: Nilesh Poddar Date: Fri, 3 Apr 2015 10:13:20 +0800 Subject: [PATCH 236/243] IPA tether: support for netlink event from ipa IPA will send ascii netlink broadcast and subsystem is net, not qlog, it's necessary to change the subsystem to qlog here Change-Id: Id11cd9597d3defa22bcd3f029abc32c673156d86 --- libsysutils/src/NetlinkEvent.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp index 72bf4239..e2ad3dd0 100644 --- a/libsysutils/src/NetlinkEvent.cpp +++ b/libsysutils/src/NetlinkEvent.cpp @@ -584,6 +584,10 @@ bool NetlinkEvent::parseAsciiNetlinkMessage(char *buffer, int size) { } s += strlen(s) + 1; } + if(findParam("ALERT_NAME") !=NULL ) { + mSubsystem = strdup("qlog"); + mAction = NlActionChange; + } return true; } From 5177000c4a74edce91cc777b4685a3ad8f4b73f6 Mon Sep 17 00:00:00 2001 From: sanketk Date: Fri, 12 Jun 2015 16:38:56 +0800 Subject: [PATCH 237/243] Don't use global variable in libnetutils. In netd, both CommandListener and NetlinkHandler thread will use libnetutils' function. Original implementation will use a global file descriptor in mutiple functions. It will cause problems when these functions are invoked from different thread. This change will make NetlinkHandler thread use local file descriptor instead of global one. CRs-fixed: 853158 Change-Id: I66458e99e48197e7a56cbb212344423290db12bd --- libnetutils/ifc_utils.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c index d9c50ab8..cb3722d8 100644 --- a/libnetutils/ifc_utils.c +++ b/libnetutils/ifc_utils.c @@ -598,23 +598,26 @@ int ifc_disable(const char *ifname) int ifc_reset_connections(const char *ifname, const int reset_mask) { #ifdef HAVE_ANDROID_OS - int result, success; + int result = 0, success; in_addr_t myaddr = 0; struct ifreq ifr; struct in6_ifreq ifr6; + int ctl_sock = -1; if (reset_mask & RESET_IPV4_ADDRESSES) { /* IPv4. Clear connections on the IP address. */ - ifc_init(); - if (!(reset_mask & RESET_IGNORE_INTERFACE_ADDRESS)) { - ifc_get_info(ifname, &myaddr, NULL, NULL); + ctl_sock = socket(AF_INET, SOCK_DGRAM, 0); + if (ctl_sock >= 0) { + if (!(reset_mask & RESET_IGNORE_INTERFACE_ADDRESS)) { + ifc_get_info(ifname, &myaddr, NULL, NULL); + } + ifc_init_ifr(ifname, &ifr); + init_sockaddr_in(&ifr.ifr_addr, myaddr); + result = ioctl(ctl_sock, SIOCKILLADDR, &ifr); + close(ctl_sock); + } else { + result = -1; } - ifc_init_ifr(ifname, &ifr); - init_sockaddr_in(&ifr.ifr_addr, myaddr); - result = ioctl(ifc_ctl_sock, SIOCKILLADDR, &ifr); - ifc_close(); - } else { - result = 0; } if (reset_mask & RESET_IPV6_ADDRESSES) { @@ -624,14 +627,18 @@ int ifc_reset_connections(const char *ifname, const int reset_mask) * So we clear all unused IPv6 connections on the device by specifying an * empty IPv6 address. */ - ifc_init6(); + ctl_sock = socket(AF_INET6, SOCK_DGRAM, 0); // This implicitly specifies an address of ::, i.e., kill all IPv6 sockets. memset(&ifr6, 0, sizeof(ifr6)); - success = ioctl(ifc_ctl_sock6, SIOCKILLADDR, &ifr6); - if (result == 0) { - result = success; + if (ctl_sock >= 0) { + success = ioctl(ctl_sock, SIOCKILLADDR, &ifr6); + if (result == 0) { + result = success; + } + close(ctl_sock); + } else { + result = -1; } - ifc_close6(); } return result; From 2c2540e0106226a42ab62a8e175caaf1b991b435 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Thu, 24 Sep 2015 23:47:11 -0700 Subject: [PATCH 238/243] sysutils: Hush logging Change-Id: Ia3eb170ca1c8e698e72d931806f80d79d48a5ec1 --- libsysutils/src/NetlinkEvent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp index e2ad3dd0..bd381ee4 100644 --- a/libsysutils/src/NetlinkEvent.cpp +++ b/libsysutils/src/NetlinkEvent.cpp @@ -610,6 +610,6 @@ const char *NetlinkEvent::findParam(const char *paramName) { return ++ptr; } - SLOGE("NetlinkEvent::FindParam(): Parameter '%s' not found", paramName); + SLOGV("NetlinkEvent::FindParam(): Parameter '%s' not found", paramName); return NULL; } From ae52f2731f255c643d2e202978cdf18677d99d8a Mon Sep 17 00:00:00 2001 From: Scott Mertz Date: Mon, 28 Sep 2015 10:41:28 -0700 Subject: [PATCH 239/243] init.rc: drop world writable on cgroups to pass cts Change-Id: I14f391d86055cd5f5158f17354132a35055b6ca3 --- rootdir/init.rc | 1 + 1 file changed, 1 insertion(+) diff --git a/rootdir/init.rc b/rootdir/init.rc index 029d7deb..a7dc8ae6 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -62,6 +62,7 @@ on init write /sys/fs/cgroup/memory/sw/memory.move_charge_at_immigrate 1 chown root system /sys/fs/cgroup/memory/sw/tasks chmod 0660 /sys/fs/cgroup/memory/sw/tasks + chmod 0220 /sys/fs/cgroup/memory/cgroup.event_control mkdir /system mkdir /data 0771 system system From 78041c00c4717e5d7fbb8d84b2b9e744fddade59 Mon Sep 17 00:00:00 2001 From: Keith Mok Date: Fri, 25 Sep 2015 16:59:10 -0700 Subject: [PATCH 240/243] fs_mgr: When formating f2fs volumes, respect the length parameter When formatting a volume because it is marked as formattable, the length parameter is discarded which makes fs_mgr write a filesystem to the full length of the block device. This patch adds length semantics to f2fs formatting, if the length is greater than zero, use that, if it isn't subtract that size from the block size. Change-Id: I526f80aa299e7b34e9802141e7fa7050d5cb5558 Ticket: SAMBAR-729 --- fs_mgr/fs_mgr_format.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/fs_mgr/fs_mgr_format.c b/fs_mgr/fs_mgr_format.c index 2e8f2aee..2a3d0a72 100644 --- a/fs_mgr/fs_mgr_format.c +++ b/fs_mgr/fs_mgr_format.c @@ -67,15 +67,27 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, long long fs_length) return rc; } -static int format_f2fs(char *fs_blkdev) +static int format_f2fs(char *fs_blkdev, long long fs_length) { - char * args[3]; + char * args[5]; int pid; int rc = 0; + char buff[65]; args[0] = (char *)"/sbin/mkfs.f2fs"; - args[1] = fs_blkdev; - args[2] = (char *)0; + + if (fs_length >= 0) { + snprintf(buff, sizeof(buff), "%lld", fs_length / 512); + args[1] = fs_blkdev; + args[2] = buff; + args[3] = (char *)0; + } else if (fs_length < 0) { + snprintf(buff, sizeof(buff), "%lld", -fs_length); + args[1] = "-r"; + args[2] = buff; + args[3] = fs_blkdev; + args[4] = (char *)0; + } pid = fork(); if (pid < 0) { @@ -114,7 +126,7 @@ int fs_mgr_do_format(struct fstab_rec *fstab) ERROR("%s: Format %s as '%s'.\n", __func__, fstab->blk_device, fstab->fs_type); if (!strncmp(fstab->fs_type, "f2fs", 4)) { - rc = format_f2fs(fstab->blk_device); + rc = format_f2fs(fstab->blk_device, fstab->length); } else if (!strncmp(fstab->fs_type, "ext4", 4)) { rc = format_ext4(fstab->blk_device, fstab->mount_point, fstab->length); } else { From 8b7372b2a9a279f7e291dd52374f5876b078180a Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Fri, 6 Feb 2015 13:22:01 -0800 Subject: [PATCH 241/243] Move map data into backtrace data proper. The backtrace structure used to include a pointer to a backtrace_map_t that represented the map data for a particular pc. This introduced a race condition where the pointer could be discarded, but the backtrace structure still contained a pointer to garbage memory. Now all of the map information is right in the structure. Bug: 19028453 Change-Id: I6021d1e6d265f246cafa6153e877fda52d04cc74 Signed-off-by: Chet Kener Signed-off-by: W4TCH0UT --- debuggerd/tombstone.cpp | 7 ++++--- include/backtrace/Backtrace.h | 6 +++--- include/backtrace/BacktraceMap.h | 17 +++++++++++----- libbacktrace/BacktraceImpl.cpp | 17 ++++++++-------- libbacktrace/BacktraceImpl.h | 4 ++-- libbacktrace/BacktraceMap.cpp | 7 ++++--- libbacktrace/UnwindCurrent.cpp | 3 +-- libbacktrace/UnwindMap.cpp | 9 ++++----- libbacktrace/UnwindMap.h | 2 +- libbacktrace/UnwindPtrace.cpp | 2 +- libbacktrace/backtrace_test.cpp | 34 ++++++++++++++++++++++---------- 11 files changed, 65 insertions(+), 43 deletions(-) diff --git a/debuggerd/tombstone.cpp b/debuggerd/tombstone.cpp index 4234fae3..e8d71538 100644 --- a/debuggerd/tombstone.cpp +++ b/debuggerd/tombstone.cpp @@ -239,12 +239,13 @@ static void dump_stack_segment( break; } - const backtrace_map_t* map = backtrace->FindMap(stack_content); + backtrace_map_t map; + backtrace->FillInMap(stack_content, &map); const char* map_name; - if (!map) { + if (BacktraceMap::IsValid(map)) { map_name = ""; } else { - map_name = map->name.c_str(); + map_name = map.name.c_str(); } uintptr_t offset = 0; std::string func_name(backtrace->GetFunctionName(stack_content, &offset)); diff --git a/include/backtrace/Backtrace.h b/include/backtrace/Backtrace.h index e07d322f..e2d718bf 100644 --- a/include/backtrace/Backtrace.h +++ b/include/backtrace/Backtrace.h @@ -39,7 +39,7 @@ struct backtrace_frame_data_t { uintptr_t pc; // The absolute pc. uintptr_t sp; // The top of the stack. size_t stack_size; // The size of the stack, zero indicate an unknown stack size. - const backtrace_map_t* map; // The map associated with the given pc. + backtrace_map_t map; // The map associated with the given pc. std::string func_name; // The function name associated with this pc, NULL if not found. uintptr_t func_offset; // pc relative to the start of the function, only valid if func_name is not NULL. }; @@ -78,8 +78,8 @@ class Backtrace { // If the string is empty, then no valid function name was found. virtual std::string GetFunctionName(uintptr_t pc, uintptr_t* offset); - // Find the map associated with the given pc. - virtual const backtrace_map_t* FindMap(uintptr_t pc); + // Fill in the map data associated with the given pc. + virtual void FillInMap(uintptr_t pc, backtrace_map_t* map); // Read the data at a specific address. virtual bool ReadWord(uintptr_t ptr, word_t* out_value) = 0; diff --git a/include/backtrace/BacktraceMap.h b/include/backtrace/BacktraceMap.h index 4ed23a88..da963071 100644 --- a/include/backtrace/BacktraceMap.h +++ b/include/backtrace/BacktraceMap.h @@ -33,6 +33,8 @@ #include struct backtrace_map_t { + backtrace_map_t(): start(0), end(0), flags(0) {} + uintptr_t start; uintptr_t end; int flags; @@ -48,15 +50,16 @@ class BacktraceMap { virtual ~BacktraceMap(); - // Get the map data structure for the given address. - virtual const backtrace_map_t* Find(uintptr_t addr); + // Fill in the map data structure for the given address. + virtual void FillIn(uintptr_t addr, backtrace_map_t* map); // The flags returned are the same flags as used by the mmap call. // The values are PROT_*. int GetFlags(uintptr_t pc) { - const backtrace_map_t* map = Find(pc); - if (map) { - return map->flags; + backtrace_map_t map; + FillIn(pc, &map); + if (IsValid(map)) { + return map.flags; } return PROT_NONE; } @@ -75,6 +78,10 @@ class BacktraceMap { virtual bool Build(); + static inline bool IsValid(const backtrace_map_t& map) { + return map.end > 0; + } + protected: BacktraceMap(pid_t pid); diff --git a/libbacktrace/BacktraceImpl.cpp b/libbacktrace/BacktraceImpl.cpp index 405b042a..fb8a725a 100644 --- a/libbacktrace/BacktraceImpl.cpp +++ b/libbacktrace/BacktraceImpl.cpp @@ -99,15 +99,15 @@ std::string Backtrace::FormatFrameData(size_t frame_num) { std::string Backtrace::FormatFrameData(const backtrace_frame_data_t* frame) { const char* map_name; - if (frame->map && !frame->map->name.empty()) { - map_name = frame->map->name.c_str(); + if (BacktraceMap::IsValid(frame->map) && !frame->map.name.empty()) { + map_name = frame->map.name.c_str(); } else { map_name = ""; } uintptr_t relative_pc; - if (frame->map) { - relative_pc = frame->pc - frame->map->start; + if (BacktraceMap::IsValid(frame->map)) { + relative_pc = frame->pc - frame->map.start; } else { relative_pc = frame->pc; } @@ -128,8 +128,8 @@ std::string Backtrace::FormatFrameData(const backtrace_frame_data_t* frame) { return buf; } -const backtrace_map_t* Backtrace::FindMap(uintptr_t pc) { - return map_->Find(pc); +void Backtrace::FillInMap(uintptr_t pc, backtrace_map_t* map) { + map_->FillIn(pc, map); } //------------------------------------------------------------------------- @@ -147,8 +147,9 @@ bool BacktraceCurrent::ReadWord(uintptr_t ptr, word_t* out_value) { return false; } - const backtrace_map_t* map = FindMap(ptr); - if (map && map->flags & PROT_READ) { + backtrace_map_t map; + FillInMap(ptr, &map); + if (BacktraceMap::IsValid(map) && map.flags & PROT_READ) { *out_value = *reinterpret_cast(ptr); return true; } else { diff --git a/libbacktrace/BacktraceImpl.h b/libbacktrace/BacktraceImpl.h index d34ad055..cd61bdff 100755 --- a/libbacktrace/BacktraceImpl.h +++ b/libbacktrace/BacktraceImpl.h @@ -37,8 +37,8 @@ class BacktraceImpl { inline pid_t Pid() { return backtrace_obj_->Pid(); } inline pid_t Tid() { return backtrace_obj_->Tid(); } - inline const backtrace_map_t* FindMap(uintptr_t addr) { - return backtrace_obj_->FindMap(addr); + inline void FillInMap(uintptr_t addr, backtrace_map_t* map) { + backtrace_obj_->FillInMap(addr, map); } inline std::string GetFunctionName(uintptr_t pc, uintptr_t* offset) { return backtrace_obj_->GetFunctionName(pc, offset); diff --git a/libbacktrace/BacktraceMap.cpp b/libbacktrace/BacktraceMap.cpp index f38e4841..82a4085e 100644 --- a/libbacktrace/BacktraceMap.cpp +++ b/libbacktrace/BacktraceMap.cpp @@ -37,14 +37,15 @@ BacktraceMap::BacktraceMap(pid_t pid) : pid_(pid) { BacktraceMap::~BacktraceMap() { } -const backtrace_map_t* BacktraceMap::Find(uintptr_t addr) { +void BacktraceMap::FillIn(uintptr_t addr, backtrace_map_t* map) { for (BacktraceMap::const_iterator it = begin(); it != end(); ++it) { if (addr >= it->start && addr < it->end) { - return &*it; + *map = *it; + return; } } - return NULL; + *map = {}; } bool BacktraceMap::ParseLine(const char* line, backtrace_map_t* map) { diff --git a/libbacktrace/UnwindCurrent.cpp b/libbacktrace/UnwindCurrent.cpp index b176aaf0..372555b3 100755 --- a/libbacktrace/UnwindCurrent.cpp +++ b/libbacktrace/UnwindCurrent.cpp @@ -137,9 +137,8 @@ bool UnwindCurrent::UnwindFromContext(size_t num_ignore_frames, bool within_hand if (!within_handler) { frame->func_name = GetFunctionName(frame->pc, &frame->func_offset); - frame->map = FindMap(frame->pc); + FillInMap(frame->pc, &frame->map); } else { - frame->map = NULL; frame->func_offset = 0; } num_frames++; diff --git a/libbacktrace/UnwindMap.cpp b/libbacktrace/UnwindMap.cpp index 387d768a..284a5615 100644 --- a/libbacktrace/UnwindMap.cpp +++ b/libbacktrace/UnwindMap.cpp @@ -113,18 +113,17 @@ bool UnwindMapLocal::Build() { return (map_created_ = (unw_map_local_create() == 0)) && GenerateMap();; } -const backtrace_map_t* UnwindMapLocal::Find(uintptr_t addr) { - const backtrace_map_t* map = BacktraceMap::Find(addr); - if (!map) { +void UnwindMapLocal::FillIn(uintptr_t addr, backtrace_map_t* map) { + BacktraceMap::FillIn(addr, map); + if (!IsValid(*map)) { // Check to see if the underlying map changed and regenerate the map // if it did. if (unw_map_local_cursor_valid(&map_cursor_) < 0) { if (GenerateMap()) { - map = BacktraceMap::Find(addr); + BacktraceMap::FillIn(addr, map); } } } - return map; } //------------------------------------------------------------------------- diff --git a/libbacktrace/UnwindMap.h b/libbacktrace/UnwindMap.h index 2fdb29f8..be8855e8 100644 --- a/libbacktrace/UnwindMap.h +++ b/libbacktrace/UnwindMap.h @@ -45,7 +45,7 @@ class UnwindMapLocal : public UnwindMap { virtual bool Build(); - virtual const backtrace_map_t* Find(uintptr_t addr); + virtual void FillIn(uintptr_t addr, backtrace_map_t* map); protected: virtual bool GenerateMap(); diff --git a/libbacktrace/UnwindPtrace.cpp b/libbacktrace/UnwindPtrace.cpp index 7ba8775b..efe758b4 100644 --- a/libbacktrace/UnwindPtrace.cpp +++ b/libbacktrace/UnwindPtrace.cpp @@ -106,7 +106,7 @@ bool UnwindPtrace::Unwind(size_t num_ignore_frames, ucontext_t* ucontext) { frame->func_name = GetFunctionName(frame->pc, &frame->func_offset); - frame->map = FindMap(frame->pc); + FillInMap(frame->pc, &frame->map); num_frames++; } else { diff --git a/libbacktrace/backtrace_test.cpp b/libbacktrace/backtrace_test.cpp index 8002ed6b..76aabd13 100644 --- a/libbacktrace/backtrace_test.cpp +++ b/libbacktrace/backtrace_test.cpp @@ -688,6 +688,25 @@ TEST(libbacktrace, simultaneous_maps) { delete map3; } +TEST(libbacktrace, fillin_erases) { + BacktraceMap* back_map = BacktraceMap::Create(getpid()); + + backtrace_map_t map; + + map.start = 1; + map.end = 3; + map.flags = 1; + map.name = "Initialized"; + back_map->FillIn(0, &map); + delete back_map; + + ASSERT_FALSE(BacktraceMap::IsValid(map)); + ASSERT_EQ(static_cast(0), map.start); + ASSERT_EQ(static_cast(0), map.end); + ASSERT_EQ(0, map.flags); + ASSERT_EQ("", map.name); +} + TEST(libbacktrace, format_test) { UniquePtr backtrace(Backtrace::Create(getpid(), BACKTRACE_CURRENT_THREAD)); ASSERT_TRUE(backtrace.get() != NULL); @@ -697,13 +716,8 @@ TEST(libbacktrace, format_test) { frame.pc = 2; frame.sp = 0; frame.stack_size = 0; - frame.map = NULL; frame.func_offset = 0; - backtrace_map_t map; - map.start = 0; - map.end = 0; - // Check no map set. frame.num = 1; #if defined(__LP64__) @@ -714,8 +728,8 @@ TEST(libbacktrace, format_test) { backtrace->FormatFrameData(&frame)); // Check map name empty, but exists. - frame.map = ↦ - map.start = 1; + frame.map.start = 1; + frame.map.end = 1; #if defined(__LP64__) EXPECT_EQ("#01 pc 0000000000000001 ", #else @@ -726,9 +740,9 @@ TEST(libbacktrace, format_test) { // Check relative pc is set and map name is set. frame.pc = 0x12345679; - frame.map = ↦ - map.name = "MapFake"; - map.start = 1; + frame.map.name = "MapFake"; + frame.map.start = 1; + frame.map.end = 1; #if defined(__LP64__) EXPECT_EQ("#01 pc 0000000012345678 MapFake", #else From e29a8e5a2c70f37f51a6fae25e66e45d211e19d6 Mon Sep 17 00:00:00 2001 From: Misael Lopez Cruz Date: Wed, 29 Apr 2015 12:02:08 -0500 Subject: [PATCH 242/243] audio: Fix false positives in audio_is_remote_submix_device() The audio_is_remote_submix_device() helper function incorrectly reported AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES and AUDIO_DEVICE_IN_LINE as a submix devices. The cases where the confusion occurs are for devices whose bitwise value only differs in the direction bit. Change-Id: I930e8d4fbe5378244b4a0fdb00f4a47726d05383 Signed-off-by: W4TCH0UT --- include/system/audio.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/system/audio.h b/include/system/audio.h index 093da96e..50ca957c 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -1220,8 +1220,10 @@ static inline bool audio_is_usb_device(audio_devices_t device) static inline bool audio_is_remote_submix_device(audio_devices_t device) { - if ((device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) == AUDIO_DEVICE_OUT_REMOTE_SUBMIX - || (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) == AUDIO_DEVICE_IN_REMOTE_SUBMIX) + if ((audio_is_output_devices(device) && + (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) == AUDIO_DEVICE_OUT_REMOTE_SUBMIX) + || (!audio_is_output_devices(device) && + (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) == AUDIO_DEVICE_IN_REMOTE_SUBMIX)) return true; else return false; From 41d60bcf858bd2223cbc50ce4739471910346a77 Mon Sep 17 00:00:00 2001 From: W4TCH0UT Date: Wed, 30 Sep 2015 10:19:49 +0530 Subject: [PATCH 243/243] Revert "Move map data into backtrace data proper." This reverts commit 8b7372b2a9a279f7e291dd52374f5876b078180a. Signed-off-by: W4TCH0UT --- debuggerd/tombstone.cpp | 7 +++---- include/backtrace/Backtrace.h | 6 +++--- include/backtrace/BacktraceMap.h | 17 +++++----------- libbacktrace/BacktraceImpl.cpp | 17 ++++++++-------- libbacktrace/BacktraceImpl.h | 4 ++-- libbacktrace/BacktraceMap.cpp | 7 +++---- libbacktrace/UnwindCurrent.cpp | 3 ++- libbacktrace/UnwindMap.cpp | 9 +++++---- libbacktrace/UnwindMap.h | 2 +- libbacktrace/UnwindPtrace.cpp | 2 +- libbacktrace/backtrace_test.cpp | 34 ++++++++++---------------------- 11 files changed, 43 insertions(+), 65 deletions(-) diff --git a/debuggerd/tombstone.cpp b/debuggerd/tombstone.cpp index e8d71538..4234fae3 100644 --- a/debuggerd/tombstone.cpp +++ b/debuggerd/tombstone.cpp @@ -239,13 +239,12 @@ static void dump_stack_segment( break; } - backtrace_map_t map; - backtrace->FillInMap(stack_content, &map); + const backtrace_map_t* map = backtrace->FindMap(stack_content); const char* map_name; - if (BacktraceMap::IsValid(map)) { + if (!map) { map_name = ""; } else { - map_name = map.name.c_str(); + map_name = map->name.c_str(); } uintptr_t offset = 0; std::string func_name(backtrace->GetFunctionName(stack_content, &offset)); diff --git a/include/backtrace/Backtrace.h b/include/backtrace/Backtrace.h index e2d718bf..e07d322f 100644 --- a/include/backtrace/Backtrace.h +++ b/include/backtrace/Backtrace.h @@ -39,7 +39,7 @@ struct backtrace_frame_data_t { uintptr_t pc; // The absolute pc. uintptr_t sp; // The top of the stack. size_t stack_size; // The size of the stack, zero indicate an unknown stack size. - backtrace_map_t map; // The map associated with the given pc. + const backtrace_map_t* map; // The map associated with the given pc. std::string func_name; // The function name associated with this pc, NULL if not found. uintptr_t func_offset; // pc relative to the start of the function, only valid if func_name is not NULL. }; @@ -78,8 +78,8 @@ class Backtrace { // If the string is empty, then no valid function name was found. virtual std::string GetFunctionName(uintptr_t pc, uintptr_t* offset); - // Fill in the map data associated with the given pc. - virtual void FillInMap(uintptr_t pc, backtrace_map_t* map); + // Find the map associated with the given pc. + virtual const backtrace_map_t* FindMap(uintptr_t pc); // Read the data at a specific address. virtual bool ReadWord(uintptr_t ptr, word_t* out_value) = 0; diff --git a/include/backtrace/BacktraceMap.h b/include/backtrace/BacktraceMap.h index da963071..4ed23a88 100644 --- a/include/backtrace/BacktraceMap.h +++ b/include/backtrace/BacktraceMap.h @@ -33,8 +33,6 @@ #include struct backtrace_map_t { - backtrace_map_t(): start(0), end(0), flags(0) {} - uintptr_t start; uintptr_t end; int flags; @@ -50,16 +48,15 @@ class BacktraceMap { virtual ~BacktraceMap(); - // Fill in the map data structure for the given address. - virtual void FillIn(uintptr_t addr, backtrace_map_t* map); + // Get the map data structure for the given address. + virtual const backtrace_map_t* Find(uintptr_t addr); // The flags returned are the same flags as used by the mmap call. // The values are PROT_*. int GetFlags(uintptr_t pc) { - backtrace_map_t map; - FillIn(pc, &map); - if (IsValid(map)) { - return map.flags; + const backtrace_map_t* map = Find(pc); + if (map) { + return map->flags; } return PROT_NONE; } @@ -78,10 +75,6 @@ class BacktraceMap { virtual bool Build(); - static inline bool IsValid(const backtrace_map_t& map) { - return map.end > 0; - } - protected: BacktraceMap(pid_t pid); diff --git a/libbacktrace/BacktraceImpl.cpp b/libbacktrace/BacktraceImpl.cpp index fb8a725a..405b042a 100644 --- a/libbacktrace/BacktraceImpl.cpp +++ b/libbacktrace/BacktraceImpl.cpp @@ -99,15 +99,15 @@ std::string Backtrace::FormatFrameData(size_t frame_num) { std::string Backtrace::FormatFrameData(const backtrace_frame_data_t* frame) { const char* map_name; - if (BacktraceMap::IsValid(frame->map) && !frame->map.name.empty()) { - map_name = frame->map.name.c_str(); + if (frame->map && !frame->map->name.empty()) { + map_name = frame->map->name.c_str(); } else { map_name = ""; } uintptr_t relative_pc; - if (BacktraceMap::IsValid(frame->map)) { - relative_pc = frame->pc - frame->map.start; + if (frame->map) { + relative_pc = frame->pc - frame->map->start; } else { relative_pc = frame->pc; } @@ -128,8 +128,8 @@ std::string Backtrace::FormatFrameData(const backtrace_frame_data_t* frame) { return buf; } -void Backtrace::FillInMap(uintptr_t pc, backtrace_map_t* map) { - map_->FillIn(pc, map); +const backtrace_map_t* Backtrace::FindMap(uintptr_t pc) { + return map_->Find(pc); } //------------------------------------------------------------------------- @@ -147,9 +147,8 @@ bool BacktraceCurrent::ReadWord(uintptr_t ptr, word_t* out_value) { return false; } - backtrace_map_t map; - FillInMap(ptr, &map); - if (BacktraceMap::IsValid(map) && map.flags & PROT_READ) { + const backtrace_map_t* map = FindMap(ptr); + if (map && map->flags & PROT_READ) { *out_value = *reinterpret_cast(ptr); return true; } else { diff --git a/libbacktrace/BacktraceImpl.h b/libbacktrace/BacktraceImpl.h index cd61bdff..d34ad055 100755 --- a/libbacktrace/BacktraceImpl.h +++ b/libbacktrace/BacktraceImpl.h @@ -37,8 +37,8 @@ class BacktraceImpl { inline pid_t Pid() { return backtrace_obj_->Pid(); } inline pid_t Tid() { return backtrace_obj_->Tid(); } - inline void FillInMap(uintptr_t addr, backtrace_map_t* map) { - backtrace_obj_->FillInMap(addr, map); + inline const backtrace_map_t* FindMap(uintptr_t addr) { + return backtrace_obj_->FindMap(addr); } inline std::string GetFunctionName(uintptr_t pc, uintptr_t* offset) { return backtrace_obj_->GetFunctionName(pc, offset); diff --git a/libbacktrace/BacktraceMap.cpp b/libbacktrace/BacktraceMap.cpp index 82a4085e..f38e4841 100644 --- a/libbacktrace/BacktraceMap.cpp +++ b/libbacktrace/BacktraceMap.cpp @@ -37,15 +37,14 @@ BacktraceMap::BacktraceMap(pid_t pid) : pid_(pid) { BacktraceMap::~BacktraceMap() { } -void BacktraceMap::FillIn(uintptr_t addr, backtrace_map_t* map) { +const backtrace_map_t* BacktraceMap::Find(uintptr_t addr) { for (BacktraceMap::const_iterator it = begin(); it != end(); ++it) { if (addr >= it->start && addr < it->end) { - *map = *it; - return; + return &*it; } } - *map = {}; + return NULL; } bool BacktraceMap::ParseLine(const char* line, backtrace_map_t* map) { diff --git a/libbacktrace/UnwindCurrent.cpp b/libbacktrace/UnwindCurrent.cpp index 372555b3..b176aaf0 100755 --- a/libbacktrace/UnwindCurrent.cpp +++ b/libbacktrace/UnwindCurrent.cpp @@ -137,8 +137,9 @@ bool UnwindCurrent::UnwindFromContext(size_t num_ignore_frames, bool within_hand if (!within_handler) { frame->func_name = GetFunctionName(frame->pc, &frame->func_offset); - FillInMap(frame->pc, &frame->map); + frame->map = FindMap(frame->pc); } else { + frame->map = NULL; frame->func_offset = 0; } num_frames++; diff --git a/libbacktrace/UnwindMap.cpp b/libbacktrace/UnwindMap.cpp index 284a5615..387d768a 100644 --- a/libbacktrace/UnwindMap.cpp +++ b/libbacktrace/UnwindMap.cpp @@ -113,17 +113,18 @@ bool UnwindMapLocal::Build() { return (map_created_ = (unw_map_local_create() == 0)) && GenerateMap();; } -void UnwindMapLocal::FillIn(uintptr_t addr, backtrace_map_t* map) { - BacktraceMap::FillIn(addr, map); - if (!IsValid(*map)) { +const backtrace_map_t* UnwindMapLocal::Find(uintptr_t addr) { + const backtrace_map_t* map = BacktraceMap::Find(addr); + if (!map) { // Check to see if the underlying map changed and regenerate the map // if it did. if (unw_map_local_cursor_valid(&map_cursor_) < 0) { if (GenerateMap()) { - BacktraceMap::FillIn(addr, map); + map = BacktraceMap::Find(addr); } } } + return map; } //------------------------------------------------------------------------- diff --git a/libbacktrace/UnwindMap.h b/libbacktrace/UnwindMap.h index be8855e8..2fdb29f8 100644 --- a/libbacktrace/UnwindMap.h +++ b/libbacktrace/UnwindMap.h @@ -45,7 +45,7 @@ class UnwindMapLocal : public UnwindMap { virtual bool Build(); - virtual void FillIn(uintptr_t addr, backtrace_map_t* map); + virtual const backtrace_map_t* Find(uintptr_t addr); protected: virtual bool GenerateMap(); diff --git a/libbacktrace/UnwindPtrace.cpp b/libbacktrace/UnwindPtrace.cpp index efe758b4..7ba8775b 100644 --- a/libbacktrace/UnwindPtrace.cpp +++ b/libbacktrace/UnwindPtrace.cpp @@ -106,7 +106,7 @@ bool UnwindPtrace::Unwind(size_t num_ignore_frames, ucontext_t* ucontext) { frame->func_name = GetFunctionName(frame->pc, &frame->func_offset); - FillInMap(frame->pc, &frame->map); + frame->map = FindMap(frame->pc); num_frames++; } else { diff --git a/libbacktrace/backtrace_test.cpp b/libbacktrace/backtrace_test.cpp index 76aabd13..8002ed6b 100644 --- a/libbacktrace/backtrace_test.cpp +++ b/libbacktrace/backtrace_test.cpp @@ -688,25 +688,6 @@ TEST(libbacktrace, simultaneous_maps) { delete map3; } -TEST(libbacktrace, fillin_erases) { - BacktraceMap* back_map = BacktraceMap::Create(getpid()); - - backtrace_map_t map; - - map.start = 1; - map.end = 3; - map.flags = 1; - map.name = "Initialized"; - back_map->FillIn(0, &map); - delete back_map; - - ASSERT_FALSE(BacktraceMap::IsValid(map)); - ASSERT_EQ(static_cast(0), map.start); - ASSERT_EQ(static_cast(0), map.end); - ASSERT_EQ(0, map.flags); - ASSERT_EQ("", map.name); -} - TEST(libbacktrace, format_test) { UniquePtr backtrace(Backtrace::Create(getpid(), BACKTRACE_CURRENT_THREAD)); ASSERT_TRUE(backtrace.get() != NULL); @@ -716,8 +697,13 @@ TEST(libbacktrace, format_test) { frame.pc = 2; frame.sp = 0; frame.stack_size = 0; + frame.map = NULL; frame.func_offset = 0; + backtrace_map_t map; + map.start = 0; + map.end = 0; + // Check no map set. frame.num = 1; #if defined(__LP64__) @@ -728,8 +714,8 @@ TEST(libbacktrace, format_test) { backtrace->FormatFrameData(&frame)); // Check map name empty, but exists. - frame.map.start = 1; - frame.map.end = 1; + frame.map = ↦ + map.start = 1; #if defined(__LP64__) EXPECT_EQ("#01 pc 0000000000000001 ", #else @@ -740,9 +726,9 @@ TEST(libbacktrace, format_test) { // Check relative pc is set and map name is set. frame.pc = 0x12345679; - frame.map.name = "MapFake"; - frame.map.start = 1; - frame.map.end = 1; + frame.map = ↦ + map.name = "MapFake"; + map.start = 1; #if defined(__LP64__) EXPECT_EQ("#01 pc 0000000012345678 MapFake", #else