Merge "Add log group to rild to improve log collection on modem issue"
diff --git a/adb/commandline.c b/adb/commandline.c
index 973932f..4c15232 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -129,18 +129,22 @@
         "  adb bugreport                - return all information from the device\n"
         "                                 that should be included in a bug report.\n"
         "\n"
-        "  adb backup [-f <file>] [-apk|-noapk] [-shared|-noshared] [-all] [<packages...>]\n"
-        "                               - Write an archive of the device's data to <file>.\n"
-        "                                 If a -f option is not supplied then the data is\n"
-        "                                 written to \"backup.ab\" in the current directory.\n"
+        "  adb backup [-f <file>] [-apk|-noapk] [-shared|-noshared] [-all] [-system|-nosystem] [<packages...>]\n"
+        "                               - write an archive of the device's data to <file>.\n"
+        "                                 If no -f option is supplied then the data is written\n"
+        "                                 to \"backup.ab\" in the current directory.\n"
         "                                 (-apk|-noapk enable/disable backup of the .apks themselves\n"
         "                                    in the archive; the default is noapk.)\n"
         "                                 (-shared|-noshared enable/disable backup of the device's\n"
         "                                    shared storage / SD card contents; the default is noshared.)\n"
         "                                 (-all means to back up all installed applications)\n"
+        "                                 (-system|-nosystem toggles whether -all automatically includes\n"
+        "                                    system applications; the default is to include system apps)\n"
         "                                 (<packages...> is the list of applications to be backed up.  If\n"
         "                                    the -all or -shared flags are passed, then the package\n"
-        "                                    list is optional.)\n"
+        "                                    list is optional.  Applications explicitly given on the\n"
+        "                                    command line will be included even if -nosystem would\n"
+        "                                    ordinarily cause them to be omitted.)\n"
         "\n"
         "  adb restore <file>           - restore device contents from the <file> backup archive\n"
         "\n"
diff --git a/charger/charger.c b/charger/charger.c
index 0ade250..d3b414d 100644
--- a/charger/charger.c
+++ b/charger/charger.c
@@ -37,6 +37,7 @@
 #include <cutils/android_reboot.h>
 #include <cutils/klog.h>
 #include <cutils/list.h>
+#include <cutils/misc.h>
 #include <cutils/uevent.h>
 
 #include "minui/minui.h"
@@ -60,6 +61,9 @@
 
 #define BATTERY_FULL_THRESH     95
 
+#define LAST_KMSG_PATH          "/proc/last_kmsg"
+#define LAST_KMSG_MAX_SZ        (32 * 1024)
+
 #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)
@@ -188,6 +192,53 @@
     gr_fill(0, 0, gr_fb_width(), gr_fb_height());
 };
 
