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

Commit f848d1eb authored by Jared Duke's avatar Jared Duke Committed by Android (Google) Code Review
Browse files

Merge "Remove installd support for compiled views" into main

parents 52a23d71 c7b93c03
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ cc_defaults {
        "unique_file.cpp",
        "utils.cpp",
        "utils_default.cpp",
        "view_compiler.cpp",
        ":installd_aidl",
    ],
    shared_libs: [
@@ -254,7 +253,6 @@ cc_binary {
        "unique_file.cpp",
        "utils.cpp",
        "utils_default.cpp",
        "view_compiler.cpp",
    ],

    static_libs: [
+0 −12
Original line number Diff line number Diff line
@@ -69,7 +69,6 @@
#include "installd_deps.h"
#include "otapreopt_utils.h"
#include "utils.h"
#include "view_compiler.h"

#include "CacheTracker.h"
#include "CrateManager.h"
@@ -3258,17 +3257,6 @@ binder::Status InstalldNativeService::controlDexOptBlocking(bool block) {
    return ok();
}

binder::Status InstalldNativeService::compileLayouts(const std::string& apkPath,
                                                     const std::string& packageName,
                                                     const std ::string& outDexFile, int uid,
                                                     bool* _aidl_return) {
    const char* apk_path = apkPath.c_str();
    const char* package_name = packageName.c_str();
    const char* out_dex_file = outDexFile.c_str();
    *_aidl_return = android::installd::view_compiler(apk_path, package_name, out_dex_file, uid);
    return *_aidl_return ? ok() : error("viewcompiler failed");
}

binder::Status InstalldNativeService::linkNativeLibraryDirectory(
        const std::optional<std::string>& uuid, const std::string& packageName,
        const std::string& nativeLibPath32, int32_t userId) {
+0 −3
Original line number Diff line number Diff line
@@ -146,9 +146,6 @@ public:

    binder::Status controlDexOptBlocking(bool block);

    binder::Status compileLayouts(const std::string& apkPath, const std::string& packageName,
                                  const std::string& outDexFile, int uid, bool* _aidl_return);

    binder::Status rmdex(const std::string& codePath, const std::string& instructionSet);

    binder::Status mergeProfiles(int32_t uid, const std::string& packageName,
+0 −2
Original line number Diff line number Diff line
@@ -70,8 +70,6 @@ interface IInstalld {
    // Blocks (when block is true) or unblock (when block is false) dexopt.
    // Blocking also invloves cancelling the currently running dexopt.
    void controlDexOptBlocking(boolean block);
    boolean compileLayouts(@utf8InCpp String apkPath, @utf8InCpp String packageName,
            @utf8InCpp String outDexFile, int uid);

    void rmdex(@utf8InCpp String codePath, @utf8InCpp String instructionSet);

cmds/installd/view_compiler.cpp

deleted100644 → 0
+0 −111
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "view_compiler.h"

#include <string>

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include "utils.h"

#include "android-base/logging.h"
#include "android-base/stringprintf.h"
#include "android-base/unique_fd.h"

namespace android {
namespace installd {

namespace {

using ::android::base::unique_fd;

constexpr int kTimeoutMs = 300000;

} // namespace

bool view_compiler(const char* apk_path, const char* package_name, const char* out_dex_file,
                   int uid) {
    CHECK(apk_path != nullptr);
    CHECK(package_name != nullptr);
    CHECK(out_dex_file != nullptr);

    // viewcompiler won't have permission to open anything, so we have to open the files first
    // and pass file descriptors.

    // Open input file
    unique_fd infd{open(apk_path, O_RDONLY)}; // NOLINT(android-cloexec-open)
    if (infd.get() < 0) {
        PLOG(ERROR) << "Could not open input file: " << apk_path;
        return false;
    }

    // Set up output file. viewcompiler can't open outputs by fd, but it can write to stdout, so
    // we close stdout and open it towards the right output.
    unique_fd outfd{open(out_dex_file, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644)};
    if (outfd.get() < 0) {
        PLOG(ERROR) << "Could not open output file: " << out_dex_file;
        return false;
    }
    if (fchmod(outfd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) != 0) {
        PLOG(ERROR) << "Could not change output file permissions";
        return false;
    }
    if (dup2(outfd, STDOUT_FILENO) < 0) {
        PLOG(ERROR) << "Could not duplicate output file descriptor";
        return false;
    }

    // Prepare command line arguments for viewcompiler
    std::string args[] = {"/system/bin/viewcompiler",
                          "--apk",
                          "--infd",
                          android::base::StringPrintf("%d", infd.get()),
                          "--dex",
                          "--package",
                          package_name};
    char* const argv[] = {const_cast<char*>(args[0].c_str()), const_cast<char*>(args[1].c_str()),
                          const_cast<char*>(args[2].c_str()), const_cast<char*>(args[3].c_str()),
                          const_cast<char*>(args[4].c_str()), const_cast<char*>(args[5].c_str()),
                          const_cast<char*>(args[6].c_str()), nullptr};

    pid_t pid = fork();
    if (pid == 0) {
        // Now that we've opened the files we need, drop privileges.
        drop_capabilities(uid);
        execv("/system/bin/viewcompiler", argv);
        _exit(1);
    }

    int return_code = wait_child_with_timeout(pid, kTimeoutMs);
    if (!WIFEXITED(return_code)) {
        LOG(WARNING) << "viewcompiler failed for " << package_name << ":" << apk_path;
        if (WTERMSIG(return_code) == SIGKILL) {
            // If the subprocess is killed while it's writing to the file, the file is likely
            // corrupted, so we should remove it.
            remove_file_at_fd(outfd.get());
        }
        return false;
    }
    return WEXITSTATUS(return_code) == 0;
}

} // namespace installd
} // namespace android
Loading