Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Add ability for some manifest attributes to reference resources.
Browse files Browse the repository at this point in the history
This loosens our restriction on many manifest attributes requiring
literal string values, to allow various ones to use values from
resources.  This is only allowed if the resource value does not change
from configuration changes, and the restriction is still in place
for attributes that are core to security (requesting permissions) or
market operation (used libraries and features etc).

Change-Id: I4da02f6a5196cb6a7dbcff9ac25403904c42c2c8
  • Loading branch information
Dianne Hackborn committed Mar 10, 2010
1 parent ae58f6d commit cf244ad
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 185 deletions.
168 changes: 91 additions & 77 deletions core/java/android/content/pm/PackageParser.java

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions core/java/android/content/res/TypedArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,42 @@ public String getNonResourceString(int index) {
return null;
}

/**
* @hide
* Retrieve the string value for the attribute at <var>index</var> that is
* not allowed to change with the given configurations.
*
* @param index Index of attribute to retrieve.
* @param allowedChangingConfigs Bit mask of configurations from
* ActivityInfo that are allowed to change.
*
* @return String holding string data. Any styling information is
* removed. Returns null if the attribute is not defined.
*/
public String getNonConfigurationString(int index, int allowedChangingConfigs) {
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index+AssetManager.STYLE_TYPE];
if ((data[index+AssetManager.STYLE_CHANGING_CONFIGURATIONS]&~allowedChangingConfigs) != 0) {
return null;
}
if (type == TypedValue.TYPE_NULL) {
return null;
} else if (type == TypedValue.TYPE_STRING) {
return loadStringValueAt(index).toString();
}

TypedValue v = mValue;
if (getValueAt(index, v)) {
Log.w(Resources.TAG, "Converting to string: " + v);
CharSequence cs = v.coerceToString();
return cs != null ? cs.toString() : null;
}
Log.w(Resources.TAG, "getString of bad type: 0x"
+ Integer.toHexString(type));
return null;
}

/**
* Retrieve the boolean value for the attribute at <var>index</var>.
*
Expand Down
4 changes: 2 additions & 2 deletions include/utils/ResourceTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ class ResXMLParser

void restart();

const ResStringPool& getStrings() const;

event_code_t getEventType() const;
// Note, unlike XmlPullParser, the first call to next() will return
// START_TAG of the first element.
Expand Down Expand Up @@ -716,8 +718,6 @@ class ResXMLTree : public ResXMLParser

void uninit();

const ResStringPool& getStrings() const;

private:
friend class ResXMLParser;

Expand Down
9 changes: 4 additions & 5 deletions libs/utils/ResourceTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ void ResXMLParser::restart()
mCurNode = NULL;
mEventCode = mTree.mError == NO_ERROR ? START_DOCUMENT : BAD_DOCUMENT;
}
const ResStringPool& ResXMLParser::getStrings() const
{
return mTree.mStrings;
}

ResXMLParser::event_code_t ResXMLParser::getEventType() const
{
Expand Down Expand Up @@ -1149,11 +1153,6 @@ void ResXMLTree::uninit()
restart();
}

const ResStringPool& ResXMLTree::getStrings() const
{
return mStrings;
}

status_t ResXMLTree::validateNode(const ResXMLTree_node* node) const
{
const uint16_t eventCode = dtohs(node->header.type);
Expand Down
2 changes: 1 addition & 1 deletion tools/aapt/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ int doDump(Bundle* bundle)
} else {
printf("versionCode='' ");
}
String8 versionName = getAttribute(tree, VERSION_NAME_ATTR, &error);
String8 versionName = getResolvedAttribute(&res, tree, VERSION_NAME_ATTR, &error);
if (error != "") {
fprintf(stderr, "ERROR getting 'android:versionName' attribute: %s\n", error.string());
goto bail;
Expand Down
Loading

0 comments on commit cf244ad

Please sign in to comment.