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