Sepolicy: Add base runtime APEX postinstall policies

Add art_apex_postinstall domain that is allowed to move
precreated AoT artifacts from /data/ota.

Bug: 125474642
Test: m
Change-Id: Id674e202737155a4ee31187f096d1dd655001fdd
diff --git a/apex/com.android.runtime.debug-file_contexts b/apex/com.android.runtime.debug-file_contexts
index 059b52a..592975d 100644
--- a/apex/com.android.runtime.debug-file_contexts
+++ b/apex/com.android.runtime.debug-file_contexts
@@ -1,11 +1,12 @@
 #############################
 # System files
 #
-(/.*)?                        u:object_r:system_file:s0
-/bin/dex2oat(d)?              u:object_r:dex2oat_exec:s0
-/bin/dexoptanalyzer(d)?       u:object_r:dexoptanalyzer_exec:s0
-/bin/profman(d)?              u:object_r:profman_exec:s0
-/bin/linker(64)?              u:object_r:system_linker_exec:s0
-/lib(64)?(/.*)?               u:object_r:system_lib_file:s0
-/etc/tz(/.*)?                 u:object_r:system_zoneinfo_file:s0
-/bin/art_preinstall_hook(.*)? u:object_r:art_apex_preinstall_exec:s0
+(/.*)?                         u:object_r:system_file:s0
+/bin/dex2oat(d)?               u:object_r:dex2oat_exec:s0
+/bin/dexoptanalyzer(d)?        u:object_r:dexoptanalyzer_exec:s0
+/bin/profman(d)?               u:object_r:profman_exec:s0
+/bin/linker(64)?               u:object_r:system_linker_exec:s0
+/lib(64)?(/.*)?                u:object_r:system_lib_file:s0
+/etc/tz(/.*)?                  u:object_r:system_zoneinfo_file:s0
+/bin/art_preinstall_hook(.*)?  u:object_r:art_apex_preinstall_exec:s0
+/bin/art_postinstall_hook(.*)? u:object_r:art_apex_postinstall_exec:s0
diff --git a/private/apexd.te b/private/apexd.te
index 31b66f5..80e115a 100644
--- a/private/apexd.te
+++ b/private/apexd.te
@@ -95,6 +95,8 @@
 
 # Allow transition to ART APEX preinstall domain.
 domain_auto_trans(apexd, art_apex_preinstall_exec, art_apex_preinstall)
+# Allow transition to ART APEX postinstall domain.
+domain_auto_trans(apexd, art_apex_postinstall_exec, art_apex_postinstall)
 
 # Allow transition to test APEX preinstall domain.
 userdebug_or_eng(`
diff --git a/private/art_apex_postinstall.te b/private/art_apex_postinstall.te
new file mode 100644
index 0000000..4c775e8
--- /dev/null
+++ b/private/art_apex_postinstall.te
@@ -0,0 +1,23 @@
+# ART APEX postinstall.
+#
+
+type art_apex_postinstall, domain, coredomain;
+type art_apex_postinstall_exec, system_file_type, exec_type, file_type;
+
+# /dev/zero
+allow art_apex_postinstall apexd:fd use;
+
+# Read temp dirs and files. Move directories.
+allow art_apex_postinstall ota_data_file:dir { r_dir_perms write rename remove_name relabelfrom reparent };
+allow art_apex_postinstall ota_data_file:file { r_file_perms relabelfrom };
+# We're deleting the old /data/dalvik-cache/* and move the new ones
+# over.
+allow art_apex_postinstall dalvikcache_data_file:dir { create_dir_perms relabelto };
+allow art_apex_postinstall dalvikcache_data_file:file { r_file_perms unlink relabelto };
+
+# Required for relabel.
+allow art_apex_postinstall file_contexts_file:file r_file_perms;
+
+# Script helpers.
+allow art_apex_postinstall shell_exec:file rx_file_perms;
+allow art_apex_postinstall toolbox_exec:file rx_file_perms;
diff --git a/private/domain.te b/private/domain.te
index 97cccb9..a48a186 100644
--- a/private/domain.te
+++ b/private/domain.te
@@ -215,6 +215,7 @@
   -cppreopts
   -dex2oat
   -otapreopt_slot
+  -art_apex_postinstall
 } dalvikcache_data_file:file no_w_file_perms;
 
 neverallow {
@@ -226,6 +227,7 @@
   -dex2oat
   -zygote
   -otapreopt_slot
+  -art_apex_postinstall
 } dalvikcache_data_file:dir no_w_dir_perms;
 
 # Minimize dac_override and dac_read_search.