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

Commit 484f2863 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: 82be7f01

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

Change-Id: Ibf1cb5eaa7af5e63244ceaa9bd104838e1cd3306
parents dc060f9c 82be7f01
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -19,18 +19,14 @@

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

namespace android {
namespace installd {

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

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

template<typename Func>
bool ParseFile(std::istream& input_stream, Func parse) {
    while (!input_stream.eof()) {
        // Read the next line.
        std::string line;
@@ -54,6 +50,15 @@ bool ParseFile(const std::string& strFile, std::function<bool (const std::string
    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 android

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

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

#include "android-base/file.h"
#include "dexopt.h"
#include "file_parsing.h"
#include "globals.h"
@@ -195,18 +197,14 @@ private:
        //   export NAME VALUE
        // For simplicity, don't respect string quotation. The values we are interested in can be
        // 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.
        // 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
        static constexpr const char* kEnvironmentVariableSources[] = {
                "/init.environ.rc", "/etc/classpath"
        };
        //
        // init.environ.rc and derive_classpath all have the same format for
        // environment variable exports (since they are all meant to be read by
        // init) and can be matched by the same regex.

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

              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;
          }
          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) {
            return false;
        }
+1 −0
Original line number 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[] = {
      "com.android.art",
      "com.android.runtime",
      "com.android.sdkext",  // For derive_classpath
    };
    std::array<bool, arraysize(kRequiredApexs)> found_apexs{ false, false };
    DIR* apex_dir = opendir("/apex");