| Felka Chang | 2a0a246 | 2019-11-20 14:20:40 +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 | #ifndef ANDROID_INSTALLD_CRATE_INFO_MANAGER_H | 
|  | 18 | #define ANDROID_INSTALLD_CRATE_INFO_MANAGER_H | 
|  | 19 |  | 
| Felka Chang | 4df87f6 | 2020-02-11 19:08:43 +0800 | [diff] [blame] | 20 | #ifdef ENABLE_STORAGE_CRATES | 
|  | 21 |  | 
| Felka Chang | 2a0a246 | 2019-11-20 14:20:40 +0800 | [diff] [blame] | 22 | #include <android/os/storage/CrateMetadata.h> | 
|  | 23 | #include <cutils/multiuser.h> | 
|  | 24 | #include <fts.h> | 
|  | 25 | #include <sys/stat.h> | 
|  | 26 | #include <sys/types.h> | 
|  | 27 |  | 
| Jooyung Han | 149be4a | 2020-01-23 12:45:10 +0900 | [diff] [blame] | 28 | #include <optional> | 
| Felka Chang | 2a0a246 | 2019-11-20 14:20:40 +0800 | [diff] [blame] | 29 | #include <string> | 
|  | 30 | #include <vector> | 
|  | 31 |  | 
|  | 32 | #ifndef CRATE_DEBUG | 
|  | 33 | #define CRATE_DEBUG 1 | 
|  | 34 | #endif | 
|  | 35 |  | 
|  | 36 | namespace android { | 
|  | 37 | namespace installd { | 
|  | 38 |  | 
|  | 39 | using android::os::storage::CrateMetadata; | 
|  | 40 |  | 
|  | 41 | /** | 
|  | 42 | * The crated folder actually is a folder that is the first level child director. In order to | 
|  | 43 | * distingish between the crated folder and the other FTSENT*, to define the type "CratedFolder" | 
|  | 44 | * make the code easy to identify the difference. | 
|  | 45 | */ | 
|  | 46 | typedef FTSENT* CratedFolder; | 
|  | 47 |  | 
|  | 48 | /** | 
|  | 49 | * In order to give the users more fine-grained files controlling, the crate information can help | 
|  | 50 | * applications' developers to show the more detail information to the users. The crate information | 
|  | 51 | * include the Label, Expiration etc.. | 
|  | 52 | */ | 
|  | 53 | class CrateManager { | 
|  | 54 | public: | 
|  | 55 | CrateManager(const char* uuid, userid_t userId, const std::string& packageName); | 
|  | 56 | ~CrateManager(); | 
|  | 57 |  | 
| Jooyung Han | 149be4a | 2020-01-23 12:45:10 +0900 | [diff] [blame] | 58 | void traverseAllCrates(std::function<void(CratedFolder, CrateMetadata&&)>& onCreateCrate); | 
| Felka Chang | 2a0a246 | 2019-11-20 14:20:40 +0800 | [diff] [blame] | 59 |  | 
|  | 60 | static void traverseChildDir(const std::string& targetDir, | 
|  | 61 | std::function<void(FTSENT*)>& onVisitChildDir); | 
|  | 62 |  | 
|  | 63 | static void traverseAllPackagesForUser( | 
| Jooyung Han | 149be4a | 2020-01-23 12:45:10 +0900 | [diff] [blame] | 64 | const std::optional<std::string>& uuid, | 
| Felka Chang | 2a0a246 | 2019-11-20 14:20:40 +0800 | [diff] [blame] | 65 | userid_t userId, | 
|  | 66 | std::function<void(FTSENT*)>& onHandlingPackage); | 
|  | 67 |  | 
|  | 68 | #if CRATE_DEBUG | 
| Jooyung Han | 149be4a | 2020-01-23 12:45:10 +0900 | [diff] [blame] | 69 | static void dump(const CrateMetadata& CrateMetadata); | 
| Felka Chang | 2a0a246 | 2019-11-20 14:20:40 +0800 | [diff] [blame] | 70 | #endif | 
|  | 71 | private: | 
|  | 72 | std::string mRoot; | 
|  | 73 | std::string mCratedFoldersRoot; | 
|  | 74 | std::string mPackageName; | 
|  | 75 |  | 
|  | 76 | void createCrate( | 
|  | 77 | CratedFolder cratedFolder, | 
| Jooyung Han | 149be4a | 2020-01-23 12:45:10 +0900 | [diff] [blame] | 78 | std::function<void(CratedFolder, CrateMetadata&&)>& onCreateCrate); | 
| Felka Chang | 2a0a246 | 2019-11-20 14:20:40 +0800 | [diff] [blame] | 79 | }; | 
|  | 80 |  | 
|  | 81 | } // namespace installd | 
|  | 82 | } // namespace android | 
|  | 83 |  | 
| Felka Chang | 4df87f6 | 2020-02-11 19:08:43 +0800 | [diff] [blame] | 84 | #else // ENABLE_STORAGE_CRATES | 
|  | 85 | #include <android/os/storage/CrateMetadata.h> | 
|  | 86 | using android::os::storage::CrateMetadata; | 
|  | 87 | #endif // ENABLE_STORAGE_CRATES | 
|  | 88 |  | 
| Felka Chang | 2a0a246 | 2019-11-20 14:20:40 +0800 | [diff] [blame] | 89 | #endif // ANDROID_INSTALLD_CRATE_INFO_MANAGER_H |