Permalink
Browse files

Add ability for some manifest attributes to reference resources.

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
Dianne Hackborn committed Mar 9, 2010
1 parent ae58f6d commit cf244ada58539ce857ec041d7288d0271204fbb6

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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>.
*
@@ -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.
@@ -716,8 +718,6 @@ class ResXMLTree : public ResXMLParser
void uninit();
- const ResStringPool& getStrings() const;
-
private:
friend class ResXMLParser;
@@ -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
{
@@ -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);
View
@@ -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;
Oops, something went wrong.

0 comments on commit cf244ad

Please sign in to comment.