File: dataloader.h

package info (click to toggle)
android-platform-tools 35.0.2-1~exp6
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 211,716 kB
  • sloc: cpp: 995,749; java: 290,495; ansic: 145,647; xml: 58,531; python: 39,608; sh: 14,500; javascript: 5,198; asm: 4,866; makefile: 3,115; yacc: 769; awk: 368; ruby: 183; sql: 140; perl: 88; lex: 67
file content (132 lines) | stat: -rw-r--r-- 4,383 bytes parent folder | download | duplicates (3)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * 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.
 */
#pragma once

#include <functional>
#include <memory>
#include <string>
#include <vector>

#include "dataloader_ndk.h"
#include "incfs.h"

namespace android::dataloader {

using DataLoaderStatus = ::DataLoaderStatus;
template <class T>
using Span = android::incfs::Span<T>;

struct DataLoader;
struct DataLoaderParams;
struct DataLoaderInstallationFile;
struct FilesystemConnector;
struct StatusListener;

using FileId = IncFsFileId;
using Uid = IncFsUid;
using ReadInfo = IncFsReadInfo;
using ReadInfoWithUid = IncFsReadInfoWithUid;
using DataBlock = IncFsDataBlock;

using FilesystemConnectorPtr = FilesystemConnector*;
using StatusListenerPtr = StatusListener*;
using ServiceConnectorPtr = DataLoaderServiceConnectorPtr;
using ServiceParamsPtr = DataLoaderServiceParamsPtr;

using DataLoaderPtr = std::unique_ptr<DataLoader>;
using DataLoaderInstallationFiles = Span<const ::DataLoaderInstallationFile>;
using PendingReads = Span<const ReadInfo>;
using PendingReadsWithUid = Span<const ReadInfoWithUid>;
using PageReads = Span<const ReadInfo>;
using PageReadsWithUid = Span<const ReadInfoWithUid>;
using RawMetadata = std::vector<char>;
using DataBlocks = Span<const DataBlock>;

constexpr int kBlockSize = INCFS_DATA_FILE_BLOCK_SIZE;

struct DataLoader {
    using Factory = std::function<DataLoaderPtr(DataLoaderServiceVmPtr, const DataLoaderParams&)>;
    static void initialize(Factory&& factory);

    virtual ~DataLoader() {}

    // Bitmask of supported features.
    virtual DataLoaderFeatures getFeatures() const = 0;

    // Lifecycle.
    virtual bool onCreate(const DataLoaderParams&, FilesystemConnectorPtr, StatusListenerPtr,
                          ServiceConnectorPtr, ServiceParamsPtr) = 0;
    virtual bool onStart() = 0;
    virtual void onStop() = 0;
    virtual void onDestroy() = 0;

    // FS callbacks.
    virtual bool onPrepareImage(DataLoaderInstallationFiles addedFiles) = 0;

    // IFS callbacks.
    virtual void onPendingReads(PendingReads pendingReads) = 0;
    virtual void onPageReads(PageReads pageReads) = 0;

    virtual void onPendingReadsWithUid(PageReadsWithUid pendingReads) = 0;
    virtual void onPageReadsWithUid(PendingReadsWithUid pageReads) = 0;
};

struct DataLoaderParams {
    DataLoaderType type() const { return mType; }
    const std::string& packageName() const { return mPackageName; }
    const std::string& className() const { return mClassName; }
    const std::string& arguments() const { return mArguments; }

    DataLoaderParams(DataLoaderType type, std::string&& packageName, std::string&& className,
                     std::string&& arguments);

private:
    DataLoaderType const mType;
    std::string const mPackageName;
    std::string const mClassName;
    std::string const mArguments;
};

struct DataLoaderInstallationFile {
    DataLoaderLocation location() const { return mLocation; }
    const std::string& name() const { return mName; }
    IncFsSize size() const { return mSize; }
    const RawMetadata& metadata() const { return mMetadata; }

    DataLoaderInstallationFile(DataLoaderLocation location, std::string&& name, IncFsSize size,
                               RawMetadata&& metadata);

private:
    DataLoaderLocation const mLocation;
    std::string const mName;
    IncFsSize const mSize;
    RawMetadata const mMetadata;
};

struct FilesystemConnector : public DataLoaderFilesystemConnector {
    android::incfs::UniqueFd openForSpecialOps(FileId fid);
    int writeBlocks(DataBlocks blocks);
    RawMetadata getRawMetadata(FileId fid);
    bool setParams(DataLoaderFilesystemParams);
};

struct StatusListener : public DataLoaderStatusListener {
    bool reportStatus(DataLoaderStatus status);
};

} // namespace android::dataloader

#include "dataloader_inline.h"