logd: Add pidToUid helper

Change-Id: I23ebae1957c027bff6cbc2573a227bf0c44c08a2
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index 7c57660..bdb3179 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -79,6 +79,7 @@
 
     // helper
     char *pidToName(pid_t pid) { return stats.pidToName(pid); }
+    uid_t pidToUid(pid_t pid) { return stats.pidToUid(pid); }
 
 private:
     void maybePrune(log_id_t id);
diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp
index 99c376a..82a3a90 100644
--- a/logd/LogStatistics.cpp
+++ b/logd/LogStatistics.cpp
@@ -728,3 +728,20 @@
 
     *buf = strdup(string.string());
 }
+
+uid_t LogStatistics::pidToUid(pid_t pid) {
+    log_id_for_each(i) {
+        LidStatistics &l = id(i);
+        UidStatisticsCollection::iterator iu;
+        for (iu = l.begin(); iu != l.end(); ++iu) {
+            UidStatistics &u = *(*iu);
+            PidStatisticsCollection::iterator ip;
+            for (ip = u.begin(); ip != u.end(); ++ip) {
+                if ((*ip)->getPid() == pid) {
+                    return u.getUid();
+                }
+            }
+        }
+    }
+    return getuid(); // associate this with the logger
+}
diff --git a/logd/LogStatistics.h b/logd/LogStatistics.h
index 4a57435..12c68d5 100644
--- a/logd/LogStatistics.h
+++ b/logd/LogStatistics.h
@@ -172,6 +172,7 @@
 
     // helper
     static char *pidToName(pid_t pid) { return PidStatistics::pidToName(pid); }
+    uid_t pidToUid(pid_t pid);
 };
 
 #endif // _LOGD_LOG_STATISTICS_H__