Skip to content

Commit

Permalink
[Fix] Work around android manifest not found on LG devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Sep 15, 2023
1 parent 1ed7316 commit b6773ec
Showing 1 changed file with 40 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,34 +97,49 @@ class LocaleConfigCompat(context: Context) {
} catch (e: FileNotFoundException) {
break
}
parser.use {
do {
if (parser.eventType != XmlPullParser.START_TAG) {
continue
}
if (parser.name != TAG_MANIFEST) {
parser.skipCurrentTag()
continue
}
if (parser.getAttributeValue(null, ATTR_PACKAGE) != context.packageName) {
break
}
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.eventType != XmlPullParser.START_TAG) {
continue
}
if (parser.name != TAG_APPLICATION) {
parser.skipCurrentTag()
continue
}
return parser.getAttributeResourceValue(
NAMESPACE_ANDROID, ATTR_LOCALE_CONFIG, ResourcesCompat.ID_NULL
)
}
} while (parser.next() != XmlPullParser.END_DOCUMENT)
val resourceId = parser.use {
getLocaleConfigResourceId(parser, context.packageName)
}
if (resourceId != ResourcesCompat.ID_NULL) {
return resourceId
}
++cookie
}
val parser = try {
context.assets.openXmlResourceParser(FILE_NAME_ANDROID_MANIFEST)
} catch (e: FileNotFoundException) {
return ResourcesCompat.ID_NULL
}
return parser.use { getLocaleConfigResourceId(parser, context.packageName) }
}

// @see com.android.server.pm.pkg.parsing.ParsingPackageUtils
@XmlRes
private fun getLocaleConfigResourceId(parser: XmlResourceParser, packageName: String): Int {
do {
if (parser.eventType != XmlPullParser.START_TAG) {
continue
}
if (parser.name != TAG_MANIFEST) {
parser.skipCurrentTag()
continue
}
if (parser.getAttributeValue(null, ATTR_PACKAGE) != packageName) {
break
}
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.eventType != XmlPullParser.START_TAG) {
continue
}
if (parser.name != TAG_APPLICATION) {
parser.skipCurrentTag()
continue
}
return parser.getAttributeResourceValue(
NAMESPACE_ANDROID, ATTR_LOCALE_CONFIG, ResourcesCompat.ID_NULL
)
}
} while (parser.next() != XmlPullParser.END_DOCUMENT)
return ResourcesCompat.ID_NULL
}

Expand Down

0 comments on commit b6773ec

Please sign in to comment.