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

Commit 1cfb5b22 authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi Committed by Automerger Merge Worker
Browse files

Merge changes I227d8e0c,Ided4415a into rvc-dev am: f3d4495d

Change-Id: I690256bb6ee189803ed47beb0630218eb3fb0ff7
parents 0e87d5eb f3d4495d
Loading
Loading
Loading
Loading
+40 −52
Original line number Diff line number Diff line
@@ -32,8 +32,12 @@ import java.io.File;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;

/**
 * Provides operations to open or create an IncrementalStorage, using IIncrementalService
@@ -175,25 +179,6 @@ public final class IncrementalManager {
        }
    }

    /**
     * Iterates through path parents to find the base dir of an Incremental Storage.
     *
     * @param file Target file to search storage for.
     * @return Absolute path which is a bind-mount point of Incremental File System.
     */
    @Nullable
    private Path getStoragePathForFile(File file) {
        File currentPath = new File(file.getParent());
        while (currentPath.getParent() != null) {
            IncrementalStorage storage = openStorage(currentPath.getAbsolutePath());
            if (storage != null) {
                return currentPath.toPath();
            }
            currentPath = new File(currentPath.getParent());
        }
        return null;
    }

    /**
     * Set up an app's code path. The expected outcome of this method is:
     * 1) The actual apk directory under /data/incremental is bind-mounted to the parent directory
@@ -212,29 +197,27 @@ public final class IncrementalManager {
     */
    public void renameCodePath(File beforeCodeFile, File afterCodeFile)
            throws IllegalArgumentException, IOException {
        final String beforeCodePath = beforeCodeFile.getAbsolutePath();
        final String afterCodePathParent = afterCodeFile.getParentFile().getAbsolutePath();
        if (!isIncrementalPath(beforeCodePath)) {
            throw new IllegalArgumentException("Not an Incremental path: " + beforeCodePath);
        }
        final String afterCodePathName = afterCodeFile.getName();
        final Path apkStoragePath = Paths.get(beforeCodePath);
        if (apkStoragePath == null || apkStoragePath.toAbsolutePath() == null) {
            throw new IOException("Invalid source storage path for: " + beforeCodePath);
        }
        final IncrementalStorage apkStorage =
                openStorage(apkStoragePath.toAbsolutePath().toString());
        final File beforeCodeAbsolute = beforeCodeFile.getAbsoluteFile();
        final IncrementalStorage apkStorage = openStorage(beforeCodeAbsolute.toString());
        if (apkStorage == null) {
            throw new IOException("Failed to retrieve storage from Incremental Service.");
            throw new IllegalArgumentException("Not an Incremental path: " + beforeCodeAbsolute);
        }
        final IncrementalStorage linkedApkStorage = createStorage(afterCodePathParent, apkStorage,
        final String targetStorageDir = afterCodeFile.getAbsoluteFile().getParent();
        final IncrementalStorage linkedApkStorage =
                createStorage(targetStorageDir, apkStorage,
                        IncrementalManager.CREATE_MODE_CREATE
                                | IncrementalManager.CREATE_MODE_PERMANENT_BIND);
        if (linkedApkStorage == null) {
            throw new IOException("Failed to create linked storage at dir: " + afterCodePathParent);
            throw new IOException("Failed to create linked storage at dir: " + targetStorageDir);
        }
        try {
            final String afterCodePathName = afterCodeFile.getName();
            linkFiles(apkStorage, beforeCodeAbsolute, "", linkedApkStorage, afterCodePathName);
            apkStorage.unBind(beforeCodeAbsolute.toString());
        } catch (Exception e) {
            linkedApkStorage.unBind(targetStorageDir);
            throw e;
        }
        linkFiles(apkStorage, beforeCodeFile, "", linkedApkStorage, afterCodePathName);
        apkStorage.unBind(beforeCodePath);
    }

    /**
@@ -252,22 +235,27 @@ public final class IncrementalManager {
    private void linkFiles(IncrementalStorage sourceStorage, File sourceAbsolutePath,
            String sourceRelativePath, IncrementalStorage targetStorage,
            String targetRelativePath) throws IOException {
        targetStorage.makeDirectory(targetRelativePath);
        final File[] entryList = sourceAbsolutePath.listFiles();
        for (int i = 0; i < entryList.length; i++) {
            final File entry = entryList[i];
            final String entryName = entryList[i].getName();
            final String sourceEntryRelativePath =
                    sourceRelativePath.isEmpty() ? entryName : sourceRelativePath + "/" + entryName;
            final String targetEntryRelativePath = targetRelativePath + "/" + entryName;
            if (entry.isFile()) {
                sourceStorage.makeLink(
                        sourceEntryRelativePath, targetStorage, targetEntryRelativePath);
            } else if (entry.isDirectory()) {
                linkFiles(sourceStorage, entry, sourceEntryRelativePath, targetStorage,
                        targetEntryRelativePath);
        final Path sourceBase = sourceAbsolutePath.toPath().resolve(sourceRelativePath);
        final Path targetRelative = Paths.get(targetRelativePath);
        Files.walkFileTree(sourceAbsolutePath.toPath(), new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                    throws IOException {
                final Path relativeDir = sourceBase.relativize(dir);
                targetStorage.makeDirectory(targetRelative.resolve(relativeDir).toString());
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                    throws IOException {
                final Path relativeFile = sourceBase.relativize(file);
                sourceStorage.makeLink(
                        file.toAbsolutePath().toString(), targetStorage,
                        targetRelative.resolve(relativeFile).toString());
                return FileVisitResult.CONTINUE;
            }
        });
    }

    /**
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ filegroup {
    srcs: [
        "incremental_service.c",
        "IncrementalService.cpp",
        "IncrementalServiceValidation.cpp",
        "BinderIncrementalService.cpp",
        "path.cpp",
        "ServiceWrappers.cpp",
+6 −7
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <android-base/logging.h>
#include <android-base/no_destructor.h>
#include <android/os/IVold.h>
#include <binder/IResultReceiver.h>
#include <binder/PermissionCache.h>
#include <incfs.h>
@@ -117,11 +118,12 @@ binder::Status BinderIncrementalService::openStorage(const std::string& path,
}

binder::Status BinderIncrementalService::createStorage(
        const std::string& path, const DataLoaderParamsParcel& params,
        const std::string& path, const content::pm::DataLoaderParamsParcel& params,
        const ::android::sp<::android::content::pm::IDataLoaderStatusListener>& listener,
        int32_t createMode, int32_t* _aidl_return) {
    *_aidl_return =
            mImpl.createStorage(path, const_cast<DataLoaderParamsParcel&&>(params), listener,
            mImpl.createStorage(path, const_cast<content::pm::DataLoaderParamsParcel&&>(params),
                                listener,
                                android::incremental::IncrementalService::CreateOptions(
                                        createMode));
    return ok();
@@ -238,11 +240,8 @@ binder::Status BinderIncrementalService::isFileRangeLoaded(int32_t storageId,
binder::Status BinderIncrementalService::getMetadataByPath(int32_t storageId,
                                                           const std::string& path,
                                                           std::vector<uint8_t>* _aidl_return) {
    auto fid = mImpl.nodeFor(storageId, path);
    if (fid != kIncFsInvalidFileId) {
        auto metadata = mImpl.getMetadata(storageId, fid);
    auto metadata = mImpl.getMetadata(storageId, path);
    _aidl_return->assign(metadata.begin(), metadata.end());
    }
    return ok();
}

+428 −214

File changed.

Preview size limit exceeded, changes collapsed.

+34 −35
Original line number Diff line number Diff line
@@ -16,13 +16,13 @@

#pragma once

#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <android/content/pm/BnDataLoaderStatusListener.h>
#include <android/content/pm/DataLoaderParamsParcel.h>
#include <binder/IServiceManager.h>
#include <android/content/pm/IDataLoaderStatusListener.h>
#include <android/os/incremental/BnIncrementalServiceConnector.h>
#include <binder/IAppOpsCallback.h>
#include <utils/String16.h>
#include <utils/StrongPointer.h>
#include <utils/Vector.h>
#include <ziparchive/zip_archive.h>

#include <atomic>
@@ -37,21 +37,14 @@
#include <string_view>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#include "ServiceWrappers.h"
#include "android/content/pm/BnDataLoaderStatusListener.h"
#include "android/os/incremental/BnIncrementalServiceConnector.h"
#include "incfs.h"
#include "path.h"

using namespace android::os::incremental;

namespace android::os {
class IVold;
}

namespace android::incremental {

using MountId = int;
@@ -101,17 +94,14 @@ public:

    void onSystemReady();

    StorageId createStorage(std::string_view mountPoint, DataLoaderParamsParcel&& dataLoaderParams,
    StorageId createStorage(std::string_view mountPoint,
                            content::pm::DataLoaderParamsParcel&& dataLoaderParams,
                            const DataLoaderStatusListener& dataLoaderStatusListener,
                            CreateOptions options = CreateOptions::Default);
    StorageId createLinkedStorage(std::string_view mountPoint, StorageId linkedStorage,
                                  CreateOptions options = CreateOptions::Default);
    StorageId openStorage(std::string_view path);

    FileId nodeFor(StorageId storage, std::string_view path) const;
    std::pair<FileId, std::string_view> parentAndNameFor(StorageId storage,
                                                         std::string_view path) const;

    int bind(StorageId storage, std::string_view source, std::string_view target, BindKind kind);
    int unbind(StorageId storage, std::string_view target);
    void deleteStorage(StorageId storage);
@@ -131,9 +121,9 @@ public:
        return false;
    }

    RawMetadata getMetadata(StorageId storage, std::string_view path) const;
    RawMetadata getMetadata(StorageId storage, FileId node) const;

    std::vector<std::string> listFiles(StorageId storage) const;
    bool startLoading(StorageId storage) const;

    bool configureNativeBinaries(StorageId storage, std::string_view apkFullPath,
@@ -151,7 +141,7 @@ public:
        const std::string packageName;
    };

    class IncrementalServiceConnector : public BnIncrementalServiceConnector {
    class IncrementalServiceConnector : public os::incremental::BnIncrementalServiceConnector {
    public:
        IncrementalServiceConnector(IncrementalService& incrementalService, int32_t storage)
              : incrementalService(incrementalService), storage(storage) {}
@@ -163,14 +153,13 @@ public:
    };

private:
    static const bool sEnablePerfLogging;

    struct IncFsMount;

    class DataLoaderStub : public android::content::pm::BnDataLoaderStatusListener {
    class DataLoaderStub : public content::pm::BnDataLoaderStatusListener {
    public:
        DataLoaderStub(IncrementalService& service, MountId id, DataLoaderParamsParcel&& params,
                       FileSystemControlParcel&& control,
        DataLoaderStub(IncrementalService& service, MountId id,
                       content::pm::DataLoaderParamsParcel&& params,
                       content::pm::FileSystemControlParcel&& control,
                       const DataLoaderStatusListener* externalListener);
        ~DataLoaderStub();
        // Cleans up the internal state and invalidates DataLoaderStub. Any subsequent calls will
@@ -184,7 +173,7 @@ private:
        void onDump(int fd);

        MountId id() const { return mId; }
        const DataLoaderParamsParcel& params() const { return mParams; }
        const content::pm::DataLoaderParamsParcel& params() const { return mParams; }

    private:
        binder::Status onStatusChanged(MountId mount, int newStatus) final;
@@ -202,14 +191,14 @@ private:

        IncrementalService& mService;
        MountId mId = kInvalidStorageId;
        DataLoaderParamsParcel mParams;
        FileSystemControlParcel mControl;
        content::pm::DataLoaderParamsParcel mParams;
        content::pm::FileSystemControlParcel mControl;
        DataLoaderStatusListener mListener;

        std::mutex mStatusMutex;
        std::condition_variable mStatusCondition;
        int mCurrentStatus = IDataLoaderStatusListener::DATA_LOADER_DESTROYED;
        int mTargetStatus = IDataLoaderStatusListener::DATA_LOADER_DESTROYED;
        int mCurrentStatus = content::pm::IDataLoaderStatusListener::DATA_LOADER_DESTROYED;
        int mTargetStatus = content::pm::IDataLoaderStatusListener::DATA_LOADER_DESTROYED;
        TimePoint mTargetStatusTs = {};
    };
    using DataLoaderStubPtr = sp<DataLoaderStub>;
@@ -228,7 +217,7 @@ private:

        using Control = incfs::UniqueControl;

        using BindMap = std::map<std::string, Bind>;
        using BindMap = std::map<std::string, Bind, path::PathLess>;
        using StorageMap = std::unordered_map<StorageId, Storage>;

        mutable std::mutex lock;
@@ -260,7 +249,10 @@ private:
    using MountMap = std::unordered_map<MountId, IfsMountPtr>;
    using BindPathMap = std::map<std::string, IncFsMount::BindMap::iterator, path::PathLess>;

    void mountExistingImages();
    static bool perfLoggingEnabled();

    std::unordered_set<std::string_view> adoptMountedInstances();
    void mountExistingImages(const std::unordered_set<std::string_view>& mountedRootNames);
    bool mountExistingImage(std::string_view root);

    IfsMountPtr getIfs(StorageId storage) const;
@@ -273,7 +265,13 @@ private:
                           std::string&& source, std::string&& target, BindKind kind,
                           std::unique_lock<std::mutex>& mainLock);

    DataLoaderStubPtr prepareDataLoader(IncFsMount& ifs, DataLoaderParamsParcel&& params,
    void addBindMountRecordLocked(IncFsMount& ifs, StorageId storage, std::string&& metadataName,
                                  std::string&& source, std::string&& target, BindKind kind);

    DataLoaderStubPtr prepareDataLoader(IncFsMount& ifs,
                                        content::pm::DataLoaderParamsParcel&& params,
                                        const DataLoaderStatusListener* externalListener = nullptr);
    void prepareDataLoaderLocked(IncFsMount& ifs, content::pm::DataLoaderParamsParcel&& params,
                                 const DataLoaderStatusListener* externalListener = nullptr);

    BindPathMap::const_iterator findStorageLocked(std::string_view path) const;
@@ -283,9 +281,10 @@ private:
    void deleteStorageLocked(IncFsMount& ifs, std::unique_lock<std::mutex>&& ifsLock);
    MountMap::iterator getStorageSlotLocked();
    std::string normalizePathToStorage(const IfsMountPtr& incfs, StorageId storage,
                                       std::string_view path);
    std::string normalizePathToStorageLocked(IncFsMount::StorageMap::iterator storageIt,
                                             std::string_view path);
                                       std::string_view path) const;
    std::string normalizePathToStorageLocked(const IfsMountPtr& incfs,
                                             IncFsMount::StorageMap::iterator storageIt,
                                             std::string_view path) const;

    binder::Status applyStorageParams(IncFsMount& ifs, bool enableReadLogs);

Loading