Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 19 | #include "IncrementalServiceValidation.h" |
| 20 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 21 | #include <android-base/strings.h> |
| 22 | #include <android-base/unique_fd.h> |
| 23 | #include <android/content/pm/DataLoaderParamsParcel.h> |
| 24 | #include <android/content/pm/FileSystemControlParcel.h> |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 25 | #include <android/content/pm/IDataLoader.h> |
| 26 | #include <android/content/pm/IDataLoaderManager.h> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 27 | #include <android/content/pm/IDataLoaderStatusListener.h> |
| 28 | #include <android/os/IVold.h> |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 29 | #include <binder/AppOpsManager.h> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 30 | #include <binder/IServiceManager.h> |
| 31 | #include <incfs.h> |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame^] | 32 | #include <jni.h> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 33 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 34 | #include <memory> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 35 | #include <string> |
| 36 | #include <string_view> |
| 37 | |
| 38 | using namespace android::incfs; |
| 39 | using namespace android::content::pm; |
| 40 | |
| 41 | namespace android::os::incremental { |
| 42 | |
| 43 | // --- Wrapper interfaces --- |
| 44 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 45 | using MountId = int32_t; |
| 46 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 47 | class VoldServiceWrapper { |
| 48 | public: |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 49 | virtual ~VoldServiceWrapper() = default; |
| 50 | virtual binder::Status mountIncFs(const std::string& backingPath, const std::string& targetDir, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 51 | int32_t flags, |
| 52 | IncrementalFileSystemControlParcel* _aidl_return) const = 0; |
| 53 | virtual binder::Status unmountIncFs(const std::string& dir) const = 0; |
| 54 | virtual binder::Status bindMount(const std::string& sourceDir, |
| 55 | const std::string& targetDir) const = 0; |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 56 | virtual binder::Status setIncFsMountOptions(const ::android::os::incremental::IncrementalFileSystemControlParcel& control, bool enableReadLogs) const = 0; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 59 | class DataLoaderManagerWrapper { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 60 | public: |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 61 | virtual ~DataLoaderManagerWrapper() = default; |
| 62 | virtual binder::Status initializeDataLoader(MountId mountId, |
| 63 | const DataLoaderParamsParcel& params, |
| 64 | const FileSystemControlParcel& control, |
| 65 | const sp<IDataLoaderStatusListener>& listener, |
| 66 | bool* _aidl_return) const = 0; |
| 67 | virtual binder::Status getDataLoader(MountId mountId, sp<IDataLoader>* _aidl_return) const = 0; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 68 | virtual binder::Status destroyDataLoader(MountId mountId) const = 0; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | class IncFsWrapper { |
| 72 | public: |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 73 | virtual ~IncFsWrapper() = default; |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 74 | virtual Control createControl(IncFsFd cmd, IncFsFd pendingReads, IncFsFd logs) const = 0; |
| 75 | virtual ErrorCode makeFile(const Control& control, std::string_view path, int mode, FileId id, |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 76 | NewFileParams params) const = 0; |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 77 | virtual ErrorCode makeDir(const Control& control, std::string_view path, int mode) const = 0; |
| 78 | virtual RawMetadata getMetadata(const Control& control, FileId fileid) const = 0; |
| 79 | virtual RawMetadata getMetadata(const Control& control, std::string_view path) const = 0; |
| 80 | virtual FileId getFileId(const Control& control, std::string_view path) const = 0; |
| 81 | virtual ErrorCode link(const Control& control, std::string_view from, |
| 82 | std::string_view to) const = 0; |
| 83 | virtual ErrorCode unlink(const Control& control, std::string_view path) const = 0; |
Yurii Zubrytskyi | e82cdd7 | 2020-04-01 12:19:26 -0700 | [diff] [blame] | 84 | virtual base::unique_fd openForSpecialOps(const Control& control, FileId id) const = 0; |
Songchun Fan | 9b75308 | 2020-02-26 13:08:06 -0800 | [diff] [blame] | 85 | virtual ErrorCode writeBlocks(Span<const DataBlock> blocks) const = 0; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 88 | class AppOpsManagerWrapper { |
| 89 | public: |
| 90 | virtual ~AppOpsManagerWrapper() = default; |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 91 | virtual binder::Status checkPermission(const char* permission, const char* operation, |
| 92 | const char* package) const = 0; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 93 | virtual void startWatchingMode(int32_t op, const String16& packageName, const sp<IAppOpsCallback>& callback) = 0; |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 94 | virtual void stopWatchingMode(const sp<IAppOpsCallback>& callback) = 0; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame^] | 97 | class JniWrapper { |
| 98 | public: |
| 99 | virtual ~JniWrapper() = default; |
| 100 | virtual void initializeForCurrentThread() const = 0; |
| 101 | }; |
| 102 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 103 | class ServiceManagerWrapper { |
| 104 | public: |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 105 | virtual ~ServiceManagerWrapper() = default; |
| 106 | virtual std::unique_ptr<VoldServiceWrapper> getVoldService() = 0; |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 107 | virtual std::unique_ptr<DataLoaderManagerWrapper> getDataLoaderManager() = 0; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 108 | virtual std::unique_ptr<IncFsWrapper> getIncFs() = 0; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 109 | virtual std::unique_ptr<AppOpsManagerWrapper> getAppOpsManager() = 0; |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame^] | 110 | virtual std::unique_ptr<JniWrapper> getJni() = 0; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | // --- Real stuff --- |
| 114 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 115 | class RealServiceManager : public ServiceManagerWrapper { |
| 116 | public: |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame^] | 117 | RealServiceManager(sp<IServiceManager> serviceManager, JNIEnv* env); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 118 | ~RealServiceManager() = default; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 119 | std::unique_ptr<VoldServiceWrapper> getVoldService() final; |
| 120 | std::unique_ptr<DataLoaderManagerWrapper> getDataLoaderManager() final; |
| 121 | std::unique_ptr<IncFsWrapper> getIncFs() final; |
| 122 | std::unique_ptr<AppOpsManagerWrapper> getAppOpsManager() final; |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame^] | 123 | std::unique_ptr<JniWrapper> getJni() final; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 124 | |
| 125 | private: |
| 126 | template <class INTERFACE> |
| 127 | sp<INTERFACE> getRealService(std::string_view serviceName) const; |
| 128 | sp<android::IServiceManager> mServiceManager; |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame^] | 129 | JavaVM* const mJvm; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | } // namespace android::os::incremental |