Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve missing namespace on system resources #3234

Merged
merged 2 commits into from
Jul 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
}