Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f82a3916 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Update BCP computation to use derive_classpath" am: 7afb3a74 am:...

Merge "Update BCP computation to use derive_classpath" am: 7afb3a74 am: 82be7f01 am: 484f2863 am: 449d34df

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1686993

Change-Id: I52d9718417e41f4d27cee7a6416e60f44d82dfa8
parents d59b18b2 449d34df
Loading
Loading
Loading
Loading
+13 −8
Original line number Original line Diff line number Diff line
@@ -19,18 +19,14 @@


#include <fstream>
#include <fstream>
#include <functional>
#include <functional>
#include <string>
#include <string_view>
#include "android-base/unique_fd.h"


namespace android {
namespace android {
namespace installd {
namespace installd {


bool ParseFile(const std::string& strFile, std::function<bool (const std::string&)> parse) {
template<typename Func>
    std::ifstream input_stream(strFile);
bool ParseFile(std::istream& input_stream, Func parse) {

    if (!input_stream.is_open()) {
        return false;
    }

    while (!input_stream.eof()) {
    while (!input_stream.eof()) {
        // Read the next line.
        // Read the next line.
        std::string line;
        std::string line;
@@ -54,6 +50,15 @@ bool ParseFile(const std::string& strFile, std::function<bool (const std::string
    return true;
    return true;
}
}


template<typename Func>
bool ParseFile(std::string_view str_file, Func parse) {
  std::ifstream ifs(str_file);
  if (!ifs.is_open()) {
    return false;
  }
  return ParseFile(ifs, parse);
}

}  // namespace installd
}  // namespace installd
}  // namespace android
}  // namespace android


+51 −24
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@
#include <sys/capability.h>
#include <sys/capability.h>
#include <sys/prctl.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/mman.h>


#include <android-base/logging.h>
#include <android-base/logging.h>
#include <android-base/macros.h>
#include <android-base/macros.h>
@@ -36,6 +37,7 @@
#include <log/log.h>
#include <log/log.h>
#include <private/android_filesystem_config.h>
#include <private/android_filesystem_config.h>


#include "android-base/file.h"
#include "dexopt.h"
#include "dexopt.h"
#include "file_parsing.h"
#include "file_parsing.h"
#include "globals.h"
#include "globals.h"
@@ -195,18 +197,14 @@ private:
        //   export NAME VALUE
        //   export NAME VALUE
        // For simplicity, don't respect string quotation. The values we are interested in can be
        // For simplicity, don't respect string quotation. The values we are interested in can be
        // encoded without them.
        // encoded without them.
        // init.environ.rc and etc/classpath have the same format for
        //
        // environment variable exports and can be matched by the same regex.
        // init.environ.rc and derive_classpath all have the same format for
        // TODO Just like with the system-properties above we really should have
        // environment variable exports (since they are all meant to be read by
        // common code between init and otapreopt to deal with reading these
        // init) and can be matched by the same regex.
        // things. See b/181182967
        static constexpr const char* kEnvironmentVariableSources[] = {
                "/init.environ.rc", "/etc/classpath"
        };


        std::regex export_regex("\\s*export\\s+(\\S+)\\s+(\\S+)");
        std::regex export_regex("\\s*export\\s+(\\S+)\\s+(\\S+)");
        for (const char* env_vars_file : kEnvironmentVariableSources) {
        auto parse_results = [&](auto& input) {
            bool parse_result = ParseFile(env_vars_file, [&](const std::string& line) {
          ParseFile(input, [&](const std::string& line) {
              std::smatch export_match;
              std::smatch export_match;
              if (!std::regex_match(line, export_match, export_regex)) {
              if (!std::regex_match(line, export_match, export_regex)) {
                  return true;
                  return true;
@@ -223,10 +221,39 @@ private:


              return true;
              return true;
          });
          });
            if (!parse_result) {
        };

        // TODO Just like with the system-properties above we really should have
        // common code between init and otapreopt to deal with reading these
        // things. See b/181182967
        // There have been a variety of places the various env-vars have been
        // over the years.  Expand or reduce this list as needed.
        static constexpr const char* kEnvironmentVariableSources[] = {
                "/init.environ.rc",
        };
        // First get everything from the static files.
        for (const char* env_vars_file : kEnvironmentVariableSources) {
          parse_results(env_vars_file);
        }

        // Next get everything from derive_classpath, since we're already in the
        // chroot it will get the new versions of any dependencies.
        {
          android::base::unique_fd fd(memfd_create("derive_classpath_temp", MFD_CLOEXEC));
          if (!fd.ok()) {
            LOG(ERROR) << "Unable to create fd for derive_classpath";
            return false;
            return false;
          }
          }
          std::string memfd_file = StringPrintf("/proc/%d/fd/%d", getpid(), fd.get());
          std::string error_msg;
          if (!Exec({"/apex/com.android.sdkext/bin/derive_classpath", memfd_file}, &error_msg)) {
            PLOG(ERROR) << "Running derive_classpath failed: " << error_msg;
            return false;
          }
          }
          std::ifstream ifs(memfd_file);
          parse_results(ifs);
        }

        if (system_properties_.GetProperty(kAndroidDataPathPropertyName) == nullptr) {
        if (system_properties_.GetProperty(kAndroidDataPathPropertyName) == nullptr) {
            return false;
            return false;
        }
        }
+1 −0
Original line number Original line Diff line number Diff line
@@ -275,6 +275,7 @@ static int otapreopt_chroot(const int argc, char **arg) {
    static constexpr const std::string_view kRequiredApexs[] = {
    static constexpr const std::string_view kRequiredApexs[] = {
      "com.android.art",
      "com.android.art",
      "com.android.runtime",
      "com.android.runtime",
      "com.android.sdkext",  // For derive_classpath
    };
    };
    std::array<bool, arraysize(kRequiredApexs)> found_apexs{ false, false };
    std::array<bool, arraysize(kRequiredApexs)> found_apexs{ false, false };
    DIR* apex_dir = opendir("/apex");
    DIR* apex_dir = opendir("/apex");