2019-11-29 14:23:45 -08:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-02-19 00:08:36 -08:00
|
|
|
#include <android-base/function_ref.h>
|
2019-11-29 14:23:45 -08:00
|
|
|
#include <android-base/unique_fd.h>
|
|
|
|
#include <android/content/pm/DataLoaderParamsParcel.h>
|
|
|
|
#include <android/content/pm/FileSystemControlParcel.h>
|
2020-02-27 15:57:35 -08:00
|
|
|
#include <android/content/pm/IDataLoader.h>
|
2019-11-29 14:23:45 -08:00
|
|
|
#include <android/content/pm/IDataLoaderStatusListener.h>
|
2020-12-14 21:50:04 -08:00
|
|
|
#include <android/os/incremental/PerUidReadTimeouts.h>
|
2020-04-17 23:13:47 -07:00
|
|
|
#include <binder/IAppOpsCallback.h>
|
2019-11-29 14:23:45 -08:00
|
|
|
#include <binder/IServiceManager.h>
|
2020-04-17 23:13:47 -07:00
|
|
|
#include <binder/Status.h>
|
2019-11-29 14:23:45 -08:00
|
|
|
#include <incfs.h>
|
2020-04-09 19:22:30 -07:00
|
|
|
#include <jni.h>
|
2020-05-05 12:48:41 -07:00
|
|
|
#include <utils/Looper.h>
|
2019-11-29 14:23:45 -08:00
|
|
|
|
2020-01-10 11:53:24 -08:00
|
|
|
#include <memory>
|
2020-04-17 23:13:47 -07:00
|
|
|
#include <span>
|
2019-11-29 14:23:45 -08:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
|
2020-04-17 23:13:47 -07:00
|
|
|
namespace android::incremental {
|
2019-11-29 14:23:45 -08:00
|
|
|
|
2020-05-29 12:05:05 -07:00
|
|
|
using Clock = std::chrono::steady_clock;
|
|
|
|
using TimePoint = std::chrono::time_point<Clock>;
|
|
|
|
using Milliseconds = std::chrono::milliseconds;
|
|
|
|
using Job = std::function<void()>;
|
|
|
|
|
2019-11-29 14:23:45 -08:00
|
|
|
// --- Wrapper interfaces ---
|
|
|
|
|
2020-01-10 11:53:24 -08:00
|
|
|
using MountId = int32_t;
|
|
|
|
|
2019-11-29 14:23:45 -08:00
|
|
|
class VoldServiceWrapper {
|
|
|
|
public:
|
2020-01-10 11:53:24 -08:00
|
|
|
virtual ~VoldServiceWrapper() = default;
|
2020-04-17 23:13:47 -07:00
|
|
|
virtual binder::Status mountIncFs(
|
|
|
|
const std::string& backingPath, const std::string& targetDir, int32_t flags,
|
2021-04-27 11:26:25 -07:00
|
|
|
const std::string& sysfsName,
|
2020-04-17 23:13:47 -07:00
|
|
|
os::incremental::IncrementalFileSystemControlParcel* result) const = 0;
|
2019-11-29 14:23:45 -08:00
|
|
|
virtual binder::Status unmountIncFs(const std::string& dir) const = 0;
|
|
|
|
virtual binder::Status bindMount(const std::string& sourceDir,
|
|
|
|
const std::string& targetDir) const = 0;
|
2020-04-17 23:13:47 -07:00
|
|
|
virtual binder::Status setIncFsMountOptions(
|
2021-03-31 22:19:42 -07:00
|
|
|
const os::incremental::IncrementalFileSystemControlParcel& control, bool enableReadLogs,
|
2021-05-10 16:17:30 -07:00
|
|
|
bool enableReadTimeouts, const std::string& sysfsName) const = 0;
|
2019-11-29 14:23:45 -08:00
|
|
|
};
|
|
|
|
|
2020-02-27 15:57:35 -08:00
|
|
|
class DataLoaderManagerWrapper {
|
2019-11-29 14:23:45 -08:00
|
|
|
public:
|
2020-02-27 15:57:35 -08:00
|
|
|
virtual ~DataLoaderManagerWrapper() = default;
|
2020-04-22 16:08:50 -07:00
|
|
|
virtual binder::Status bindToDataLoader(
|
2021-02-06 20:31:43 -08:00
|
|
|
MountId mountId, const content::pm::DataLoaderParamsParcel& params, int bindDelayMs,
|
2020-04-17 23:13:47 -07:00
|
|
|
const sp<content::pm::IDataLoaderStatusListener>& listener, bool* result) const = 0;
|
|
|
|
virtual binder::Status getDataLoader(MountId mountId,
|
|
|
|
sp<content::pm::IDataLoader>* result) const = 0;
|
2020-04-22 16:08:50 -07:00
|
|
|
virtual binder::Status unbindFromDataLoader(MountId mountId) const = 0;
|
2019-11-29 14:23:45 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
class IncFsWrapper {
|
|
|
|
public:
|
2020-04-17 23:13:47 -07:00
|
|
|
using Control = incfs::Control;
|
|
|
|
using FileId = incfs::FileId;
|
|
|
|
using ErrorCode = incfs::ErrorCode;
|
2020-08-25 12:45:22 -07:00
|
|
|
using UniqueFd = incfs::UniqueFd;
|
2020-05-08 16:18:52 -07:00
|
|
|
using WaitResult = incfs::WaitResult;
|
2021-02-17 14:24:14 -08:00
|
|
|
using Features = incfs::Features;
|
2021-04-27 11:26:25 -07:00
|
|
|
using Metrics = incfs::Metrics;
|
2021-04-30 09:50:58 -07:00
|
|
|
using LastReadError = incfs::LastReadError;
|
2020-04-17 23:13:47 -07:00
|
|
|
|
2021-02-19 00:08:36 -08:00
|
|
|
using ExistingMountCallback = android::base::function_ref<
|
|
|
|
void(std::string_view root, std::string_view backingDir,
|
|
|
|
std::span<std::pair<std::string_view, std::string_view>> binds)>;
|
2020-04-17 23:13:47 -07:00
|
|
|
|
2021-03-24 00:46:29 -07:00
|
|
|
using FileCallback = android::base::function_ref<bool(const Control& control, FileId fileId)>;
|
|
|
|
|
2021-03-18 16:59:47 -07:00
|
|
|
static std::string toString(FileId fileId);
|
|
|
|
|
2020-01-10 11:53:24 -08:00
|
|
|
virtual ~IncFsWrapper() = default;
|
2021-02-17 14:24:14 -08:00
|
|
|
virtual Features features() const = 0;
|
2020-04-17 23:13:47 -07:00
|
|
|
virtual void listExistingMounts(const ExistingMountCallback& cb) const = 0;
|
|
|
|
virtual Control openMount(std::string_view path) const = 0;
|
2020-12-08 07:35:24 -08:00
|
|
|
virtual Control createControl(IncFsFd cmd, IncFsFd pendingReads, IncFsFd logs,
|
|
|
|
IncFsFd blocksWritten) const = 0;
|
2020-03-03 09:47:15 -08:00
|
|
|
virtual ErrorCode makeFile(const Control& control, std::string_view path, int mode, FileId id,
|
2020-04-17 23:13:47 -07:00
|
|
|
incfs::NewFileParams params) const = 0;
|
2021-02-17 14:24:14 -08:00
|
|
|
virtual ErrorCode makeMappedFile(const Control& control, std::string_view path, int mode,
|
|
|
|
incfs::NewMappedFileParams params) const = 0;
|
2020-03-03 09:47:15 -08:00
|
|
|
virtual ErrorCode makeDir(const Control& control, std::string_view path, int mode) const = 0;
|
2020-04-22 13:59:06 -07:00
|
|
|
virtual ErrorCode makeDirs(const Control& control, std::string_view path, int mode) const = 0;
|
2020-04-17 23:13:47 -07:00
|
|
|
virtual incfs::RawMetadata getMetadata(const Control& control, FileId fileid) const = 0;
|
|
|
|
virtual incfs::RawMetadata getMetadata(const Control& control, std::string_view path) const = 0;
|
2020-03-03 09:47:15 -08:00
|
|
|
virtual FileId getFileId(const Control& control, std::string_view path) const = 0;
|
2020-08-20 08:40:29 -07:00
|
|
|
virtual std::pair<IncFsBlockIndex, IncFsBlockIndex> countFilledBlocks(
|
|
|
|
const Control& control, std::string_view path) const = 0;
|
2021-03-18 14:21:54 -07:00
|
|
|
virtual incfs::LoadingState isFileFullyLoaded(const Control& control,
|
|
|
|
std::string_view path) const = 0;
|
2021-03-24 00:46:29 -07:00
|
|
|
virtual incfs::LoadingState isFileFullyLoaded(const Control& control, FileId id) const = 0;
|
2021-03-18 14:21:54 -07:00
|
|
|
virtual incfs::LoadingState isEverythingFullyLoaded(const Control& control) const = 0;
|
2020-03-03 09:47:15 -08:00
|
|
|
virtual ErrorCode link(const Control& control, std::string_view from,
|
|
|
|
std::string_view to) const = 0;
|
|
|
|
virtual ErrorCode unlink(const Control& control, std::string_view path) const = 0;
|
2020-08-25 12:45:22 -07:00
|
|
|
virtual UniqueFd openForSpecialOps(const Control& control, FileId id) const = 0;
|
2020-04-17 23:13:47 -07:00
|
|
|
virtual ErrorCode writeBlocks(std::span<const incfs::DataBlock> blocks) const = 0;
|
2021-03-24 00:46:29 -07:00
|
|
|
virtual ErrorCode reserveSpace(const Control& control, FileId id, IncFsSize size) const = 0;
|
2020-05-08 16:18:52 -07:00
|
|
|
virtual WaitResult waitForPendingReads(
|
|
|
|
const Control& control, std::chrono::milliseconds timeout,
|
2021-03-31 22:19:42 -07:00
|
|
|
std::vector<incfs::ReadInfoWithUid>* pendingReadsBuffer) const = 0;
|
2020-12-14 21:50:04 -08:00
|
|
|
virtual ErrorCode setUidReadTimeouts(
|
|
|
|
const Control& control,
|
|
|
|
const std::vector<::android::os::incremental::PerUidReadTimeouts>& perUidReadTimeouts)
|
|
|
|
const = 0;
|
2021-03-24 00:46:29 -07:00
|
|
|
virtual ErrorCode forEachFile(const Control& control, FileCallback cb) const = 0;
|
|
|
|
virtual ErrorCode forEachIncompleteFile(const Control& control, FileCallback cb) const = 0;
|
2021-04-27 11:26:25 -07:00
|
|
|
virtual std::optional<Metrics> getMetrics(std::string_view sysfsName) const = 0;
|
2021-04-30 09:50:58 -07:00
|
|
|
virtual std::optional<LastReadError> getLastReadError(const Control& control) const = 0;
|
2019-11-29 14:23:45 -08:00
|
|
|
};
|
|
|
|
|
2020-04-02 20:03:47 -07:00
|
|
|
class AppOpsManagerWrapper {
|
|
|
|
public:
|
|
|
|
virtual ~AppOpsManagerWrapper() = default;
|
2020-04-03 23:00:19 -07:00
|
|
|
virtual binder::Status checkPermission(const char* permission, const char* operation,
|
|
|
|
const char* package) const = 0;
|
2020-08-20 08:40:29 -07:00
|
|
|
virtual void startWatchingMode(int32_t op, const String16& packageName,
|
|
|
|
const sp<IAppOpsCallback>& callback) = 0;
|
2020-04-03 23:00:19 -07:00
|
|
|
virtual void stopWatchingMode(const sp<IAppOpsCallback>& callback) = 0;
|
2020-04-02 20:03:47 -07:00
|
|
|
};
|
|
|
|
|
2020-04-09 19:22:30 -07:00
|
|
|
class JniWrapper {
|
|
|
|
public:
|
|
|
|
virtual ~JniWrapper() = default;
|
|
|
|
virtual void initializeForCurrentThread() const = 0;
|
|
|
|
};
|
|
|
|
|
2020-05-05 12:48:41 -07:00
|
|
|
class LooperWrapper {
|
|
|
|
public:
|
|
|
|
virtual ~LooperWrapper() = default;
|
|
|
|
virtual int addFd(int fd, int ident, int events, android::Looper_callbackFunc callback,
|
|
|
|
void* data) = 0;
|
|
|
|
virtual int removeFd(int fd) = 0;
|
|
|
|
virtual void wake() = 0;
|
|
|
|
virtual int pollAll(int timeoutMillis) = 0;
|
|
|
|
};
|
|
|
|
|
2020-05-29 12:05:05 -07:00
|
|
|
class TimedQueueWrapper {
|
|
|
|
public:
|
|
|
|
virtual ~TimedQueueWrapper() = default;
|
|
|
|
virtual void addJob(MountId id, Milliseconds after, Job what) = 0;
|
|
|
|
virtual void removeJobs(MountId id) = 0;
|
|
|
|
virtual void stop() = 0;
|
|
|
|
};
|
|
|
|
|
2020-08-20 08:40:29 -07:00
|
|
|
class FsWrapper {
|
|
|
|
public:
|
|
|
|
virtual ~FsWrapper() = default;
|
2021-02-19 00:08:36 -08:00
|
|
|
|
|
|
|
using FileCallback = android::base::function_ref<bool(std::string_view)>;
|
|
|
|
virtual void listFilesRecursive(std::string_view directoryPath, FileCallback onFile) const = 0;
|
2020-08-20 08:40:29 -07:00
|
|
|
};
|
|
|
|
|
2021-03-09 19:24:23 -08:00
|
|
|
class ClockWrapper {
|
|
|
|
public:
|
|
|
|
virtual ~ClockWrapper() = default;
|
|
|
|
virtual TimePoint now() const = 0;
|
|
|
|
};
|
|
|
|
|
2019-11-29 14:23:45 -08:00
|
|
|
class ServiceManagerWrapper {
|
|
|
|
public:
|
2020-01-10 11:53:24 -08:00
|
|
|
virtual ~ServiceManagerWrapper() = default;
|
|
|
|
virtual std::unique_ptr<VoldServiceWrapper> getVoldService() = 0;
|
2020-02-27 15:57:35 -08:00
|
|
|
virtual std::unique_ptr<DataLoaderManagerWrapper> getDataLoaderManager() = 0;
|
2020-01-10 11:53:24 -08:00
|
|
|
virtual std::unique_ptr<IncFsWrapper> getIncFs() = 0;
|
2020-04-02 20:03:47 -07:00
|
|
|
virtual std::unique_ptr<AppOpsManagerWrapper> getAppOpsManager() = 0;
|
2020-04-09 19:22:30 -07:00
|
|
|
virtual std::unique_ptr<JniWrapper> getJni() = 0;
|
2020-05-05 12:48:41 -07:00
|
|
|
virtual std::unique_ptr<LooperWrapper> getLooper() = 0;
|
2020-05-29 12:05:05 -07:00
|
|
|
virtual std::unique_ptr<TimedQueueWrapper> getTimedQueue() = 0;
|
2020-09-03 11:45:53 -07:00
|
|
|
virtual std::unique_ptr<TimedQueueWrapper> getProgressUpdateJobQueue() = 0;
|
2020-08-20 08:40:29 -07:00
|
|
|
virtual std::unique_ptr<FsWrapper> getFs() = 0;
|
2021-03-09 19:24:23 -08:00
|
|
|
virtual std::unique_ptr<ClockWrapper> getClock() = 0;
|
2019-11-29 14:23:45 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// --- Real stuff ---
|
|
|
|
|
|
|
|
class RealServiceManager : public ServiceManagerWrapper {
|
|
|
|
public:
|
2020-04-09 19:22:30 -07:00
|
|
|
RealServiceManager(sp<IServiceManager> serviceManager, JNIEnv* env);
|
2019-11-29 14:23:45 -08:00
|
|
|
~RealServiceManager() = default;
|
2020-04-02 20:03:47 -07:00
|
|
|
std::unique_ptr<VoldServiceWrapper> getVoldService() final;
|
|
|
|
std::unique_ptr<DataLoaderManagerWrapper> getDataLoaderManager() final;
|
|
|
|
std::unique_ptr<IncFsWrapper> getIncFs() final;
|
|
|
|
std::unique_ptr<AppOpsManagerWrapper> getAppOpsManager() final;
|
2020-04-09 19:22:30 -07:00
|
|
|
std::unique_ptr<JniWrapper> getJni() final;
|
2020-05-05 12:48:41 -07:00
|
|
|
std::unique_ptr<LooperWrapper> getLooper() final;
|
2020-05-29 12:05:05 -07:00
|
|
|
std::unique_ptr<TimedQueueWrapper> getTimedQueue() final;
|
2020-09-03 11:45:53 -07:00
|
|
|
std::unique_ptr<TimedQueueWrapper> getProgressUpdateJobQueue() final;
|
2020-08-20 08:40:29 -07:00
|
|
|
std::unique_ptr<FsWrapper> getFs() final;
|
2021-03-09 19:24:23 -08:00
|
|
|
std::unique_ptr<ClockWrapper> getClock() final;
|
2019-11-29 14:23:45 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
template <class INTERFACE>
|
|
|
|
sp<INTERFACE> getRealService(std::string_view serviceName) const;
|
|
|
|
sp<android::IServiceManager> mServiceManager;
|
2020-04-09 19:22:30 -07:00
|
|
|
JavaVM* const mJvm;
|
2019-11-29 14:23:45 -08:00
|
|
|
};
|
|
|
|
|
2020-04-17 23:13:47 -07:00
|
|
|
} // namespace android::incremental
|