blob: db23c8488bdd8e02de924b40d0c32b17280e7b67 (
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
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
|
/*
* Copyright (C) 2014 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 __APK_BUILDER_H
#define __APK_BUILDER_H
#include <set>
#include <utils/Errors.h>
#include <utils/String8.h>
#include <utils/StrongPointer.h>
#include <utils/Vector.h>
#include "ConfigDescription.h"
#include "OutputSet.h"
#include "ResourceFilter.h"
class ApkSplit;
class AaptFile;
class ApkBuilder : public android::RefBase {
public:
ApkBuilder(const sp<WeakResourceFilter>& configFilter);
/**
* Tells the builder to generate a separate APK for resources that
* match the configurations specified. Split APKs can not have
* overlapping resources.
*
* NOTE: All splits should be set up before any files are added.
*/
android::status_t createSplitForConfigs(const std::set<ConfigDescription>& configs);
/**
* Adds a file to be written to the final APK. It's name must not collide
* with that of any files previously added. When a Split APK is being
* generated, duplicates can exist as long as they are in different splits
* (resources.arsc, AndroidManifest.xml).
*/
android::status_t addEntry(const String8& path, const android::sp<AaptFile>& file);
android::Vector<sp<ApkSplit> >& getSplits() {
return mSplits;
}
android::sp<ApkSplit> getBaseSplit() {
return mSplits[0];
}
void print() const;
private:
android::sp<ResourceFilter> mConfigFilter;
android::sp<AndResourceFilter> mDefaultFilter;
android::Vector<sp<ApkSplit> > mSplits;
};
class ApkSplit : public OutputSet {
public:
android::status_t addEntry(const String8& path, const android::sp<AaptFile>& file);
const std::set<OutputEntry>& getEntries() const {
return mFiles;
}
const std::set<ConfigDescription>& getConfigs() const {
return mConfigs;
}
bool matches(const sp<AaptFile>& file) const {
return mFilter->match(file->getGroupEntry().toParams());
}
sp<ResourceFilter> getResourceFilter() const {
return mFilter;
}
const android::String8& getPrintableName() const {
return mName;
}
const android::String8& getDirectorySafeName() const {
return mDirName;
}
bool isBase() const {
return mIsBase;
}
void print() const;
private:
friend class ApkBuilder;
ApkSplit(const std::set<ConfigDescription>& configs, const android::sp<ResourceFilter>& filter, bool isBase=false);
std::set<ConfigDescription> mConfigs;
const sp<ResourceFilter> mFilter;
const bool mIsBase;
String8 mName;
String8 mDirName;
std::set<OutputEntry> mFiles;
};
#endif // __APK_BUILDER_H
|