Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c1cd702 authored by Mark Salyzyn's avatar Mark Salyzyn Committed by android-build-merger
Browse files

Merge "logd: switch from android_ids to getpwuid"

am: 9a3e238a

* commit '9a3e238a':
  logd: switch from android_ids to getpwuid

Change-Id: Ief9baf28b1bfc062d205fd75f871323a28d6e1a8
parents 98ab3c0a 9a3e238a
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -15,8 +15,10 @@
 */

#include <fcntl.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

#include <log/logger.h>
@@ -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;