Create new ephemeral app directory

Bug: 25119046
Change-Id: I829f7ae1df09f2b7af1cd64fbbad6c1f5a2d716d
diff --git a/cmds/installd/commands.cpp b/cmds/installd/commands.cpp
index 2fd5cd2..17201d5 100644
--- a/cmds/installd/commands.cpp
+++ b/cmds/installd/commands.cpp
@@ -36,6 +36,7 @@
 dir_rec_t android_asec_dir;
 dir_rec_t android_app_dir;
 dir_rec_t android_app_private_dir;
+dir_rec_t android_app_ephemeral_dir;
 dir_rec_t android_app_lib_dir;
 dir_rec_t android_media_dir;
 dir_rec_t android_mnt_expand_dir;
diff --git a/cmds/installd/installd.cpp b/cmds/installd/installd.cpp
index 52f7b9c..cb76f33 100644
--- a/cmds/installd/installd.cpp
+++ b/cmds/installd/installd.cpp
@@ -346,6 +346,11 @@
         return -1;
     }
 
+    // Get the android ephemeral app directory.
+    if (copy_and_append(&android_app_ephemeral_dir, &android_data_dir, EPHEMERAL_APP_SUBDIR) < 0) {
+        return -1;
+    }
+
     // Get the android app native library directory.
     if (copy_and_append(&android_app_lib_dir, &android_data_dir, APP_LIB_SUBDIR) < 0) {
         return -1;
@@ -367,7 +372,7 @@
     }
 
     // Take note of the system and vendor directories.
-    android_system_dirs.count = 4;
+    android_system_dirs.count = 5;
 
     android_system_dirs.dirs = (dir_rec_t*) calloc(android_system_dirs.count, sizeof(dir_rec_t));
     if (android_system_dirs.dirs == NULL) {
@@ -393,6 +398,9 @@
     android_system_dirs.dirs[3].path = strdup("/oem/app/");
     android_system_dirs.dirs[3].len = strlen(android_system_dirs.dirs[3].path);
 
+    android_system_dirs.dirs[4].path = build_string2(android_root_dir.path, EPHEMERAL_APP_SUBDIR);
+    android_system_dirs.dirs[4].len = strlen(android_system_dirs.dirs[4].path);
+
     return 0;
 }
 
diff --git a/cmds/installd/installd.h b/cmds/installd/installd.h
index d911c49..8662417 100644
--- a/cmds/installd/installd.h
+++ b/cmds/installd/installd.h
@@ -65,6 +65,7 @@
 
 #define APP_SUBDIR             "app/" // sub-directory under ANDROID_DATA
 #define PRIV_APP_SUBDIR        "priv-app/" // sub-directory under ANDROID_DATA
+#define EPHEMERAL_APP_SUBDIR   "app-ephemeral/" // sub-directory under ANDROID_DATA
 
 #define APP_LIB_SUBDIR         "app-lib/" // sub-directory under ANDROID_DATA
 
@@ -124,6 +125,7 @@
 
 extern dir_rec_t android_app_dir;
 extern dir_rec_t android_app_private_dir;
+extern dir_rec_t android_app_ephemeral_dir;
 extern dir_rec_t android_app_lib_dir;
 extern dir_rec_t android_data_dir;
 extern dir_rec_t android_asec_dir;
diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp
index 549a420..e51e731 100644
--- a/cmds/installd/utils.cpp
+++ b/cmds/installd/utils.cpp
@@ -1079,6 +1079,8 @@
         dir = &android_app_dir;
     } else if (!strncmp(path, android_app_private_dir.path, android_app_private_dir.len)) {
         dir = &android_app_private_dir;
+    } else if (!strncmp(path, android_app_ephemeral_dir.path, android_app_ephemeral_dir.len)) {
+        dir = &android_app_ephemeral_dir;
     } else if (!strncmp(path, android_asec_dir.path, android_asec_dir.len)) {
         dir = &android_asec_dir;
     } else if (!strncmp(path, android_mnt_expand_dir.path, android_mnt_expand_dir.len)) {