From b8a95bd3c9502d48b203b9f1e5df9b84a5df6281 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Thu, 7 Apr 2016 11:06:31 -0700 Subject: [PATCH] logd: switch from android_ids to getpwuid Bug: 27999086 Change-Id: I7f4e68b21f58789b4dcada04f9c27f5722940c02 --- logd/LogStatistics.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp index 2b02bc1d7..02a4a7534 100644 --- a/logd/LogStatistics.cpp +++ b/logd/LogStatistics.cpp @@ -15,8 +15,10 @@ */ #include +#include #include #include +#include #include #include @@ -159,14 +161,13 @@ const char *LogStatistics::uidToName(uid_t uid) const { return strdup("auditd"); } - // Android hard coded - const struct android_id_info *info = android_ids; - - for (size_t i = 0; i < android_id_count; ++i) { - if (info->aid == uid) { - return strdup(info->name); + // Android system + if (uid < AID_APP) { + // in bionic, thread safe as long as we copy the results + struct passwd *pwd = getpwuid(uid); + if (pwd) { + return strdup(pwd->pw_name); } - ++info; } // Parse /data/system/packages.list @@ -179,6 +180,14 @@ const char *LogStatistics::uidToName(uid_t uid) const { return name; } + // Android application + if (uid >= AID_APP) { + struct passwd *pwd = getpwuid(uid); + if (pwd) { + return strdup(pwd->pw_name); + } + } + // report uid -> pid(s) -> pidToName if unique for(pidTable_t::const_iterator it = pidTable.begin(); it != pidTable.end(); ++it) { const PidEntry &entry = it->second;