+#define MAX_KLOG_WRITE_BUF_SZ 256
+
+static void dump_last_kmsg(void)
+{
+    char *buf;
+    char *ptr;
+    unsigned sz = 0;
+    int len;
+
+    LOGI("\n");
+    LOGI("*************** LAST KMSG ***************\n");
+    LOGI("\n");
+    buf = load_file(LAST_KMSG_PATH, &sz);
+    if (!buf || !sz) {
+        LOGI("last_kmsg not found. Cold reset?\n");
+        goto out;
+    }
+
+    len = min(sz, LAST_KMSG_MAX_SZ);
+    ptr = buf + (sz - len);
+
+    while (len > 0) {
+        int cnt = min(len, MAX_KLOG_WRITE_BUF_SZ);
+        char yoink;
+        char *nl;
+
+        nl = memrchr(ptr, '\n', cnt - 1);
+        if (nl)
+            cnt = nl - ptr + 1;
+
+        yoink = ptr[cnt];
+        ptr[cnt] = '\0';
+        KLOG_INFO("", "%s", ptr);
+        ptr[cnt] = yoink;
+
+        len -= cnt;
+        ptr += cnt;
+    }
+
+    free(buf);
+
+out:
+    LOGI("\n");
+    LOGI("************* END LAST KMSG *************\n");
+    LOGI("\n");
+}
+
 static int read_file(const char *path, char *buf, size_t sz)
 {
     int fd;
@@ -770,7 +821,6 @@
     if (charger->num_supplies_online == 0) {
         if (charger->next_pwr_check == -1) {
             charger->next_pwr_check = now + UNPLUGGED_SHUTDOWN_TIME;
-            kick_animation(charger->batt_anim);
             LOGI("[%lld] device unplugged: shutting down in %lld (@ %lld)\n",
                  now, UNPLUGGED_SHUTDOWN_TIME, charger->next_pwr_check);
         } else if (now >= charger->next_pwr_check) {
@@ -863,6 +913,10 @@
     klog_init();
     klog_set_level(CHARGER_KLOG_LEVEL);
 
+    dump_last_kmsg();
+
+    LOGI("--------------- STARTING CHARGER MODE ---------------\n");
+
     gr_init();
     gr_font_size(&char_width, &char_height);
 
diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
index 048864c..2cc673f 100644
--- a/include/private/android_filesystem_config.h
+++ b/include/private/android_filesystem_config.h
@@ -59,6 +59,7 @@
 #define AID_MEDIA_RW      1023  /* internal media storage write access */
 #define AID_MTP           1024  /* MTP USB driver access */
 #define AID_NFC           1025  /* nfc subsystem */
+#define AID_DRMRPC        1026  /* group for drm rpc */
 
 #define AID_SHELL         2000  /* adb and debug shell user */
 #define AID_CACHE         2001  /* cache access */
@@ -105,6 +106,7 @@
     { "drm",       AID_DRM, },
     { "available", AID_AVAILABLE, },
     { "nfc",       AID_NFC, },
+    { "drmrpc",    AID_DRMRPC, },
     { "shell",     AID_SHELL, },
     { "cache",     AID_CACHE, },
     { "diag",      AID_DIAG, },
diff --git a/include/system/camera.h b/include/system/camera.h
index 81ce4cb..86b62b7 100644
--- a/include/system/camera.h
+++ b/include/system/camera.h
@@ -105,8 +105,8 @@
      * This does not affect the order of byte array of
      * CAMERA_MSG_PREVIEW_FRAME, CAMERA_MSG_VIDEO_FRAME,
      * CAMERA_MSG_POSTVIEW_FRAME, CAMERA_MSG_RAW_IMAGE, or
-     * CAMERA_MSG_COMPRESSED_IMAGE. This is not allowed to be set during
-     * preview
+     * CAMERA_MSG_COMPRESSED_IMAGE. This is allowed to be set during preview
+     * since API level 14.
      */
     CAMERA_CMD_SET_DISPLAY_ORIENTATION = 3,
 
diff --git a/liblog/logprint.c b/liblog/logprint.c
index 4c5b3e5..59fed9b 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -350,16 +350,28 @@
 int android_log_processLogBuffer(struct logger_entry *buf,
                                  AndroidLogEntry *entry)
 {
-    size_t tag_len;
-
     entry->tv_sec = buf->sec;
     entry->tv_nsec = buf->nsec;
     entry->priority = buf->msg[0];
     entry->pid = buf->pid;
     entry->tid = buf->tid;
+
+    /*
+     * format: <priority:1><tag:N>\0<message:N>\0
+     *
+     * tag str
+     *   starts at msg+1
+     * msg
+     *   starts at msg+1+len(tag)+1
+     */
     entry->tag = buf->msg + 1;
-    tag_len = strlen(entry->tag);
-    entry->messageLen = buf->len - tag_len - 3;
+    const size_t tag_len = strlen(entry->tag);
+    const size_t preambleAndNullLen = tag_len + 3;
+    if (buf->len <= preambleAndNullLen) {
+        fprintf(stderr, "+++ LOG: entry corrupt or truncated\n");
+        return -1;
+    }
+    entry->messageLen = buf->len - preambleAndNullLen;
     entry->message = entry->tag + tag_len + 1;
 
     return 0;
diff --git a/libnl_2/genl/genl.c b/libnl_2/genl/genl.c
index dd20717..2442993 100644
--- a/libnl_2/genl/genl.c
+++ b/libnl_2/genl/genl.c
@@ -112,6 +112,7 @@
 	nlmhdr.nlmsg_pid = sock->s_local.nl_pid;
 
 	/* Generic netlink header */
+	memset(&gmhhdr, 0, sizeof(gmhhdr));
 	gmhhdr.cmd = CTRL_CMD_GETFAMILY;
 	gmhhdr.version = CTRL_ATTR_FAMILY_ID;
 
@@ -221,9 +222,11 @@
 
 				/* Save the family id */
 				else if (nl80211_flag &&
-					nla->nla_type == CTRL_ATTR_FAMILY_ID)
-					nl80211_genl_id = \
+					nla->nla_type == CTRL_ATTR_FAMILY_ID) {
+					nl80211_genl_id =
 						*((int *)nla_data(nla));
+					nl80211_flag = 0;
+				}
 
 			}
 
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 96b68ef..4cd2151 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -323,7 +323,7 @@
 
                 // the caller requested to just dump the log and exit
                 if (g_nonblock) {
-                    exit(0);
+                    return;
                 }
             } else {
                 // print all that aren't the last in their list
@@ -765,10 +765,10 @@
     }
 
     if (getLogSize) {
-        return 0;
+        exit(0);
     }
     if (clearLog) {
-        return 0;
+        exit(0);
     }
 
     //LOG_EVENT_INT(10, 12345);
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 5102565..10c0f12 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -416,12 +416,12 @@
 service drm /system/bin/drmserver
     class main
     user drm
-    group system inet
+    group system inet drmrpc
 
 service media /system/bin/mediaserver
     class main
     user media
-    group audio camera inet net_bt net_bt_admin net_bw_acct
+    group audio camera inet net_bt net_bt_admin net_bw_acct drmrpc
     ioprio rt 4
 
 service bootanim /system/bin/bootanimation