Merge "Handle invalid shared GIDs." am: 788bdeae78 am: 477601a9ff am: 4be16dccfe
am: 2d9bf64d9f

Change-Id: I3fb92764c2a0271483e31646c63fbabd1f1c58c6
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp
index 8a9d6a6..81369f9 100644
--- a/cmds/installd/InstalldNativeService.cpp
+++ b/cmds/installd/InstalldNativeService.cpp
@@ -323,8 +323,8 @@
             const std::string ref_profile_path = create_data_ref_profile_package_path(pkgname);
             // dex2oat/profman runs under the shared app gid and it needs to read/write reference
             // profiles.
-            appid_t shared_app_gid = multiuser_get_shared_app_gid(uid);
-            if (fs_prepare_dir_strict(
+            int shared_app_gid = multiuser_get_shared_app_gid(uid);
+            if ((shared_app_gid != -1) && fs_prepare_dir_strict(
                     ref_profile_path.c_str(), 0700, shared_app_gid, shared_app_gid) != 0) {
                 return error("Failed to prepare " + ref_profile_path);
             }