Skip to content

Commit

Permalink
fix: resolve missing namespace on system resources (#3234)
Browse files Browse the repository at this point in the history
* fix: resolve missing namespace on system resources

* refactor: align pkdId check to 2nd of if
  • Loading branch information
iBotPeaches authored Jul 30, 2023
1 parent 57ef8a2 commit cd275ff
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ public int getAttributeCount() {
public String getAttributeNamespace(int index) {
int offset = getAttributeOffset(index);
int namespace = mAttributes[offset + ATTRIBUTE_IX_NAMESPACE_URI];

// #2972 - If the namespace index is -1, the attribute is not present, but if the attribute is from system
// we can resolve it to the default namespace. This may prove to be too aggressive as we scope the entire
// system namespace, but it is better than not resolving it at all.
ResID resId = new ResID(getAttributeNameResource(index));
if (namespace == -1 && resId.pkgId == 1) {
return ANDROID_RES_NS;
}

if (namespace == -1) {
return "";
}
Expand All @@ -284,12 +293,11 @@ public String getAttributeNamespace(int index) {
// unless the pkgId of the resource is private. We will grab the non-standard one.
String value = mStringBlock.getString(namespace);

if (value == null || value.length() == 0) {
ResID resId = new ResID(getAttributeNameResource(index));
if (value == null || value.isEmpty()) {
if (resId.pkgId == PRIVATE_PKG_ID) {
value = getNonDefaultNamespaceUri(offset);
return getNonDefaultNamespaceUri(offset);
} else {
value = "http://schemas.android.com/apk/res/android";
return ANDROID_RES_NS;
}
}

Expand All @@ -308,7 +316,7 @@ private String getNonDefaultNamespaceUri(int offset) {
// We have the namespaces that can't be touched in the opening tag.
// Though no known way to correlate them at this time.
// So return the res-auto namespace.
return "http://schemas.android.com/apk/res-auto";
return ANDROID_RES_NS_AUTO;
}

@Override
Expand Down Expand Up @@ -828,4 +836,7 @@ private void setFirstError(AndrolibException error) {
private static final int ATTRIBUTE_LENGTH = 5;

private static final int PRIVATE_PKG_ID = 0x7F;

private static final String ANDROID_RES_NS_AUTO = "http://schemas.android.com/apk/res-auto";
private static final String ANDROID_RES_NS = "http://schemas.android.com/apk/res/android";
}

0 comments on commit cd275ff

Please sign in to comment.