Add knowledge of mipmap to aapt
New mipmap drawable type that does not get filtered according to configuration. Useful for things that get built as part of the system. Change-Id: I556033d065e504079271dce79c23c90d3c387ce4
This commit is contained in:
@@ -33,8 +33,8 @@ static const char* kNoCompressExt[] = {
|
||||
|
||||
/* fwd decls, so I can write this downward */
|
||||
ssize_t processAssets(Bundle* bundle, ZipFile* zip, const sp<AaptAssets>& assets);
|
||||
ssize_t processAssets(Bundle* bundle, ZipFile* zip,
|
||||
const sp<AaptDir>& dir, const AaptGroupEntry& ge);
|
||||
ssize_t processAssets(Bundle* bundle, ZipFile* zip, const sp<AaptDir>& dir,
|
||||
const AaptGroupEntry& ge, const ResourceFilter* filter);
|
||||
bool processFile(Bundle* bundle, ZipFile* zip,
|
||||
const sp<AaptGroup>& group, const sp<AaptFile>& file);
|
||||
bool okayToCompress(Bundle* bundle, const String8& pathName);
|
||||
@@ -204,34 +204,45 @@ ssize_t processAssets(Bundle* bundle, ZipFile* zip,
|
||||
const size_t N = assets->getGroupEntries().size();
|
||||
for (size_t i=0; i<N; i++) {
|
||||
const AaptGroupEntry& ge = assets->getGroupEntries()[i];
|
||||
if (!filter.match(ge.toParams())) {
|
||||
continue;
|
||||
}
|
||||
ssize_t res = processAssets(bundle, zip, assets, ge);
|
||||
|
||||
ssize_t res = processAssets(bundle, zip, assets, ge, &filter);
|
||||
if (res < 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
count += res;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
ssize_t processAssets(Bundle* bundle, ZipFile* zip,
|
||||
const sp<AaptDir>& dir, const AaptGroupEntry& ge)
|
||||
ssize_t processAssets(Bundle* bundle, ZipFile* zip, const sp<AaptDir>& dir,
|
||||
const AaptGroupEntry& ge, const ResourceFilter* filter)
|
||||
{
|
||||
ssize_t count = 0;
|
||||
|
||||
const size_t ND = dir->getDirs().size();
|
||||
size_t i;
|
||||
for (i=0; i<ND; i++) {
|
||||
ssize_t res = processAssets(bundle, zip, dir->getDirs().valueAt(i), ge);
|
||||
const sp<AaptDir>& subDir = dir->getDirs().valueAt(i);
|
||||
|
||||
const bool filterable = filter != NULL && subDir->getLeaf().find("mipmap-") != 0;
|
||||
|
||||
if (filterable && subDir->getLeaf() != subDir->getPath() && !filter->match(ge.toParams())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ssize_t res = processAssets(bundle, zip, subDir, ge, filterable ? filter : NULL);
|
||||
if (res < 0) {
|
||||
return res;
|
||||
}
|
||||
count += res;
|
||||
}
|
||||
|
||||
if (filter != NULL && !filter->match(ge.toParams())) {
|
||||
return count;
|
||||
}
|
||||
|
||||
const size_t NF = dir->getFiles().size();
|
||||
for (i=0; i<NF; i++) {
|
||||
sp<AaptGroup> gp = dir->getFiles().valueAt(i);
|
||||
|
||||
@@ -150,7 +150,7 @@ bool isValidResourceType(const String8& type)
|
||||
{
|
||||
return type == "anim" || type == "drawable" || type == "layout"
|
||||
|| type == "values" || type == "xml" || type == "raw"
|
||||
|| type == "color" || type == "menu";
|
||||
|| type == "color" || type == "menu" || type == "mipmap";
|
||||
}
|
||||
|
||||
static sp<AaptFile> getResourceFile(const sp<AaptAssets>& assets, bool makeIfNecessary=true)
|
||||
@@ -284,9 +284,9 @@ static status_t makeFileResources(Bundle* bundle, const sp<AaptAssets>& assets,
|
||||
}
|
||||
|
||||
static status_t preProcessImages(Bundle* bundle, const sp<AaptAssets>& assets,
|
||||
const sp<ResourceTypeSet>& set)
|
||||
const sp<ResourceTypeSet>& set, const char* type)
|
||||
{
|
||||
ResourceDirIterator it(set, String8("drawable"));
|
||||
ResourceDirIterator it(set, String8(type));
|
||||
Vector<sp<AaptFile> > newNameFiles;
|
||||
Vector<String8> newNamePaths;
|
||||
bool hasErrors = false;
|
||||
@@ -802,6 +802,7 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
|
||||
sp<ResourceTypeSet> raws;
|
||||
sp<ResourceTypeSet> colors;
|
||||
sp<ResourceTypeSet> menus;
|
||||
sp<ResourceTypeSet> mipmaps;
|
||||
|
||||
ASSIGN_IT(drawable);
|
||||
ASSIGN_IT(layout);
|
||||
@@ -810,6 +811,7 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
|
||||
ASSIGN_IT(raw);
|
||||
ASSIGN_IT(color);
|
||||
ASSIGN_IT(menu);
|
||||
ASSIGN_IT(mipmap);
|
||||
|
||||
assets->setResources(resources);
|
||||
// now go through any resource overlays and collect their files
|
||||
@@ -828,7 +830,8 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
|
||||
!applyFileOverlay(bundle, assets, &xmls, "xml") ||
|
||||
!applyFileOverlay(bundle, assets, &raws, "raw") ||
|
||||
!applyFileOverlay(bundle, assets, &colors, "color") ||
|
||||
!applyFileOverlay(bundle, assets, &menus, "menu")) {
|
||||
!applyFileOverlay(bundle, assets, &menus, "menu") ||
|
||||
!applyFileOverlay(bundle, assets, &mipmaps, "mipmap")) {
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
@@ -836,7 +839,7 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
|
||||
|
||||
if (drawables != NULL) {
|
||||
if (bundle->getOutputAPKFile() != NULL) {
|
||||
err = preProcessImages(bundle, assets, drawables);
|
||||
err = preProcessImages(bundle, assets, drawables, "drawable");
|
||||
}
|
||||
if (err == NO_ERROR) {
|
||||
err = makeFileResources(bundle, assets, &table, drawables, "drawable");
|
||||
@@ -848,6 +851,20 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
|
||||
}
|
||||
}
|
||||
|
||||
if (mipmaps != NULL) {
|
||||
if (bundle->getOutputAPKFile() != NULL) {
|
||||
err = preProcessImages(bundle, assets, mipmaps, "mipmap");
|
||||
}
|
||||
if (err == NO_ERROR) {
|
||||
err = makeFileResources(bundle, assets, &table, mipmaps, "mipmap");
|
||||
if (err != NO_ERROR) {
|
||||
hasErrors = true;
|
||||
}
|
||||
} else {
|
||||
hasErrors = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (layouts != NULL) {
|
||||
err = makeFileResources(bundle, assets, &table, layouts, "layout");
|
||||
if (err != NO_ERROR) {
|
||||
|
||||
@@ -2539,7 +2539,7 @@ ResourceFilter::parse(const char* arg)
|
||||
}
|
||||
|
||||
bool
|
||||
ResourceFilter::match(int axis, uint32_t value)
|
||||
ResourceFilter::match(int axis, uint32_t value) const
|
||||
{
|
||||
if (value == 0) {
|
||||
// they didn't specify anything so take everything
|
||||
@@ -2555,7 +2555,7 @@ ResourceFilter::match(int axis, uint32_t value)
|
||||
}
|
||||
|
||||
bool
|
||||
ResourceFilter::match(const ResTable_config& config)
|
||||
ResourceFilter::match(const ResTable_config& config) const
|
||||
{
|
||||
if (config.locale) {
|
||||
uint32_t locale = (config.country[1] << 24) | (config.country[0] << 16)
|
||||
@@ -2608,6 +2608,8 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
||||
const size_t N = mOrderedPackages.size();
|
||||
size_t pi;
|
||||
|
||||
const static String16 mipmap16("mipmap");
|
||||
|
||||
bool useUTF8 = !bundle->getWantUTF16() && bundle->isMinSdkAtLeast(SDK_FROYO);
|
||||
|
||||
// Iterate through all data, collecting all values (strings,
|
||||
@@ -2630,7 +2632,10 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
||||
typeStrings.add(String16("<empty>"), false);
|
||||
continue;
|
||||
}
|
||||
typeStrings.add(t->getName(), false);
|
||||
const String16 typeName(t->getName());
|
||||
typeStrings.add(typeName, false);
|
||||
|
||||
const bool filterable = (typeName != mipmap16);
|
||||
|
||||
const size_t N = t->getOrderedConfigs().size();
|
||||
for (size_t ci=0; ci<N; ci++) {
|
||||
@@ -2641,7 +2646,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
||||
const size_t N = c->getEntries().size();
|
||||
for (size_t ei=0; ei<N; ei++) {
|
||||
ConfigDescription config = c->getEntries().keyAt(ei);
|
||||
if (!filter.match(config)) {
|
||||
if (filterable && !filter.match(config)) {
|
||||
continue;
|
||||
}
|
||||
sp<Entry> e = c->getEntries().valueAt(ei);
|
||||
@@ -2721,6 +2726,8 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
||||
"Type name %s not found",
|
||||
String8(typeName).string());
|
||||
|
||||
const bool filterable = (typeName != mipmap16);
|
||||
|
||||
const size_t N = t != NULL ? t->getOrderedConfigs().size() : 0;
|
||||
|
||||
// First write the typeSpec chunk, containing information about
|
||||
@@ -2745,7 +2752,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
||||
(((uint8_t*)data->editData())
|
||||
+ typeSpecStart + sizeof(ResTable_typeSpec));
|
||||
memset(typeSpecFlags, 0, sizeof(uint32_t)*N);
|
||||
|
||||
|
||||
for (size_t ei=0; ei<N; ei++) {
|
||||
sp<ConfigList> cl = t->getOrderedConfigs().itemAt(ei);
|
||||
if (cl->getPublic()) {
|
||||
@@ -2753,11 +2760,11 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
||||
}
|
||||
const size_t CN = cl->getEntries().size();
|
||||
for (size_t ci=0; ci<CN; ci++) {
|
||||
if (!filter.match(cl->getEntries().keyAt(ci))) {
|
||||
if (filterable && !filter.match(cl->getEntries().keyAt(ci))) {
|
||||
continue;
|
||||
}
|
||||
for (size_t cj=ci+1; cj<CN; cj++) {
|
||||
if (!filter.match(cl->getEntries().keyAt(cj))) {
|
||||
if (filterable && !filter.match(cl->getEntries().keyAt(cj))) {
|
||||
continue;
|
||||
}
|
||||
typeSpecFlags[ei] |= htodl(
|
||||
@@ -2794,7 +2801,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
|
||||
config.screenWidth,
|
||||
config.screenHeight));
|
||||
|
||||
if (!filter.match(config)) {
|
||||
if (filterable && !filter.match(config)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -549,9 +549,9 @@ class ResourceFilter
|
||||
public:
|
||||
ResourceFilter() : mData(), mContainsPseudo(false) {}
|
||||
status_t parse(const char* arg);
|
||||
bool match(int axis, uint32_t value);
|
||||
bool match(const ResTable_config& config);
|
||||
inline bool containsPseudo() { return mContainsPseudo; }
|
||||
bool match(int axis, uint32_t value) const;
|
||||
bool match(const ResTable_config& config) const;
|
||||
inline bool containsPseudo() const { return mContainsPseudo; }
|
||||
|
||||
private:
|
||||
KeyedVector<int,SortedVector<uint32_t> > mData;
|
||||
|
||||
Reference in New Issue
Block a user