Load /data oat/odex files non-executable when only_use_system_oat_files is set.

Make it still ok to use the vdex and the class status in the oat file.
This means:
- If dex code is uncompressed in APK we'll use that
- If dex code is compressed in APK, we'll use the dex code in the vdex.

This is a temporary solution in order to almost mimic performance-wise what
full stack integrity wants to achieve (priv-apps running from verified,
uncompressed dex code in APK).

This is to assess the impact of full stack integrity on privileged apps.

This CL doesn't ensure any integrity, and doesn't check whether the vdex has
been "tainted".

bug: 30972906

Change-Id: If0a6ab26dd6211290db53b7f02d88d45aff68c0c
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index 8707e73..20f9aaa 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -71,9 +71,12 @@
 
 OatFileAssistant::OatFileAssistant(const char* dex_location,
                                    const InstructionSet isa,
-                                   bool load_executable)
+                                   bool load_executable,
+                                   bool only_load_system_executable)
     : OatFileAssistant(dex_location,
-                       isa, load_executable,
+                       isa,
+                       load_executable,
+                       only_load_system_executable,
                        -1 /* vdex_fd */,
                        -1 /* oat_fd */,
                        -1 /* zip_fd */) {}
@@ -82,11 +85,13 @@
 OatFileAssistant::OatFileAssistant(const char* dex_location,
                                    const InstructionSet isa,
                                    bool load_executable,
+                                   bool only_load_system_executable,
                                    int vdex_fd,
                                    int oat_fd,
                                    int zip_fd)
     : isa_(isa),
       load_executable_(load_executable),
+      only_load_system_executable_(only_load_system_executable),
       odex_(this, /*is_oat_location*/ false),
       oat_(this, /*is_oat_location*/ true),
       zip_fd_(zip_fd) {
@@ -1120,6 +1125,10 @@
   if (!load_attempted_) {
     load_attempted_ = true;
     if (filename_provided_) {
+      bool executable = oat_file_assistant_->load_executable_;
+      if (executable && oat_file_assistant_->only_load_system_executable_) {
+        executable = LocationIsOnSystem(filename_.c_str());
+      }
       std::string error_msg;
       if (use_fd_) {
         if (oat_fd_ >= 0 && vdex_fd_ >= 0) {
@@ -1128,7 +1137,7 @@
                                     filename_.c_str(),
                                     nullptr,
                                     nullptr,
-                                    oat_file_assistant_->load_executable_,
+                                    executable,
                                     false /* low_4gb */,
                                     oat_file_assistant_->dex_location_.c_str(),
                                     &error_msg));
@@ -1138,7 +1147,7 @@
                                   filename_.c_str(),
                                   nullptr,
                                   nullptr,
-                                  oat_file_assistant_->load_executable_,
+                                  executable,
                                   false /* low_4gb */,
                                   oat_file_assistant_->dex_location_.c_str(),
                                   &error_msg));