8 #define PACKAGE_LIST_PATH "/data/system/packages.list"
9 #define PACKAGE_NAME_MAX_LEN (1<<16)
11 /* Tries to resolve a package name from a uid via the packages list file.
13 * If there is no matching uid, it will return an empty string which can
14 * be resolved by appops in some cases (i.e. apps with uid = 0, uid = AID_SHELL).
16 * Since packages may share UID, this function will return the first present
19 const char* resolve_package_name(int uid) {
20 char *packages = read_file(PACKAGE_LIST_PATH);
22 if (packages == NULL) {
28 char *line_end = strstr(p, "\n");
33 char *pkgName = strtok_r(p, " ", &token);
34 if (pkgName != NULL) {
35 char *pkgUid = strtok_r(NULL, " ", &token);
39 int pkgUidInt = strtoul(pkgUid, &endptr, 10);
40 if ((errno == 0 && endptr != NULL && !(*endptr)) && pkgUidInt == uid)
41 return strdup(pkgName);