blob: d9b590f7842b6afa4859f172bd5e64fb04563fe7 [file] [log] [blame]
Felka Chang2a0a2462019-11-20 14:20:40 +08001/*
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 Chang4df87f62020-02-11 19:08:43 +080020#ifdef ENABLE_STORAGE_CRATES
21
Felka Chang2a0a2462019-11-20 14:20:40 +080022#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
Ryan Prichard644a5b72023-07-20 21:39:48 -070028#include <functional>
Jooyung Han2d5878e2020-01-23 12:45:10 +090029#include <optional>
Felka Chang2a0a2462019-11-20 14:20:40 +080030#include <string>
31#include <vector>
32
33#ifndef CRATE_DEBUG
34#define CRATE_DEBUG 1
35#endif
36
37namespace android {
38namespace installd {
39
40using android::os::storage::CrateMetadata;
41
42/**
43 * The crated folder actually is a folder that is the first level child director. In order to
44 * distingish between the crated folder and the other FTSENT*, to define the type "CratedFolder"
45 * make the code easy to identify the difference.
46 */
47typedef FTSENT* CratedFolder;
48
49/**
50 * In order to give the users more fine-grained files controlling, the crate information can help
51 * applications' developers to show the more detail information to the users. The crate information
52 * include the Label, Expiration etc..
53 */
54class CrateManager {
55public:
56 CrateManager(const char* uuid, userid_t userId, const std::string& packageName);
57 ~CrateManager();
58
Jooyung Han2d5878e2020-01-23 12:45:10 +090059 void traverseAllCrates(std::function<void(CratedFolder, CrateMetadata&&)>& onCreateCrate);
Felka Chang2a0a2462019-11-20 14:20:40 +080060
61 static void traverseChildDir(const std::string& targetDir,
62 std::function<void(FTSENT*)>& onVisitChildDir);
63
64 static void traverseAllPackagesForUser(
Jooyung Han2d5878e2020-01-23 12:45:10 +090065 const std::optional<std::string>& uuid,
Felka Chang2a0a2462019-11-20 14:20:40 +080066 userid_t userId,
67 std::function<void(FTSENT*)>& onHandlingPackage);
68
69#if CRATE_DEBUG
Jooyung Han2d5878e2020-01-23 12:45:10 +090070 static void dump(const CrateMetadata& CrateMetadata);
Felka Chang2a0a2462019-11-20 14:20:40 +080071#endif
72private:
73 std::string mRoot;
74 std::string mCratedFoldersRoot;
75 std::string mPackageName;
76
77 void createCrate(
78 CratedFolder cratedFolder,
Jooyung Han2d5878e2020-01-23 12:45:10 +090079 std::function<void(CratedFolder, CrateMetadata&&)>& onCreateCrate);
Felka Chang2a0a2462019-11-20 14:20:40 +080080};
81
82} // namespace installd
83} // namespace android
84
Felka Chang4df87f62020-02-11 19:08:43 +080085#else // ENABLE_STORAGE_CRATES
86#include <android/os/storage/CrateMetadata.h>
87using android::os::storage::CrateMetadata;
88#endif // ENABLE_STORAGE_CRATES
89
Felka Chang2a0a2462019-11-20 14:20:40 +080090#endif // ANDROID_INSTALLD_CRATE_INFO_MANAGER_H