Merge "Switch to new project ID constants."
diff --git a/FsCrypt.cpp b/FsCrypt.cpp
index 06389e8..276444c 100644
--- a/FsCrypt.cpp
+++ b/FsCrypt.cpp
@@ -40,6 +40,7 @@
 #include <unistd.h>
 
 #include <private/android_filesystem_config.h>
+#include <private/android_projectid_config.h>
 
 #include "android/os/IVold.h"
 
@@ -814,7 +815,8 @@
         // Setup quota project ID and inheritance policy
         if (!IsFilesystemSupported("sdcardfs")) {
             if (SetQuotaInherit(media_ce_path) != 0) return false;
-            if (SetQuotaProjectId(media_ce_path, multiuser_get_uid(user_id, AID_MEDIA_RW)) != 0) {
+            if (SetQuotaProjectId(media_ce_path,
+                                  multiuser_get_uid(user_id, PROJECT_ID_EXT_DEFAULT)) != 0) {
                 return false;
             }
         }
diff --git a/Utils.cpp b/Utils.cpp
index ef9dba6..82ad1f1 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -29,6 +29,7 @@
 #include <cutils/fs.h>
 #include <logwrap/logwrap.h>
 #include <private/android_filesystem_config.h>
+#include <private/android_projectid_config.h>
 
 #include <dirent.h>
 #include <fcntl.h>
@@ -321,7 +322,13 @@
     }
     std::string pathToCreate = root + appDir;
     int depth = 0;
-    bool withinCache = false;
+    // Derive initial project ID
+    if (appDir == kAppDataDir || appDir == kAppMediaDir) {
+        projectId = uid - AID_APP_START + PROJECT_ID_EXT_DATA_START;
+    } else if (appDir == kAppObbDir) {
+        projectId = uid - AID_APP_START + PROJECT_ID_EXT_OBB_START;
+    }
+
     while ((pos = leftToCreate.find('/')) != std::string::npos) {
         std::string component = leftToCreate.substr(0, pos + 1);
         leftToCreate = leftToCreate.erase(0, pos + 1);
@@ -332,12 +339,7 @@
             // Android/data, eg Android/data/com.foo/cache
             // Note that this "sticks" - eg subdirs of this dir need the same
             // project ID.
-            withinCache = true;
-        }
-        if (withinCache) {
-            projectId = uid - AID_APP_START + AID_CACHE_GID_START;
-        } else {
-            projectId = uid - AID_APP_START + AID_EXT_GID_START;
+            projectId = uid - AID_APP_START + PROJECT_ID_EXT_CACHE_START;
         }
 
         if (fixupExisting && access(pathToCreate.c_str(), F_OK) == 0) {