| 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 |  | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 19 | #include <android/content/pm/BnDataLoaderStatusListener.h> | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 20 | #include <android/content/pm/DataLoaderParamsParcel.h> | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 21 | #include <android/content/pm/IDataLoaderStatusListener.h> | 
 | 22 | #include <android/os/incremental/BnIncrementalServiceConnector.h> | 
 | 23 | #include <binder/IAppOpsCallback.h> | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 24 | #include <utils/String16.h> | 
 | 25 | #include <utils/StrongPointer.h> | 
| Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 26 | #include <ziparchive/zip_archive.h> | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 27 |  | 
 | 28 | #include <atomic> | 
 | 29 | #include <chrono> | 
| Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 30 | #include <condition_variable> | 
 | 31 | #include <functional> | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 32 | #include <limits> | 
 | 33 | #include <map> | 
 | 34 | #include <mutex> | 
| Songchun Fan | 9b75308 | 2020-02-26 13:08:06 -0800 | [diff] [blame] | 35 | #include <span> | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 36 | #include <string> | 
 | 37 | #include <string_view> | 
| Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 38 | #include <thread> | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 39 | #include <unordered_map> | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 40 | #include <unordered_set> | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 41 | #include <utility> | 
 | 42 | #include <vector> | 
 | 43 |  | 
 | 44 | #include "ServiceWrappers.h" | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 45 | #include "incfs.h" | 
 | 46 | #include "path.h" | 
 | 47 |  | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 48 | namespace android::incremental { | 
 | 49 |  | 
 | 50 | using MountId = int; | 
 | 51 | using StorageId = int; | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 52 | using FileId = incfs::FileId; | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 53 | using BlockIndex = incfs::BlockIndex; | 
 | 54 | using RawMetadata = incfs::RawMetadata; | 
 | 55 | using Clock = std::chrono::steady_clock; | 
 | 56 | using TimePoint = std::chrono::time_point<Clock>; | 
 | 57 | using Seconds = std::chrono::seconds; | 
 | 58 |  | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 59 | using IDataLoaderStatusListener = ::android::content::pm::IDataLoaderStatusListener; | 
 | 60 | using DataLoaderStatusListener = ::android::sp<IDataLoaderStatusListener>; | 
| Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 61 |  | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 62 | class IncrementalService final { | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 63 | public: | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 64 |     explicit IncrementalService(ServiceManagerWrapper&& sm, std::string_view rootDir); | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 65 |  | 
 | 66 | #pragma GCC diagnostic push | 
 | 67 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" | 
 | 68 |     ~IncrementalService(); | 
 | 69 | #pragma GCC diagnostic pop | 
 | 70 |  | 
 | 71 |     static constexpr StorageId kInvalidStorageId = -1; | 
 | 72 |     static constexpr StorageId kMaxStorageId = std::numeric_limits<int>::max(); | 
 | 73 |  | 
 | 74 |     enum CreateOptions { | 
 | 75 |         TemporaryBind = 1, | 
 | 76 |         PermanentBind = 2, | 
 | 77 |         CreateNew = 4, | 
 | 78 |         OpenExisting = 8, | 
 | 79 |  | 
 | 80 |         Default = TemporaryBind | CreateNew | 
 | 81 |     }; | 
 | 82 |  | 
 | 83 |     enum class BindKind { | 
 | 84 |         Temporary = 0, | 
 | 85 |         Permanent = 1, | 
 | 86 |     }; | 
 | 87 |  | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 88 |     static FileId idFromMetadata(std::span<const uint8_t> metadata); | 
 | 89 |     static inline FileId idFromMetadata(std::span<const char> metadata) { | 
 | 90 |         return idFromMetadata({(const uint8_t*)metadata.data(), metadata.size()}); | 
 | 91 |     } | 
 | 92 |  | 
| Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame] | 93 |     void onDump(int fd); | 
 | 94 |  | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 95 |     void onSystemReady(); | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 96 |  | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 97 |     StorageId createStorage(std::string_view mountPoint, | 
 | 98 |                             content::pm::DataLoaderParamsParcel&& dataLoaderParams, | 
| Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 99 |                             const DataLoaderStatusListener& dataLoaderStatusListener, | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 100 |                             CreateOptions options = CreateOptions::Default); | 
 | 101 |     StorageId createLinkedStorage(std::string_view mountPoint, StorageId linkedStorage, | 
 | 102 |                                   CreateOptions options = CreateOptions::Default); | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 103 |     StorageId openStorage(std::string_view path); | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 104 |  | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 105 |     int bind(StorageId storage, std::string_view source, std::string_view target, BindKind kind); | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 106 |     int unbind(StorageId storage, std::string_view target); | 
 | 107 |     void deleteStorage(StorageId storage); | 
 | 108 |  | 
| Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 109 |     int setStorageParams(StorageId storage, bool enableReadLogs); | 
 | 110 |  | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 111 |     int makeFile(StorageId storage, std::string_view path, int mode, FileId id, | 
 | 112 |                  incfs::NewFileParams params); | 
| Songchun Fan | 9610093 | 2020-02-03 19:20:58 -0800 | [diff] [blame] | 113 |     int makeDir(StorageId storage, std::string_view path, int mode = 0755); | 
 | 114 |     int makeDirs(StorageId storage, std::string_view path, int mode = 0755); | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 115 |  | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 116 |     int link(StorageId sourceStorageId, std::string_view oldPath, StorageId destStorageId, | 
 | 117 |              std::string_view newPath); | 
 | 118 |     int unlink(StorageId storage, std::string_view path); | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 119 |  | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 120 |     bool isRangeLoaded(StorageId storage, FileId file, std::pair<BlockIndex, BlockIndex> range) { | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 121 |         return false; | 
 | 122 |     } | 
 | 123 |  | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 124 |     RawMetadata getMetadata(StorageId storage, std::string_view path) const; | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 125 |     RawMetadata getMetadata(StorageId storage, FileId node) const; | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 126 |  | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 127 |     bool startLoading(StorageId storage) const; | 
| Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 128 |  | 
| Songchun Fan | 0f8b6fe | 2020-02-05 17:41:25 -0800 | [diff] [blame] | 129 |     bool configureNativeBinaries(StorageId storage, std::string_view apkFullPath, | 
 | 130 |                                  std::string_view libDirRelativePath, std::string_view abi); | 
| Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 131 |     bool waitForNativeBinariesExtraction(StorageId storage); | 
| Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 132 |  | 
| Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 133 |     class AppOpsListener : public android::BnAppOpsCallback { | 
 | 134 |     public: | 
| Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 135 |         AppOpsListener(IncrementalService& incrementalService, std::string packageName) | 
 | 136 |               : incrementalService(incrementalService), packageName(std::move(packageName)) {} | 
| Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 137 |         void opChanged(int32_t op, const String16& packageName) final; | 
| Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 138 |  | 
 | 139 |     private: | 
 | 140 |         IncrementalService& incrementalService; | 
 | 141 |         const std::string packageName; | 
 | 142 |     }; | 
 | 143 |  | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 144 |     class IncrementalServiceConnector : public os::incremental::BnIncrementalServiceConnector { | 
| Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 145 |     public: | 
 | 146 |         IncrementalServiceConnector(IncrementalService& incrementalService, int32_t storage) | 
| Alex Buynytskyy | 5f9e3a0 | 2020-04-07 21:13:41 -0700 | [diff] [blame] | 147 |               : incrementalService(incrementalService), storage(storage) {} | 
| Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 148 |         binder::Status setStorageParams(bool enableReadLogs, int32_t* _aidl_return) final; | 
 | 149 |  | 
 | 150 |     private: | 
 | 151 |         IncrementalService& incrementalService; | 
| Alex Buynytskyy | 5f9e3a0 | 2020-04-07 21:13:41 -0700 | [diff] [blame] | 152 |         int32_t const storage; | 
| Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 153 |     }; | 
 | 154 |  | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 155 | private: | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 156 |     struct IncFsMount; | 
 | 157 |  | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 158 |     class DataLoaderStub : public content::pm::BnDataLoaderStatusListener { | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 159 |     public: | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 160 |         DataLoaderStub(IncrementalService& service, MountId id, | 
 | 161 |                        content::pm::DataLoaderParamsParcel&& params, | 
 | 162 |                        content::pm::FileSystemControlParcel&& control, | 
| Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 163 |                        const DataLoaderStatusListener* externalListener); | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 164 |         ~DataLoaderStub(); | 
| Alex Buynytskyy | 9a54579a | 2020-04-17 15:34:47 -0700 | [diff] [blame] | 165 |         // Cleans up the internal state and invalidates DataLoaderStub. Any subsequent calls will | 
 | 166 |         // result in an error. | 
 | 167 |         void cleanupResources(); | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 168 |  | 
| Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 169 |         bool requestCreate(); | 
| Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 170 |         bool requestStart(); | 
| Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 171 |         bool requestDestroy(); | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 172 |  | 
| Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 173 |         void onDump(int fd); | 
 | 174 |  | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 175 |         MountId id() const { return mId; } | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 176 |         const content::pm::DataLoaderParamsParcel& params() const { return mParams; } | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 177 |  | 
 | 178 |     private: | 
 | 179 |         binder::Status onStatusChanged(MountId mount, int newStatus) final; | 
 | 180 |  | 
| Alex Buynytskyy | 9a54579a | 2020-04-17 15:34:47 -0700 | [diff] [blame] | 181 |         bool isValid() const { return mId != kInvalidStorageId; } | 
| Alex Buynytskyy | 0bdbccf | 2020-04-23 20:36:42 -0700 | [diff] [blame] | 182 |         sp<content::pm::IDataLoader> getDataLoader(); | 
| Alex Buynytskyy | 9a54579a | 2020-04-17 15:34:47 -0700 | [diff] [blame] | 183 |  | 
| Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 184 |         bool bind(); | 
| Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 185 |         bool create(); | 
| Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 186 |         bool start(); | 
| Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 187 |         bool destroy(); | 
 | 188 |  | 
 | 189 |         bool setTargetStatus(int status); | 
| Alex Buynytskyy | 7e0a1a8 | 2020-04-27 17:06:10 -0700 | [diff] [blame] | 190 |         void setTargetStatusLocked(int status); | 
| Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 191 |  | 
 | 192 |         bool fsmStep(); | 
| Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 193 |  | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 194 |         IncrementalService& mService; | 
| Alex Buynytskyy | b0ea448 | 2020-05-04 18:39:58 -0700 | [diff] [blame] | 195 |  | 
 | 196 |         std::mutex mMutex; | 
| Alex Buynytskyy | 9a54579a | 2020-04-17 15:34:47 -0700 | [diff] [blame] | 197 |         MountId mId = kInvalidStorageId; | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 198 |         content::pm::DataLoaderParamsParcel mParams; | 
 | 199 |         content::pm::FileSystemControlParcel mControl; | 
| Alex Buynytskyy | 9a54579a | 2020-04-17 15:34:47 -0700 | [diff] [blame] | 200 |         DataLoaderStatusListener mListener; | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 201 |  | 
| Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 202 |         std::condition_variable mStatusCondition; | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 203 |         int mCurrentStatus = content::pm::IDataLoaderStatusListener::DATA_LOADER_DESTROYED; | 
 | 204 |         int mTargetStatus = content::pm::IDataLoaderStatusListener::DATA_LOADER_DESTROYED; | 
| Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 205 |         TimePoint mTargetStatusTs = {}; | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 206 |     }; | 
 | 207 |     using DataLoaderStubPtr = sp<DataLoaderStub>; | 
 | 208 |  | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 209 |     struct IncFsMount { | 
 | 210 |         struct Bind { | 
 | 211 |             StorageId storage; | 
 | 212 |             std::string savedFilename; | 
 | 213 |             std::string sourceDir; | 
 | 214 |             BindKind kind; | 
 | 215 |         }; | 
 | 216 |  | 
 | 217 |         struct Storage { | 
 | 218 |             std::string name; | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 219 |         }; | 
 | 220 |  | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 221 |         using Control = incfs::UniqueControl; | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 222 |  | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 223 |         using BindMap = std::map<std::string, Bind, path::PathLess>; | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 224 |         using StorageMap = std::unordered_map<StorageId, Storage>; | 
 | 225 |  | 
 | 226 |         mutable std::mutex lock; | 
 | 227 |         const std::string root; | 
 | 228 |         Control control; | 
 | 229 |         /*const*/ MountId mountId; | 
 | 230 |         StorageMap storages; | 
 | 231 |         BindMap bindPoints; | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 232 |         DataLoaderStubPtr dataLoaderStub; | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 233 |         std::atomic<int> nextStorageDirNo{0}; | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 234 |         const IncrementalService& incrementalService; | 
 | 235 |  | 
 | 236 |         IncFsMount(std::string root, MountId mountId, Control control, | 
 | 237 |                    const IncrementalService& incrementalService) | 
 | 238 |               : root(std::move(root)), | 
 | 239 |                 control(std::move(control)), | 
 | 240 |                 mountId(mountId), | 
| Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 241 |                 incrementalService(incrementalService) {} | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 242 |         IncFsMount(IncFsMount&&) = delete; | 
 | 243 |         IncFsMount& operator=(IncFsMount&&) = delete; | 
 | 244 |         ~IncFsMount(); | 
 | 245 |  | 
 | 246 |         StorageMap::iterator makeStorage(StorageId id); | 
 | 247 |  | 
 | 248 |         static void cleanupFilesystem(std::string_view root); | 
 | 249 |     }; | 
 | 250 |  | 
 | 251 |     using IfsMountPtr = std::shared_ptr<IncFsMount>; | 
 | 252 |     using MountMap = std::unordered_map<MountId, IfsMountPtr>; | 
 | 253 |     using BindPathMap = std::map<std::string, IncFsMount::BindMap::iterator, path::PathLess>; | 
 | 254 |  | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 255 |     static bool perfLoggingEnabled(); | 
 | 256 |  | 
 | 257 |     std::unordered_set<std::string_view> adoptMountedInstances(); | 
 | 258 |     void mountExistingImages(const std::unordered_set<std::string_view>& mountedRootNames); | 
| Yurii Zubrytskyi | 107ae35 | 2020-04-03 13:12:51 -0700 | [diff] [blame] | 259 |     bool mountExistingImage(std::string_view root); | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 260 |  | 
 | 261 |     IfsMountPtr getIfs(StorageId storage) const; | 
 | 262 |     const IfsMountPtr& getIfsLocked(StorageId storage) const; | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 263 |     int addBindMount(IncFsMount& ifs, StorageId storage, std::string_view storageRoot, | 
 | 264 |                      std::string&& source, std::string&& target, BindKind kind, | 
 | 265 |                      std::unique_lock<std::mutex>& mainLock); | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 266 |  | 
 | 267 |     int addBindMountWithMd(IncFsMount& ifs, StorageId storage, std::string&& metadataName, | 
| Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 268 |                            std::string&& source, std::string&& target, BindKind kind, | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 269 |                            std::unique_lock<std::mutex>& mainLock); | 
 | 270 |  | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 271 |     void addBindMountRecordLocked(IncFsMount& ifs, StorageId storage, std::string&& metadataName, | 
 | 272 |                                   std::string&& source, std::string&& target, BindKind kind); | 
 | 273 |  | 
 | 274 |     DataLoaderStubPtr prepareDataLoader(IncFsMount& ifs, | 
 | 275 |                                         content::pm::DataLoaderParamsParcel&& params, | 
| Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 276 |                                         const DataLoaderStatusListener* externalListener = nullptr); | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 277 |     void prepareDataLoaderLocked(IncFsMount& ifs, content::pm::DataLoaderParamsParcel&& params, | 
 | 278 |                                  const DataLoaderStatusListener* externalListener = nullptr); | 
| Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 279 |  | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 280 |     BindPathMap::const_iterator findStorageLocked(std::string_view path) const; | 
 | 281 |     StorageId findStorageId(std::string_view path) const; | 
 | 282 |  | 
 | 283 |     void deleteStorage(IncFsMount& ifs); | 
 | 284 |     void deleteStorageLocked(IncFsMount& ifs, std::unique_lock<std::mutex>&& ifsLock); | 
 | 285 |     MountMap::iterator getStorageSlotLocked(); | 
| Yurii Zubrytskyi | efebb45 | 2020-04-22 13:59:06 -0700 | [diff] [blame] | 286 |     std::string normalizePathToStorage(const IncFsMount& incfs, StorageId storage, | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 287 |                                        std::string_view path) const; | 
| Yurii Zubrytskyi | efebb45 | 2020-04-22 13:59:06 -0700 | [diff] [blame] | 288 |     std::string normalizePathToStorageLocked(const IncFsMount& incfs, | 
 | 289 |                                              IncFsMount::StorageMap::const_iterator storageIt, | 
| Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 290 |                                              std::string_view path) const; | 
| Yurii Zubrytskyi | efebb45 | 2020-04-22 13:59:06 -0700 | [diff] [blame] | 291 |     int makeDirs(const IncFsMount& ifs, StorageId storageId, std::string_view path, int mode); | 
| Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 292 |     binder::Status applyStorageParams(IncFsMount& ifs, bool enableReadLogs); | 
| Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 293 |  | 
 | 294 |     void registerAppOpsCallback(const std::string& packageName); | 
| Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 295 |     bool unregisterAppOpsCallback(const std::string& packageName); | 
 | 296 |     void onAppOpChanged(const std::string& packageName); | 
| Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 297 |  | 
| Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 298 |     void runJobProcessing(); | 
 | 299 |     void extractZipFile(const IfsMountPtr& ifs, ZipArchiveHandle zipFile, ZipEntry& entry, | 
 | 300 |                         const incfs::FileId& libFileId, std::string_view targetLibPath, | 
 | 301 |                         Clock::time_point scheduledTs); | 
 | 302 |  | 
 | 303 | private: | 
| Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 304 |     const std::unique_ptr<VoldServiceWrapper> mVold; | 
 | 305 |     const std::unique_ptr<DataLoaderManagerWrapper> mDataLoaderManager; | 
 | 306 |     const std::unique_ptr<IncFsWrapper> mIncFs; | 
 | 307 |     const std::unique_ptr<AppOpsManagerWrapper> mAppOpsManager; | 
 | 308 |     const std::unique_ptr<JniWrapper> mJni; | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 309 |     const std::string mIncrementalDir; | 
 | 310 |  | 
 | 311 |     mutable std::mutex mLock; | 
 | 312 |     mutable std::mutex mMountOperationLock; | 
 | 313 |     MountMap mMounts; | 
 | 314 |     BindPathMap mBindsByPath; | 
 | 315 |  | 
| Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 316 |     std::mutex mCallbacksLock; | 
| Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 317 |     std::map<std::string, sp<AppOpsListener>> mCallbackRegistered; | 
| Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 318 |  | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 319 |     std::atomic_bool mSystemReady = false; | 
 | 320 |     StorageId mNextId = 0; | 
| Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 321 |  | 
 | 322 |     using Job = std::function<void()>; | 
| Yurii Zubrytskyi | 721ac4d | 2020-04-13 11:34:32 -0700 | [diff] [blame] | 323 |     std::unordered_map<MountId, std::vector<Job>> mJobQueue; | 
 | 324 |     MountId mPendingJobsMount = kInvalidStorageId; | 
| Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 325 |     std::condition_variable mJobCondition; | 
 | 326 |     std::mutex mJobMutex; | 
 | 327 |     std::thread mJobProcessor; | 
 | 328 |     bool mRunning = true; | 
| Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 329 | }; | 
 | 330 |  | 
 | 331 | } // namespace android::incremental |