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

Commit 967390a5 authored by Alex Buynytskyy's avatar Alex Buynytskyy Committed by Android (Google) Code Review
Browse files

Merge "Add packageName argument in preparation for per-package lock."

parents d5e0d0d5 44036e24
Loading
Loading
Loading
Loading
+39 −23
Original line number Diff line number Diff line
@@ -2494,35 +2494,33 @@ static const char* getCStr(const std::optional<std::string>& data,
        const char* default_value = nullptr) {
    return data ? data->c_str() : default_value;
}
binder::Status InstalldNativeService::dexopt(const std::string& apkPath, int32_t uid,
        const std::optional<std::string>& packageName, const std::string& instructionSet,
        int32_t dexoptNeeded, const std::optional<std::string>& outputPath, int32_t dexFlags,
binder::Status InstalldNativeService::dexopt(
        const std::string& apkPath, int32_t uid, const std::string& packageName,
        const std::string& instructionSet, int32_t dexoptNeeded,
        const std::optional<std::string>& outputPath, int32_t dexFlags,
        const std::string& compilerFilter, const std::optional<std::string>& uuid,
        const std::optional<std::string>& classLoaderContext,
        const std::optional<std::string>& seInfo, bool downgrade, int32_t targetSdkVersion,
        const std::optional<std::string>& profileName,
        const std::optional<std::string>& dexMetadataPath,
        const std::optional<std::string>& compilationReason,
        bool* aidl_return) {
        const std::optional<std::string>& compilationReason, bool* aidl_return) {
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_UUID(uuid);
    CHECK_ARGUMENT_PATH(apkPath);
    if (packageName && *packageName != "*") {
        CHECK_ARGUMENT_PACKAGE_NAME(*packageName);
    }
    CHECK_ARGUMENT_PACKAGE_NAME(packageName);
    CHECK_ARGUMENT_PATH(outputPath);
    CHECK_ARGUMENT_PATH(dexMetadataPath);
    std::lock_guard<std::recursive_mutex> lock(mLock);

    const char* oat_dir = getCStr(outputPath);
    const char* instruction_set = instructionSet.c_str();
    if (oat_dir != nullptr && !createOatDir(oat_dir, instruction_set).isOk()) {
    if (oat_dir != nullptr && !createOatDir(packageName, oat_dir, instruction_set).isOk()) {
        // Can't create oat dir - let dexopt use cache dir.
        oat_dir = nullptr;
    }

    const char* apk_path = apkPath.c_str();
    const char* pkgname = getCStr(packageName, "*");
    const char* pkgname = packageName.c_str();
    const char* compiler_filter = compilerFilter.c_str();
    const char* volume_uuid = getCStr(uuid);
    const char* class_loader_context = getCStr(classLoaderContext);
@@ -2680,9 +2678,11 @@ binder::Status InstalldNativeService::restoreconAppData(const std::optional<std:
    return res;
}

binder::Status InstalldNativeService::createOatDir(const std::string& oatDir,
binder::Status InstalldNativeService::createOatDir(const std::string& packageName,
                                                   const std::string& oatDir,
                                                   const std::string& instructionSet) {
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_PACKAGE_NAME(packageName);
    CHECK_ARGUMENT_PATH(oatDir);
    std::lock_guard<std::recursive_mutex> lock(mLock);

@@ -2706,8 +2706,10 @@ binder::Status InstalldNativeService::createOatDir(const std::string& oatDir,
    return ok();
}

binder::Status InstalldNativeService::rmPackageDir(const std::string& packageDir) {
binder::Status InstalldNativeService::rmPackageDir(const std::string& packageName,
                                                   const std::string& packageDir) {
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_PACKAGE_NAME(packageName);
    CHECK_ARGUMENT_PATH(packageDir);
    std::lock_guard<std::recursive_mutex> lock(mLock);

@@ -2720,9 +2722,12 @@ binder::Status InstalldNativeService::rmPackageDir(const std::string& packageDir
    return ok();
}

binder::Status InstalldNativeService::linkFile(const std::string& relativePath,
        const std::string& fromBase, const std::string& toBase) {
binder::Status InstalldNativeService::linkFile(const std::string& packageName,
                                               const std::string& relativePath,
                                               const std::string& fromBase,
                                               const std::string& toBase) {
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_PACKAGE_NAME(packageName);
    CHECK_ARGUMENT_PATH(fromBase);
    CHECK_ARGUMENT_PATH(toBase);
    std::lock_guard<std::recursive_mutex> lock(mLock);
@@ -2750,9 +2755,12 @@ binder::Status InstalldNativeService::linkFile(const std::string& relativePath,
    return ok();
}

binder::Status InstalldNativeService::moveAb(const std::string& apkPath,
        const std::string& instructionSet, const std::string& outputPath) {
binder::Status InstalldNativeService::moveAb(const std::string& packageName,
                                             const std::string& apkPath,
                                             const std::string& instructionSet,
                                             const std::string& outputPath) {
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_PACKAGE_NAME(packageName);
    CHECK_ARGUMENT_PATH(apkPath);
    CHECK_ARGUMENT_PATH(outputPath);
    std::lock_guard<std::recursive_mutex> lock(mLock);
@@ -2765,10 +2773,13 @@ binder::Status InstalldNativeService::moveAb(const std::string& apkPath,
    return success ? ok() : error();
}

binder::Status InstalldNativeService::deleteOdex(const std::string& apkPath,
        const std::string& instructionSet, const std::optional<std::string>& outputPath,
binder::Status InstalldNativeService::deleteOdex(const std::string& packageName,
                                                 const std::string& apkPath,
                                                 const std::string& instructionSet,
                                                 const std::optional<std::string>& outputPath,
                                                 int64_t* _aidl_return) {
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_PACKAGE_NAME(packageName);
    CHECK_ARGUMENT_PATH(apkPath);
    CHECK_ARGUMENT_PATH(outputPath);
    std::lock_guard<std::recursive_mutex> lock(mLock);
@@ -2800,9 +2811,12 @@ struct fsverity_measurement {

#endif

binder::Status InstalldNativeService::installApkVerity(const std::string& filePath,
        android::base::unique_fd verityInputAshmem, int32_t contentSize) {
binder::Status InstalldNativeService::installApkVerity(const std::string& packageName,
                                                       const std::string& filePath,
                                                       android::base::unique_fd verityInputAshmem,
                                                       int32_t contentSize) {
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_PACKAGE_NAME(packageName);
    CHECK_ARGUMENT_PATH(filePath);
    std::lock_guard<std::recursive_mutex> lock(mLock);

@@ -2882,9 +2896,11 @@ binder::Status InstalldNativeService::installApkVerity(const std::string& filePa
    return ok();
}

binder::Status InstalldNativeService::assertFsverityRootHashMatches(const std::string& filePath,
binder::Status InstalldNativeService::assertFsverityRootHashMatches(
        const std::string& packageName, const std::string& filePath,
        const std::vector<uint8_t>& expectedHash) {
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_PACKAGE_NAME(packageName);
    CHECK_ARGUMENT_PATH(filePath);
    std::lock_guard<std::recursive_mutex> lock(mLock);

+24 −22
Original line number Diff line number Diff line
@@ -110,16 +110,15 @@ public:
            int32_t appId, const std::string& seInfo,
            int32_t targetSdkVersion, const std::string& fromCodePath);

    binder::Status dexopt(const std::string& apkPath, int32_t uid,
            const std::optional<std::string>& packageName, const std::string& instructionSet,
            int32_t dexoptNeeded, const std::optional<std::string>& outputPath, int32_t dexFlags,
    binder::Status dexopt(const std::string& apkPath, int32_t uid, const std::string& packageName,
                          const std::string& instructionSet, int32_t dexoptNeeded,
                          const std::optional<std::string>& outputPath, int32_t dexFlags,
                          const std::string& compilerFilter, const std::optional<std::string>& uuid,
                          const std::optional<std::string>& classLoaderContext,
                          const std::optional<std::string>& seInfo, bool downgrade,
                          int32_t targetSdkVersion, const std::optional<std::string>& profileName,
                          const std::optional<std::string>& dexMetadataPath,
            const std::optional<std::string>& compilationReason,
            bool* aidl_return);
                          const std::optional<std::string>& compilationReason, bool* aidl_return);

    binder::Status controlDexOptBlocking(bool block);

@@ -143,21 +142,24 @@ public:
    binder::Status destroyProfileSnapshot(const std::string& packageName,
            const std::string& profileName);

    binder::Status rmPackageDir(const std::string& packageDir);
    binder::Status rmPackageDir(const std::string& packageName, const std::string& packageDir);
    binder::Status freeCache(const std::optional<std::string>& uuid, int64_t targetFreeBytes,
            int32_t flags);
    binder::Status linkNativeLibraryDirectory(const std::optional<std::string>& uuid,
            const std::string& packageName, const std::string& nativeLibPath32, int32_t userId);
    binder::Status createOatDir(const std::string& oatDir, const std::string& instructionSet);
    binder::Status linkFile(const std::string& relativePath, const std::string& fromBase,
            const std::string& toBase);
    binder::Status moveAb(const std::string& apkPath, const std::string& instructionSet,
            const std::string& outputPath);
    binder::Status deleteOdex(const std::string& apkPath, const std::string& instructionSet,
    binder::Status createOatDir(const std::string& packageName, const std::string& oatDir,
                                const std::string& instructionSet);
    binder::Status linkFile(const std::string& packageName, const std::string& relativePath,
                            const std::string& fromBase, const std::string& toBase);
    binder::Status moveAb(const std::string& packageName, const std::string& apkPath,
                          const std::string& instructionSet, const std::string& outputPath);
    binder::Status deleteOdex(const std::string& packageName, const std::string& apkPath,
                              const std::string& instructionSet,
                              const std::optional<std::string>& outputPath, int64_t* _aidl_return);
    binder::Status installApkVerity(const std::string& filePath,
    binder::Status installApkVerity(const std::string& packageName, const std::string& filePath,
                                    android::base::unique_fd verityInput, int32_t contentSize);
    binder::Status assertFsverityRootHashMatches(const std::string& filePath,
    binder::Status assertFsverityRootHashMatches(const std::string& packageName,
                                                 const std::string& filePath,
                                                 const std::vector<uint8_t>& expectedHash);
    binder::Status reconcileSecondaryDexFile(const std::string& dexPath,
        const std::string& packageName, int32_t uid, const std::vector<std::string>& isa,
+14 −12
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ interface IInstalld {
            @utf8InCpp String seInfo, int targetSdkVersion, @utf8InCpp String fromCodePath);

    // Returns false if it is cancelled. Returns true if it is completed or have other errors.
    boolean dexopt(@utf8InCpp String apkPath, int uid, @nullable @utf8InCpp String packageName,
    boolean dexopt(@utf8InCpp String apkPath, int uid, @utf8InCpp String packageName,
            @utf8InCpp String instructionSet, int dexoptNeeded,
            @nullable @utf8InCpp String outputPath, int dexFlags,
            @utf8InCpp String compilerFilter, @nullable @utf8InCpp String uuid,
@@ -85,20 +85,22 @@ interface IInstalld {
            @utf8InCpp String profileName, @utf8InCpp String classpath);
    void destroyProfileSnapshot(@utf8InCpp String packageName, @utf8InCpp String profileName);

    void rmPackageDir(@utf8InCpp String packageDir);
    void rmPackageDir(@utf8InCpp String packageName, @utf8InCpp String packageDir);
    void freeCache(@nullable @utf8InCpp String uuid, long targetFreeBytes, int flags);
    void linkNativeLibraryDirectory(@nullable @utf8InCpp String uuid,
            @utf8InCpp String packageName, @utf8InCpp String nativeLibPath32, int userId);
    void createOatDir(@utf8InCpp String oatDir, @utf8InCpp String instructionSet);
    void linkFile(@utf8InCpp String relativePath, @utf8InCpp String fromBase,
            @utf8InCpp String toBase);
    void moveAb(@utf8InCpp String apkPath, @utf8InCpp String instructionSet,
            @utf8InCpp String outputPath);
    long deleteOdex(@utf8InCpp String apkPath, @utf8InCpp String instructionSet,
            @nullable @utf8InCpp String outputPath);
    void installApkVerity(@utf8InCpp String filePath, in FileDescriptor verityInput,
            int contentSize);
    void assertFsverityRootHashMatches(@utf8InCpp String filePath, in byte[] expectedHash);
    void createOatDir(@utf8InCpp String packageName, @utf8InCpp String oatDir,
            @utf8InCpp String instructionSet);
    void linkFile(@utf8InCpp String packageName, @utf8InCpp String relativePath,
            @utf8InCpp String fromBase, @utf8InCpp String toBase);
    void moveAb(@utf8InCpp String packageName, @utf8InCpp String apkPath,
            @utf8InCpp String instructionSet, @utf8InCpp String outputPath);
    long deleteOdex(@utf8InCpp String packageName, @utf8InCpp String apkPath,
            @utf8InCpp String instructionSet, @nullable @utf8InCpp String outputPath);
    void installApkVerity(@utf8InCpp String packageName, @utf8InCpp String filePath,
            in FileDescriptor verityInput, int contentSize);
    void assertFsverityRootHashMatches(@utf8InCpp String packageName, @utf8InCpp String filePath,
            in byte[] expectedHash);

    boolean reconcileSecondaryDexFile(@utf8InCpp String dexPath, @utf8InCpp String pkgName,
        int uid, in @utf8InCpp String[] isas, @nullable @utf8InCpp String volume_uuid,
+2 −1
Original line number Diff line number Diff line
@@ -635,6 +635,7 @@ protected:

        int64_t bytes_freed;
        binder::Status result = service_->deleteOdex(
            package_name_,
            apk_path_,
            kRuntimeIsa,
            in_dalvik_cache ? std::nullopt : std::make_optional<std::string>(app_oat_dir_.c_str()),
@@ -729,7 +730,7 @@ TEST_F(DexoptTest, DexoptPrimaryPublic) {

TEST_F(DexoptTest, DexoptPrimaryPublicCreateOatDir) {
    LOG(INFO) << "DexoptPrimaryPublic";
    ASSERT_BINDER_SUCCESS(service_->createOatDir(app_oat_dir_, kRuntimeIsa));
    ASSERT_BINDER_SUCCESS(service_->createOatDir(package_name_, app_oat_dir_, kRuntimeIsa));
    CompilePrimaryDexOk("verify",
                        DEXOPT_BOOTCOMPLETE | DEXOPT_PUBLIC,
                        app_oat_dir_.c_str(),