Merge changes I459078c4,I36be1b49

* changes:
  storaged: clean up output format
  storaged: replace string functions that can throw exception
diff --git a/storaged/storaged_service.cpp b/storaged/storaged_service.cpp
index f968ed7..33e85e3 100644
--- a/storaged/storaged_service.cpp
+++ b/storaged/storaged_service.cpp
@@ -18,6 +18,8 @@
 
 #include <vector>
 
+#include <android-base/parseint.h>
+#include <android-base/parsedouble.h>
 #include <binder/IBinder.h>
 #include <binder/IInterface.h>
 
@@ -29,6 +31,8 @@
 #include <storaged.h>
 #include <storaged_service.h>
 
+using namespace android::base;
+
 extern storaged_t storaged;
 
 std::vector<struct uid_info> BpStoraged::dump_uids(const char* /*option*/) {
@@ -97,19 +101,22 @@
         if (arg == String16("--hours")) {
             if (++i >= args.size())
                 break;
-            hours = std::stod(String8(args[i]).string());
+            if(!ParseDouble(String8(args[i]).c_str(), &hours))
+                return BAD_VALUE;
             continue;
         }
         if (arg == String16("--time_window")) {
             if (++i >= args.size())
                 break;
-            time_window = std::stoi(String8(args[i]).string());
+            if(!ParseInt(String8(args[i]).c_str(), &time_window))
+                return BAD_VALUE;
             continue;
         }
         if (arg == String16("--threshold")) {
             if (++i >= args.size())
                 break;
-            threshold = std::stoll(String8(args[i]).string());
+            if(!ParseUint(String8(args[i]).c_str(), &threshold))
+                return BAD_VALUE;
             continue;
         }
         if (arg == String16("--force")) {
@@ -129,16 +136,16 @@
         last_ts = it.first;
 
         for (const auto& record : it.second.entries) {
-            dprintf(fd, "%s %llu %llu %llu %llu %llu %llu %llu %llu\n",
+            dprintf(fd, "%s %ju %ju %ju %ju %ju %ju %ju %ju\n",
                 record.name.c_str(),
-                (unsigned long long)record.ios.bytes[READ][FOREGROUND][CHARGER_OFF],
-                (unsigned long long)record.ios.bytes[WRITE][FOREGROUND][CHARGER_OFF],
-                (unsigned long long)record.ios.bytes[READ][BACKGROUND][CHARGER_OFF],
-                (unsigned long long)record.ios.bytes[WRITE][BACKGROUND][CHARGER_OFF],
-                (unsigned long long)record.ios.bytes[READ][FOREGROUND][CHARGER_ON],
-                (unsigned long long)record.ios.bytes[WRITE][FOREGROUND][CHARGER_ON],
-                (unsigned long long)record.ios.bytes[READ][BACKGROUND][CHARGER_ON],
-                (unsigned long long)record.ios.bytes[WRITE][BACKGROUND][CHARGER_ON]);
+                record.ios.bytes[READ][FOREGROUND][CHARGER_OFF],
+                record.ios.bytes[WRITE][FOREGROUND][CHARGER_OFF],
+                record.ios.bytes[READ][BACKGROUND][CHARGER_OFF],
+                record.ios.bytes[WRITE][BACKGROUND][CHARGER_OFF],
+                record.ios.bytes[READ][FOREGROUND][CHARGER_ON],
+                record.ios.bytes[WRITE][FOREGROUND][CHARGER_ON],
+                record.ios.bytes[READ][BACKGROUND][CHARGER_ON],
+                record.ios.bytes[WRITE][BACKGROUND][CHARGER_ON]);
         }
     }
 
diff --git a/storaged/storaged_uid_monitor.cpp b/storaged/storaged_uid_monitor.cpp
index 8bb6bf3..5bb98e1 100644
--- a/storaged/storaged_uid_monitor.cpp
+++ b/storaged/storaged_uid_monitor.cpp
@@ -25,6 +25,7 @@
 #include <android-base/file.h>
 #include <android-base/logging.h>
 #include <android-base/macros.h>
+#include <android-base/parseint.h>
 #include <android-base/strings.h>
 #include <android-base/stringprintf.h>
 #include <log/log_event_list.h>
@@ -59,12 +60,12 @@
 {
     std::unordered_map<uint32_t, struct uid_info> uid_io_stats;
     std::string buffer;
-    if (!android::base::ReadFileToString(UID_IO_STATS_PATH, &buffer)) {
+    if (!ReadFileToString(UID_IO_STATS_PATH, &buffer)) {
         PLOG_TO(SYSTEM, ERROR) << UID_IO_STATS_PATH << ": ReadFileToString failed";
         return uid_io_stats;
     }
 
-    std::vector<std::string> io_stats = android::base::Split(buffer, "\n");
+    std::vector<std::string> io_stats = Split(buffer, "\n");
     struct uid_info u;
     bool refresh_uid = false;
 
@@ -72,26 +73,23 @@
         if (io_stats[i].empty()) {
             continue;
         }
-        std::vector<std::string> fields = android::base::Split(io_stats[i], " ");
-        if (fields.size() < 9) {
-            LOG_TO(SYSTEM, WARNING) << "Invalid io stats: \""
+        std::vector<std::string> fields = Split(io_stats[i], " ");
+        if (fields.size() < 11 ||
+            !ParseUint(fields[0],  &u.uid) ||
+            !ParseUint(fields[1],  &u.io[FOREGROUND].rchar) ||
+            !ParseUint(fields[2],  &u.io[FOREGROUND].wchar) ||
+            !ParseUint(fields[3],  &u.io[FOREGROUND].read_bytes) ||
+            !ParseUint(fields[4],  &u.io[FOREGROUND].write_bytes) ||
+            !ParseUint(fields[5],  &u.io[BACKGROUND].rchar) ||
+            !ParseUint(fields[6],  &u.io[BACKGROUND].wchar) ||
+            !ParseUint(fields[7],  &u.io[BACKGROUND].read_bytes) ||
+            !ParseUint(fields[8],  &u.io[BACKGROUND].write_bytes) ||
+            !ParseUint(fields[9],  &u.io[FOREGROUND].fsync) ||
+            !ParseUint(fields[10], &u.io[BACKGROUND].fsync)) {
+            LOG_TO(SYSTEM, WARNING) << "Invalid I/O stats: \""
                                     << io_stats[i] << "\"";
             continue;
         }
-        u.uid = stoul(fields[0]);
-        u.io[FOREGROUND].rchar = stoull(fields[1]);
-        u.io[FOREGROUND].wchar = stoull(fields[2]);
-        u.io[FOREGROUND].read_bytes = stoull(fields[3]);
-        u.io[FOREGROUND].write_bytes = stoull(fields[4]);
-        u.io[BACKGROUND].rchar = stoull(fields[5]);
-        u.io[BACKGROUND].wchar = stoull(fields[6]);
-        u.io[BACKGROUND].read_bytes = stoull(fields[7]);
-        u.io[BACKGROUND].write_bytes = stoull(fields[8]);
-
-        if (fields.size() == 11) {
-            u.io[FOREGROUND].fsync = stoull(fields[9]);
-            u.io[BACKGROUND].fsync = stoull(fields[10]);
-        }
 
         if (last_uid_io_stats.find(u.uid) == last_uid_io_stats.end()) {
             refresh_uid = true;
diff --git a/storaged/storaged_utils.cpp b/storaged/storaged_utils.cpp
index 5df0185..9fcf1fa 100644
--- a/storaged/storaged_utils.cpp
+++ b/storaged/storaged_utils.cpp
@@ -270,23 +270,11 @@
 
 // Logging functions
 void log_console_running_uids_info(std::vector<struct uid_info> uids) {
-// Sample Output:
-//                                       Application        FG Read       FG Write        FG Read       FG Write        BG Read       BG Write        BG Read       BG Write
-//                                          NAME/UID     Characters     Characters          Bytes          Bytes     Characters     Characters          Bytes          Bytes
-//                                        ----------     ----------     ----------     ----------     ----------     ----------     ----------     ----------     ----------
-//                      com.google.android.gsf.login              0              0              0              0       57195097        5137089      176386048        6512640
-//           com.google.android.googlequicksearchbox              0              0              0              0        4196821       12123468       34295808       13225984
-//                                              1037           4572            537              0              0         131352        5145643       34263040        5144576
-//                        com.google.android.youtube           2182             70              0              0       63969383         482939       38731776         466944
-
-    // Title
-    printf("Per-UID I/O stats\n");
-    printf("                                       Application        FG Read       FG Write        FG Read       FG Write        BG Read       BG Write        BG Read       BG Write       FG fsync       BG fsync\n"
-           "                                          NAME/UID     Characters     Characters          Bytes          Bytes     Characters     Characters          Bytes          Bytes                              \n"
-           "                                        ----------     ----------     ----------     ----------     ----------     ----------     ----------     ----------     ----------     ----------     ----------\n");
+    printf("name/uid fg_rchar fg_wchar fg_rbytes fg_wbytes "
+           "bg_rchar bg_wchar bg_rbytes bg_wbytes fg_fsync bg_fsync\n");
 
     for (const auto& uid : uids) {
-        printf("%50s%15ju%15ju%15ju%15ju%15ju%15ju%15ju%15ju%15ju%15ju\n", uid.name.c_str(),
+        printf("%s %ju %ju %ju %ju %ju %ju %ju %ju %ju %ju\n", uid.name.c_str(),
             uid.io[0].rchar, uid.io[0].wchar, uid.io[0].read_bytes, uid.io[0].write_bytes,
             uid.io[1].rchar, uid.io[1].wchar, uid.io[1].read_bytes, uid.io[1].write_bytes,
             uid.io[0].fsync, uid.io[1].fsync);