summaryrefslogtreecommitdiff
path: root/cmds/installd/CrateManager.h
blob: 1f30b5dc7948c1fa49af678c6adb07ac4e9da711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_INSTALLD_CRATE_INFO_MANAGER_H
#define ANDROID_INSTALLD_CRATE_INFO_MANAGER_H

#ifdef ENABLE_STORAGE_CRATES

#include <android/os/storage/CrateMetadata.h>
#include <cutils/multiuser.h>
#include <fts.h>
#include <sys/stat.h>
#include <sys/types.h>

#include <optional>
#include <string>
#include <vector>

#ifndef CRATE_DEBUG
#define CRATE_DEBUG 1
#endif

namespace android {
namespace installd {

using android::os::storage::CrateMetadata;

/**
 * The crated folder actually is a folder that is the first level child director. In order to
 * distingish between the crated folder and the other FTSENT*, to define the type "CratedFolder"
 * make the code easy to identify the difference.
 */
typedef FTSENT* CratedFolder;

/**
 * In order to give the users more fine-grained files controlling, the crate information can help
 * applications' developers to show the more detail information to the users. The crate information
 * include the Label, Expiration etc..
 */
class CrateManager {
public:
    CrateManager(const char* uuid, userid_t userId, const std::string& packageName);
    ~CrateManager();

    void traverseAllCrates(std::function<void(CratedFolder, CrateMetadata&&)>& onCreateCrate);

    static void traverseChildDir(const std::string& targetDir,
            std::function<void(FTSENT*)>& onVisitChildDir);

    static void traverseAllPackagesForUser(
        const std::optional<std::string>& uuid,
        userid_t userId,
        std::function<void(FTSENT*)>& onHandlingPackage);

#if CRATE_DEBUG
    static void dump(const CrateMetadata& CrateMetadata);
#endif
private:
    std::string mRoot;
    std::string mCratedFoldersRoot;
    std::string mPackageName;

    void createCrate(
        CratedFolder cratedFolder,
        std::function<void(CratedFolder, CrateMetadata&&)>& onCreateCrate);
};

} // namespace installd
} // namespace android

#else // ENABLE_STORAGE_CRATES
#include <android/os/storage/CrateMetadata.h>
using android::os::storage::CrateMetadata;
#endif // ENABLE_STORAGE_CRATES

#endif // ANDROID_INSTALLD_CRATE_INFO_MANAGER_H