1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2019 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_INSTALLD_CRATE_INFO_MANAGER_H 18*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_INSTALLD_CRATE_INFO_MANAGER_H 19*38e8c45fSAndroid Build Coastguard Worker 20*38e8c45fSAndroid Build Coastguard Worker #ifdef ENABLE_STORAGE_CRATES 21*38e8c45fSAndroid Build Coastguard Worker 22*38e8c45fSAndroid Build Coastguard Worker #include <android/os/storage/CrateMetadata.h> 23*38e8c45fSAndroid Build Coastguard Worker #include <cutils/multiuser.h> 24*38e8c45fSAndroid Build Coastguard Worker #include <fts.h> 25*38e8c45fSAndroid Build Coastguard Worker #include <sys/stat.h> 26*38e8c45fSAndroid Build Coastguard Worker #include <sys/types.h> 27*38e8c45fSAndroid Build Coastguard Worker 28*38e8c45fSAndroid Build Coastguard Worker #include <functional> 29*38e8c45fSAndroid Build Coastguard Worker #include <optional> 30*38e8c45fSAndroid Build Coastguard Worker #include <string> 31*38e8c45fSAndroid Build Coastguard Worker #include <vector> 32*38e8c45fSAndroid Build Coastguard Worker 33*38e8c45fSAndroid Build Coastguard Worker #ifndef CRATE_DEBUG 34*38e8c45fSAndroid Build Coastguard Worker #define CRATE_DEBUG 1 35*38e8c45fSAndroid Build Coastguard Worker #endif 36*38e8c45fSAndroid Build Coastguard Worker 37*38e8c45fSAndroid Build Coastguard Worker namespace android { 38*38e8c45fSAndroid Build Coastguard Worker namespace installd { 39*38e8c45fSAndroid Build Coastguard Worker 40*38e8c45fSAndroid Build Coastguard Worker using android::os::storage::CrateMetadata; 41*38e8c45fSAndroid Build Coastguard Worker 42*38e8c45fSAndroid Build Coastguard Worker /** 43*38e8c45fSAndroid Build Coastguard Worker * The crated folder actually is a folder that is the first level child director. In order to 44*38e8c45fSAndroid Build Coastguard Worker * distingish between the crated folder and the other FTSENT*, to define the type "CratedFolder" 45*38e8c45fSAndroid Build Coastguard Worker * make the code easy to identify the difference. 46*38e8c45fSAndroid Build Coastguard Worker */ 47*38e8c45fSAndroid Build Coastguard Worker typedef FTSENT* CratedFolder; 48*38e8c45fSAndroid Build Coastguard Worker 49*38e8c45fSAndroid Build Coastguard Worker /** 50*38e8c45fSAndroid Build Coastguard Worker * In order to give the users more fine-grained files controlling, the crate information can help 51*38e8c45fSAndroid Build Coastguard Worker * applications' developers to show the more detail information to the users. The crate information 52*38e8c45fSAndroid Build Coastguard Worker * include the Label, Expiration etc.. 53*38e8c45fSAndroid Build Coastguard Worker */ 54*38e8c45fSAndroid Build Coastguard Worker class CrateManager { 55*38e8c45fSAndroid Build Coastguard Worker public: 56*38e8c45fSAndroid Build Coastguard Worker CrateManager(const char* uuid, userid_t userId, const std::string& packageName); 57*38e8c45fSAndroid Build Coastguard Worker ~CrateManager(); 58*38e8c45fSAndroid Build Coastguard Worker 59*38e8c45fSAndroid Build Coastguard Worker void traverseAllCrates(std::function<void(CratedFolder, CrateMetadata&&)>& onCreateCrate); 60*38e8c45fSAndroid Build Coastguard Worker 61*38e8c45fSAndroid Build Coastguard Worker static void traverseChildDir(const std::string& targetDir, 62*38e8c45fSAndroid Build Coastguard Worker std::function<void(FTSENT*)>& onVisitChildDir); 63*38e8c45fSAndroid Build Coastguard Worker 64*38e8c45fSAndroid Build Coastguard Worker static void traverseAllPackagesForUser( 65*38e8c45fSAndroid Build Coastguard Worker const std::optional<std::string>& uuid, 66*38e8c45fSAndroid Build Coastguard Worker userid_t userId, 67*38e8c45fSAndroid Build Coastguard Worker std::function<void(FTSENT*)>& onHandlingPackage); 68*38e8c45fSAndroid Build Coastguard Worker 69*38e8c45fSAndroid Build Coastguard Worker #if CRATE_DEBUG 70*38e8c45fSAndroid Build Coastguard Worker static void dump(const CrateMetadata& CrateMetadata); 71*38e8c45fSAndroid Build Coastguard Worker #endif 72*38e8c45fSAndroid Build Coastguard Worker private: 73*38e8c45fSAndroid Build Coastguard Worker std::string mRoot; 74*38e8c45fSAndroid Build Coastguard Worker std::string mCratedFoldersRoot; 75*38e8c45fSAndroid Build Coastguard Worker std::string mPackageName; 76*38e8c45fSAndroid Build Coastguard Worker 77*38e8c45fSAndroid Build Coastguard Worker void createCrate( 78*38e8c45fSAndroid Build Coastguard Worker CratedFolder cratedFolder, 79*38e8c45fSAndroid Build Coastguard Worker std::function<void(CratedFolder, CrateMetadata&&)>& onCreateCrate); 80*38e8c45fSAndroid Build Coastguard Worker }; 81*38e8c45fSAndroid Build Coastguard Worker 82*38e8c45fSAndroid Build Coastguard Worker } // namespace installd 83*38e8c45fSAndroid Build Coastguard Worker } // namespace android 84*38e8c45fSAndroid Build Coastguard Worker 85*38e8c45fSAndroid Build Coastguard Worker #else // ENABLE_STORAGE_CRATES 86*38e8c45fSAndroid Build Coastguard Worker #include <android/os/storage/CrateMetadata.h> 87*38e8c45fSAndroid Build Coastguard Worker using android::os::storage::CrateMetadata; 88*38e8c45fSAndroid Build Coastguard Worker #endif // ENABLE_STORAGE_CRATES 89*38e8c45fSAndroid Build Coastguard Worker 90*38e8c45fSAndroid Build Coastguard Worker #endif // ANDROID_INSTALLD_CRATE_INFO_MANAGER_H 91