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

Commit 38621c80 authored by Andreas Gampe's avatar Andreas Gampe Committed by android-build-merger
Browse files

Merge changes Iee2d74a3,Ib2298818 am: 1d0c5b63

am: 335a8ea6

Change-Id: I6677925be1073eaf46ddfb9e4e895d8e3059af70
parents edc39e36 335a8ea6
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
{
  "presubmit": [
    {
      "name": "installd_cache_test"
    },
    {
      "name": "installd_dexopt_test"
    },
    {
      "name": "installd_otapreopt_test"
    },
    {
      "name": "installd_service_test"
    },
    {
      "name": "installd_utils_test"
    }
  ]
}
+64 −21
Original line number Diff line number Diff line
@@ -84,10 +84,16 @@ static void run_cmd(const std::string& cmd) {
    system(cmd.c_str());
}

static void mkdir(const std::string& path, uid_t owner, gid_t group, mode_t mode) {
    ::mkdir(path.c_str(), mode);
    ::chown(path.c_str(), owner, group);
    ::chmod(path.c_str(), mode);
static int mkdir(const std::string& path, uid_t owner, gid_t group, mode_t mode) {
    int ret = ::mkdir(path.c_str(), mode);
    if (ret != 0) {
        return ret;
    }
    ret = ::chown(path.c_str(), owner, group);
    if (ret != 0) {
        return ret;
    }
    return ::chmod(path.c_str(), mode);
}

static int log_callback(int type, const char *fmt, ...) { // NOLINT
@@ -184,7 +190,7 @@ protected:
        se_info_ = "default";
        app_apk_dir_ = android_app_dir + package_name_;

        create_mock_app();
        ASSERT_TRUE(create_mock_app());
    }

    virtual void TearDown() {
@@ -198,18 +204,29 @@ protected:
        delete service_;
    }

    void create_mock_app() {
    ::testing::AssertionResult create_mock_app() {
        // Create the oat dir.
        app_oat_dir_ = app_apk_dir_ + "/oat";
        mkdir(app_apk_dir_, kSystemUid, kSystemGid, 0755);
        service_->createOatDir(app_oat_dir_, kRuntimeIsa);
        if (mkdir(app_apk_dir_, kSystemUid, kSystemGid, 0755) != 0) {
            return ::testing::AssertionFailure() << "Could not create app dir " << app_apk_dir_
                                                 << " : " << strerror(errno);
        }
        binder::Status status = service_->createOatDir(app_oat_dir_, kRuntimeIsa);
        if (!status.isOk()) {
            return ::testing::AssertionFailure() << "Could not create oat dir: "
                                                 << status.toString8().c_str();
        }

        // Copy the primary apk.
        apk_path_ = app_apk_dir_ + "/base.jar";
        ASSERT_TRUE(WriteBase64ToFile(kDexFile, apk_path_, kSystemUid, kSystemGid, 0644));
        std::string error_msg;
        if (!WriteBase64ToFile(kDexFile, apk_path_, kSystemUid, kSystemGid, 0644, &error_msg)) {
            return ::testing::AssertionFailure() << "Could not write base64 file to " << apk_path_
                                                 << " : " << error_msg;
        }

        // Create the app user data.
        ASSERT_TRUE(service_->createAppData(
        status = service_->createAppData(
                volume_uuid_,
                package_name_,
                kTestUserId,
@@ -217,14 +234,26 @@ protected:
                kTestAppUid,
                se_info_,
                kOSdkVersion,
            &ce_data_inode_).isOk());
                &ce_data_inode_);
        if (!status.isOk()) {
            return ::testing::AssertionFailure() << "Could not create app data: "
                                                 << status.toString8().c_str();
        }

        // Create a secondary dex file on CE storage
        const char* volume_uuid_cstr = volume_uuid_ == nullptr ? nullptr : volume_uuid_->c_str();
        app_private_dir_ce_ = create_data_user_ce_package_path(
                volume_uuid_cstr, kTestUserId, package_name_.c_str());
        secondary_dex_ce_ = app_private_dir_ce_ + "/secondary_ce.jar";
        ASSERT_TRUE(WriteBase64ToFile(kDexFile, secondary_dex_ce_, kTestAppUid, kTestAppGid, 0600));
        if (!WriteBase64ToFile(kDexFile,
                               secondary_dex_ce_,
                               kTestAppUid,
                               kTestAppGid,
                               0600,
                               &error_msg)) {
            return ::testing::AssertionFailure() << "Could not write base64 file to "
                                                 << secondary_dex_ce_ << " : " << error_msg;
        }
        std::string app_private_dir_ce_link = create_data_user_ce_package_path_as_user_link(
                volume_uuid_cstr, kTestUserId, package_name_.c_str());
        secondary_dex_ce_link_ = app_private_dir_ce_link + "/secondary_ce.jar";
@@ -233,10 +262,24 @@ protected:
        app_private_dir_de_ = create_data_user_de_package_path(
                volume_uuid_cstr, kTestUserId, package_name_.c_str());
        secondary_dex_de_ = app_private_dir_de_ + "/secondary_de.jar";
        ASSERT_TRUE(WriteBase64ToFile(kDexFile, secondary_dex_de_, kTestAppUid, kTestAppGid, 0600));
        if (!WriteBase64ToFile(kDexFile,
                               secondary_dex_de_,
                               kTestAppUid,
                               kTestAppGid,
                               0600,
                               &error_msg)) {
            return ::testing::AssertionFailure() << "Could not write base64 file to "
                                                 << secondary_dex_de_ << " : " << error_msg;
        }

        // Fix app data uid.
        ASSERT_TRUE(service_->fixupAppData(volume_uuid_, kTestUserId).isOk());
        status = service_->fixupAppData(volume_uuid_, kTestUserId);
        if (!status.isOk()) {
            return ::testing::AssertionFailure() << "Could not fixup app data: "
                                                 << status.toString8().c_str();
        }

        return ::testing::AssertionSuccess();
    }


+8 −5
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
#include <sys/capability.h>

#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <selinux/android.h>

uint8_t kBase64Map[256] = {
@@ -74,7 +75,7 @@ uint8_t* DecodeBase64(const char* src, size_t* dst_size) {
}

bool WriteBase64ToFile(const char* base64, const std::string& file,
        uid_t uid, gid_t gid, int mode) {
        uid_t uid, gid_t gid, int mode, std::string* error_msg) {
    CHECK(base64 != nullptr);
    size_t length;
    std::unique_ptr<uint8_t[]> bytes(DecodeBase64(base64, &length));
@@ -83,8 +84,10 @@ bool WriteBase64ToFile(const char* base64, const std::string& file,

    int fd = open(file.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);

    using android::base::StringPrintf;

    if (fd < 0) {
        PLOG(ERROR) << "Could not open file " << file;
        *error_msg = StringPrintf("Could not open file %s: %s", file.c_str(), strerror(errno));
        return false;
    }

@@ -92,18 +95,18 @@ bool WriteBase64ToFile(const char* base64, const std::string& file,
    while (wrote < length) {
        ssize_t cur = write(fd, bytes.get() + wrote, length - wrote);
        if (cur == -1) {
            PLOG(ERROR) << "Could not write file " << file;
            *error_msg = StringPrintf("Could not write file %s: %s", file.c_str(), strerror(errno));
            return false;
        }
        wrote += cur;
    }

    if (::chown(file.c_str(), uid, gid) != 0) {
        PLOG(ERROR) << "Could not chown file " << file;
        *error_msg = StringPrintf("Could not chown file %s: %s", file.c_str(), strerror(errno));
        return false;
    }
    if (::chmod(file.c_str(), mode) != 0) {
        PLOG(ERROR) << "Could not chmod file " << file;
        *error_msg = StringPrintf("Could not chmod file %s: %s", file.c_str(), strerror(errno));
        return false;
    }
    return true;