#include <utils/String8.h>
#include <utils/Vector.h>
#include <utils/RefBase.h>
-#include <utils/ZipFile.h>
+#include "ZipFile.h"
#include "Bundle.h"
#include "SourcePos.h"
bool valid_symbol_name(const String8& str);
+class AaptAssets;
+
enum {
AXIS_NONE = 0,
AXIS_MCC = 1,
AXIS_MNC,
AXIS_LANGUAGE,
AXIS_REGION,
+ AXIS_SCREENLAYOUTSIZE,
+ AXIS_SCREENLAYOUTLONG,
AXIS_ORIENTATION,
+ AXIS_UIMODETYPE,
+ AXIS_UIMODENIGHT,
AXIS_DENSITY,
AXIS_TOUCHSCREEN,
AXIS_KEYSHIDDEN,
AXIS_KEYBOARD,
+ AXIS_NAVHIDDEN,
AXIS_NAVIGATION,
AXIS_SCREENSIZE,
- AXIS_VERSION
+ AXIS_SMALLESTSCREENWIDTHDP,
+ AXIS_SCREENWIDTHDP,
+ AXIS_SCREENHEIGHTDP,
+ AXIS_VERSION,
+
+ AXIS_START = AXIS_MCC,
+ AXIS_END = AXIS_VERSION,
};
/**
struct AaptGroupEntry
{
public:
- AaptGroupEntry() { }
+ AaptGroupEntry() : mParamsChanged(true) { }
AaptGroupEntry(const String8& _locale, const String8& _vendor)
- : locale(_locale), vendor(_vendor) { }
-
- String8 mcc;
- String8 mnc;
- String8 locale;
- String8 vendor;
- String8 orientation;
- String8 density;
- String8 touchscreen;
- String8 keysHidden;
- String8 keyboard;
- String8 navigation;
- String8 screenSize;
- String8 version;
+ : locale(_locale), vendor(_vendor), mParamsChanged(true) { }
bool initFromDirName(const char* dir, String8* resType);
static status_t parseNamePart(const String8& part, int* axis, uint32_t* value);
-
+
+ static uint32_t getConfigValueForAxis(const ResTable_config& config, int axis);
+
+ static bool configSameExcept(const ResTable_config& config,
+ const ResTable_config& otherConfig, int axis);
+
static bool getMccName(const char* name, ResTable_config* out = NULL);
static bool getMncName(const char* name, ResTable_config* out = NULL);
static bool getLocaleName(const char* name, ResTable_config* out = NULL);
+ static bool getScreenLayoutSizeName(const char* name, ResTable_config* out = NULL);
+ static bool getScreenLayoutLongName(const char* name, ResTable_config* out = NULL);
static bool getOrientationName(const char* name, ResTable_config* out = NULL);
+ static bool getUiModeTypeName(const char* name, ResTable_config* out = NULL);
+ static bool getUiModeNightName(const char* name, ResTable_config* out = NULL);
static bool getDensityName(const char* name, ResTable_config* out = NULL);
static bool getTouchscreenName(const char* name, ResTable_config* out = NULL);
static bool getKeysHiddenName(const char* name, ResTable_config* out = NULL);
static bool getKeyboardName(const char* name, ResTable_config* out = NULL);
static bool getNavigationName(const char* name, ResTable_config* out = NULL);
+ static bool getNavHiddenName(const char* name, ResTable_config* out = NULL);
static bool getScreenSizeName(const char* name, ResTable_config* out = NULL);
+ static bool getSmallestScreenWidthDpName(const char* name, ResTable_config* out = NULL);
+ static bool getScreenWidthDpName(const char* name, ResTable_config* out = NULL);
+ static bool getScreenHeightDpName(const char* name, ResTable_config* out = NULL);
static bool getVersionName(const char* name, ResTable_config* out = NULL);
int compare(const AaptGroupEntry& o) const;
- ResTable_config toParams() const;
+ const ResTable_config& toParams() const;
inline bool operator<(const AaptGroupEntry& o) const { return compare(o) < 0; }
inline bool operator<=(const AaptGroupEntry& o) const { return compare(o) <= 0; }
String8 toString() const;
String8 toDirName(const String8& resType) const;
+
+ const String8& getVersionString() const { return version; }
+
+private:
+ String8 mcc;
+ String8 mnc;
+ String8 locale;
+ String8 vendor;
+ String8 smallestScreenWidthDp;
+ String8 screenWidthDp;
+ String8 screenHeightDp;
+ String8 screenLayoutSize;
+ String8 screenLayoutLong;
+ String8 orientation;
+ String8 uiModeType;
+ String8 uiModeNight;
+ String8 density;
+ String8 touchscreen;
+ String8 keysHidden;
+ String8 keyboard;
+ String8 navHidden;
+ String8 navigation;
+ String8 screenSize;
+ String8 version;
+
+ mutable bool mParamsChanged;
+ mutable ResTable_config mParams;
};
inline int compare_type(const AaptGroupEntry& lhs, const AaptGroupEntry& rhs)
}
class AaptGroup;
+class FilePathStore;
/**
* A single asset file we know about.
{
//printf("new AaptFile created %s\n", (const char*)sourceFile);
}
- virtual ~AaptFile() { }
+ virtual ~AaptFile() {
+ free(mData);
+ }
const String8& getPath() const { return mPath; }
const AaptGroupEntry& getGroupEntry() const { return mGroupEntry; }
status_t addFile(const sp<AaptFile>& file);
void removeFile(size_t index);
- void print() const;
+ void print(const String8& prefix) const;
String8 getPrintableSource() const;
};
/**
- * A single directory of assets, which can contain for files and other
+ * A single directory of assets, which can contain files and other
* sub-directories.
*/
class AaptDir : public RefBase
const DefaultKeyedVector<String8, sp<AaptGroup> >& getFiles() const { return mFiles; }
const DefaultKeyedVector<String8, sp<AaptDir> >& getDirs() const { return mDirs; }
- status_t addFile(const String8& name, const sp<AaptGroup>& file);
- status_t addDir(const String8& name, const sp<AaptDir>& dir);
-
- sp<AaptDir> makeDir(const String8& name);
+ virtual status_t addFile(const String8& name, const sp<AaptGroup>& file);
void removeFile(const String8& name);
void removeDir(const String8& name);
- status_t renameFile(const sp<AaptFile>& file, const String8& newName);
-
- status_t addLeafFile(const String8& leafName,
- const sp<AaptFile>& file);
-
- virtual ssize_t slurpFullTree(Bundle* bundle,
- const String8& srcDir,
- const AaptGroupEntry& kind,
- const String8& resType);
-
/*
* Perform some sanity checks on the names of files and directories here.
* In particular:
*/
status_t validate() const;
- void print() const;
+ void print(const String8& prefix) const;
String8 getPrintableSource() const;
private:
+ friend class AaptAssets;
+
+ status_t addDir(const String8& name, const sp<AaptDir>& dir);
+ sp<AaptDir> makeDir(const String8& name);
+ status_t addLeafFile(const String8& leafName,
+ const sp<AaptFile>& file);
+ virtual ssize_t slurpFullTree(Bundle* bundle,
+ const String8& srcDir,
+ const AaptGroupEntry& kind,
+ const String8& resType,
+ sp<FilePathStore>& fullResPaths);
+
String8 mLeaf;
String8 mPath;
{
public:
AaptSymbolEntry()
- : isPublic(false), typeCode(TYPE_UNKNOWN)
+ : isPublic(false), isJavaSymbol(false), typeCode(TYPE_UNKNOWN)
{
}
AaptSymbolEntry(const String8& _name)
- : name(_name), isPublic(false), typeCode(TYPE_UNKNOWN)
+ : name(_name), isPublic(false), isJavaSymbol(false), typeCode(TYPE_UNKNOWN)
{
}
AaptSymbolEntry(const AaptSymbolEntry& o)
: name(o.name), sourcePos(o.sourcePos), isPublic(o.isPublic)
- , comment(o.comment), typeComment(o.typeComment)
+ , isJavaSymbol(o.isJavaSymbol), comment(o.comment), typeComment(o.typeComment)
, typeCode(o.typeCode), int32Val(o.int32Val), stringVal(o.stringVal)
{
}
{
sourcePos = o.sourcePos;
isPublic = o.isPublic;
+ isJavaSymbol = o.isJavaSymbol;
comment = o.comment;
typeComment = o.typeComment;
typeCode = o.typeCode;
SourcePos sourcePos;
bool isPublic;
+ bool isJavaSymbol;
String16 comment;
String16 typeComment;
return NO_ERROR;
}
+ status_t makeSymbolJavaSymbol(const String8& name, const SourcePos& pos) {
+ if (!check_valid_symbol_name(name, pos, "symbol")) {
+ return BAD_VALUE;
+ }
+ AaptSymbolEntry& sym = edit_symbol(name, &pos);
+ sym.isJavaSymbol = true;
+ return NO_ERROR;
+ }
+
void appendComment(const String8& name, const String16& comment, const SourcePos& pos) {
if (comment.size() <= 0) {
return;
return sym;
}
+ status_t applyJavaSymbols(const sp<AaptSymbols>& javaSymbols);
+
const KeyedVector<String8, AaptSymbolEntry>& getSymbols() const
{ return mSymbols; }
const DefaultKeyedVector<String8, sp<AaptSymbols> >& getNestedSymbols() const
AaptSymbolEntry mDefSymbol;
};
-class ResourceTypeSet;
+class ResourceTypeSet : public RefBase,
+ public KeyedVector<String8,sp<AaptGroup> >
+{
+public:
+ ResourceTypeSet();
+};
+
+// Storage for lists of fully qualified paths for
+// resources encountered during slurping.
+class FilePathStore : public RefBase,
+ public Vector<String8>
+{
+public:
+ FilePathStore();
+};
/**
* Asset hierarchy being operated on.
class AaptAssets : public AaptDir
{
public:
- AaptAssets() : AaptDir(String8(), String8()), mHaveIncludedAssets(false) { }
- virtual ~AaptAssets() { }
+ AaptAssets();
+ virtual ~AaptAssets() { delete mRes; }
const String8& getPackage() const { return mPackage; }
- void setPackage(const String8& package) { mPackage = package; mSymbolsPrivatePackage = package; }
+ void setPackage(const String8& package) {
+ mPackage = package;
+ mSymbolsPrivatePackage = package;
+ mHavePrivateSymbols = false;
+ }
+
+ const SortedVector<AaptGroupEntry>& getGroupEntries() const;
- const SortedVector<AaptGroupEntry>& getGroupEntries() const { return mGroupEntries; }
+ virtual status_t addFile(const String8& name, const sp<AaptGroup>& file);
sp<AaptFile> addFile(const String8& filePath,
const AaptGroupEntry& entry,
const sp<AaptFile>& file,
const String8& resType);
+ void addGroupEntry(const AaptGroupEntry& entry) { mGroupEntries.add(entry); }
+
ssize_t slurpFromArgs(Bundle* bundle);
- virtual ssize_t slurpFullTree(Bundle* bundle,
- const String8& srcDir,
- const AaptGroupEntry& kind,
- const String8& resType);
+ sp<AaptSymbols> getSymbolsFor(const String8& name);
- ssize_t slurpResourceTree(Bundle* bundle, const String8& srcDir);
- ssize_t slurpResourceZip(Bundle* bundle, const char* filename);
+ sp<AaptSymbols> getJavaSymbolsFor(const String8& name);
- sp<AaptSymbols> getSymbolsFor(const String8& name);
+ status_t applyJavaSymbols();
const DefaultKeyedVector<String8, sp<AaptSymbols> >& getSymbols() const { return mSymbols; }
String8 getSymbolsPrivatePackage() const { return mSymbolsPrivatePackage; }
- void setSymbolsPrivatePackage(const String8& pkg) { mSymbolsPrivatePackage = pkg; }
-
+ void setSymbolsPrivatePackage(const String8& pkg) {
+ mSymbolsPrivatePackage = pkg;
+ mHavePrivateSymbols = mSymbolsPrivatePackage != mPackage;
+ }
+
+ bool havePrivateSymbols() const { return mHavePrivateSymbols; }
+
+ bool isJavaSymbol(const AaptSymbolEntry& sym, bool includePrivate) const;
+
status_t buildIncludedResources(Bundle* bundle);
status_t addIncludedResources(const sp<AaptFile>& file);
const ResTable& getIncludedResources() const;
- void print() const;
+ void print(const String8& prefix) const;
- inline const Vector<sp<AaptDir> >& resDirs() { return mDirs; }
+ inline const Vector<sp<AaptDir> >& resDirs() const { return mResDirs; }
+ sp<AaptDir> resDir(const String8& name) const;
inline sp<AaptAssets> getOverlay() { return mOverlay; }
inline void setOverlay(sp<AaptAssets>& overlay) { mOverlay = overlay; }
inline KeyedVector<String8, sp<ResourceTypeSet> >* getResources() { return mRes; }
inline void
- setResources(KeyedVector<String8, sp<ResourceTypeSet> >* res) { mRes = res; }
+ setResources(KeyedVector<String8, sp<ResourceTypeSet> >* res) { delete mRes; mRes = res; }
+
+ inline sp<FilePathStore>& getFullResPaths() { return mFullResPaths; }
+ inline void
+ setFullResPaths(sp<FilePathStore>& res) { mFullResPaths = res; }
+
+ inline sp<FilePathStore>& getFullAssetPaths() { return mFullAssetPaths; }
+ inline void
+ setFullAssetPaths(sp<FilePathStore>& res) { mFullAssetPaths = res; }
private:
+ virtual ssize_t slurpFullTree(Bundle* bundle,
+ const String8& srcDir,
+ const AaptGroupEntry& kind,
+ const String8& resType,
+ sp<FilePathStore>& fullResPaths);
+
+ ssize_t slurpResourceTree(Bundle* bundle, const String8& srcDir);
+ ssize_t slurpResourceZip(Bundle* bundle, const char* filename);
+
+ status_t filter(Bundle* bundle);
+
String8 mPackage;
SortedVector<AaptGroupEntry> mGroupEntries;
DefaultKeyedVector<String8, sp<AaptSymbols> > mSymbols;
+ DefaultKeyedVector<String8, sp<AaptSymbols> > mJavaSymbols;
String8 mSymbolsPrivatePackage;
+ bool mHavePrivateSymbols;
+
+ Vector<sp<AaptDir> > mResDirs;
- Vector<sp<AaptDir> > mDirs;
+ bool mChanged;
bool mHaveIncludedAssets;
AssetManager mIncludedAssets;
sp<AaptAssets> mOverlay;
KeyedVector<String8, sp<ResourceTypeSet> >* mRes;
+
+ sp<FilePathStore> mFullResPaths;
+ sp<FilePathStore> mFullAssetPaths;
};
#endif // __AAPT_ASSETS_H