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

Commit 54889cf8 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 7321546 from 449d34df to sc-release

Change-Id: Ic1ffa7b2de518056ddfa859cfcb8f93626f19ceb
parents 73d4ce46 449d34df
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -59,9 +59,6 @@
        }
      ]
    },
    {
      "name": "libsurfaceflinger_unittest"
    },
    {
      "name": "CtsGraphicsTestCases",
      "options": [
+4 −0
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@ cc_defaults {
        "libutils",
        "server_configurable_flags",
    ],
    static_libs: [
        "libasync_safe",
    ],
    export_shared_lib_headers: [
        "libbinder",
    ],
@@ -250,6 +253,7 @@ cc_binary {
    ],

    static_libs: [
        "libasync_safe",
        "libdiskusage",
        "libotapreoptparameters",
    ],
+26 −12
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <async_safe/log.h>
#include <cutils/fs.h>
#include <cutils/properties.h>
#include <cutils/sched_policy.h>
@@ -727,7 +728,8 @@ bool copy_system_profile(const std::string& system_profile,

        if (flock(out_fd.get(), LOCK_EX | LOCK_NB) != 0) {
            if (errno != EWOULDBLOCK) {
                PLOG(WARNING) << "Error locking profile " << package_name;
                async_safe_format_log(ANDROID_LOG_WARN, LOG_TAG, "Error locking profile %s: %d",
                        package_name.c_str(), errno);
            }
            // This implies that the app owning this profile is running
            // (and has acquired the lock).
@@ -735,13 +737,15 @@ bool copy_system_profile(const std::string& system_profile,
            // The app never acquires the lock for the reference profiles of primary apks.
            // Only dex2oat from installd will do that. Since installd is single threaded
            // we should not see this case. Nevertheless be prepared for it.
            PLOG(WARNING) << "Failed to flock " << package_name;
            async_safe_format_log(ANDROID_LOG_WARN, LOG_TAG, "Failed to flock %s: %d",
                    package_name.c_str(), errno);
            return false;
        }

        bool truncated = ftruncate(out_fd.get(), 0) == 0;
        if (!truncated) {
            PLOG(WARNING) << "Could not truncate " << package_name;
            async_safe_format_log(ANDROID_LOG_WARN, LOG_TAG, "Could not truncate %s: %d",
                    package_name.c_str(), errno);
        }

        // Copy over data.
@@ -755,7 +759,8 @@ bool copy_system_profile(const std::string& system_profile,
            write(out_fd.get(), buffer, bytes);
        }
        if (flock(out_fd.get(), LOCK_UN) != 0) {
            PLOG(WARNING) << "Error unlocking profile " << package_name;
            async_safe_format_log(ANDROID_LOG_WARN, LOG_TAG, "Error unlocking profile %s: %d",
                    package_name.c_str(), errno);
        }
        // Use _exit since we don't want to run the global destructors in the child.
        // b/62597429
@@ -1513,7 +1518,8 @@ static bool process_secondary_dex_dexopt(const std::string& dex_path, const char

        // Validate the path structure.
        if (!validate_secondary_dex_path(pkgname, dex_path, volume_uuid, uid, storage_flag)) {
            LOG(ERROR) << "Could not validate secondary dex path " << dex_path;
            async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG,
                    "Could not validate secondary dex path %s", dex_path.c_str());
            _exit(kSecondaryDexDexoptAnalyzerSkippedValidatePath);
        }

@@ -1809,7 +1815,8 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins
        drop_capabilities(uid);

        if (flock(out_oat.fd(), LOCK_EX | LOCK_NB) != 0) {
            PLOG(ERROR) << "flock(" << out_oat.path() << ") failed";
            async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG, "flock(%s) failed",
                    out_oat.path().c_str());
            _exit(DexoptReturnCodes::kFlock);
        }

@@ -1904,7 +1911,8 @@ bool reconcile_secondary_dex_file(const std::string& dex_path,
        const char* volume_uuid_cstr = volume_uuid ? volume_uuid->c_str() : nullptr;
        if (!validate_secondary_dex_path(pkgname, dex_path, volume_uuid_cstr,
                uid, storage_flag)) {
            LOG(ERROR) << "Could not validate secondary dex path " << dex_path;
            async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG,
                    "Could not validate secondary dex path %s", dex_path.c_str());
            _exit(kReconcileSecondaryDexValidationError);
        }

@@ -1917,7 +1925,8 @@ bool reconcile_secondary_dex_file(const std::string& dex_path,
            case kSecondaryDexAccessIOError: _exit(kReconcileSecondaryDexAccessIOError);
            case kSecondaryDexAccessPermissionError: _exit(kReconcileSecondaryDexValidationError);
            default:
                LOG(ERROR) << "Unexpected result from check_secondary_dex_access: " << access_check;
                async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG,
                        "Unexpected result from check_secondary_dex_access: %d", access_check);
                _exit(kReconcileSecondaryDexValidationError);
        }

@@ -1930,7 +1939,7 @@ bool reconcile_secondary_dex_file(const std::string& dex_path,
            std::string error_msg;
            if (!create_secondary_dex_oat_layout(
                    dex_path,isas[i], oat_dir, oat_isa_dir, oat_path, &error_msg)) {
                LOG(ERROR) << error_msg;
                async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG, "%s", error_msg.c_str());
                _exit(kReconcileSecondaryDexValidationError);
            }

@@ -1957,7 +1966,8 @@ bool reconcile_secondary_dex_file(const std::string& dex_path,
            result = rmdir_if_empty(oat_dir) && result;
        }
        if (!result) {
            PLOG(ERROR) << "Failed to clean secondary dex artifacts for location " << dex_path;
            async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG,
                    "Could not validate secondary dex path %s", dex_path.c_str());
        }
        _exit(result ? kReconcileSecondaryDexCleanedUp : kReconcileSecondaryDexAccessIOError);
    }
@@ -2030,7 +2040,8 @@ bool hash_secondary_dex_file(const std::string& dex_path, const std::string& pkg
        pipe_read.reset();

        if (!validate_secondary_dex_path(pkgname, dex_path, volume_uuid_cstr, uid, storage_flag)) {
            LOG(ERROR) << "Could not validate secondary dex path " << dex_path;
            async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG,
                    "Could not validate secondary dex path %s", dex_path.c_str());
            _exit(DexoptReturnCodes::kHashValidatePath);
        }

@@ -2041,6 +2052,8 @@ bool hash_secondary_dex_file(const std::string& dex_path, const std::string& pkg
                _exit(0);
            }
            PLOG(ERROR) << "Failed to open secondary dex " << dex_path;
            async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG,
                    "Failed to open secondary dex %s: %d", dex_path.c_str(), errno);
            _exit(DexoptReturnCodes::kHashOpenPath);
        }

@@ -2053,7 +2066,8 @@ bool hash_secondary_dex_file(const std::string& dex_path, const std::string& pkg
            if (bytes_read == 0) {
                break;
            } else if (bytes_read == -1) {
                PLOG(ERROR) << "Failed to read secondary dex " << dex_path;
                async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG,
                        "Failed to read secondary dex %s: %d", dex_path.c_str(), errno);
                _exit(DexoptReturnCodes::kHashReadDex);
            }

+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;
        }
Loading