Skip to content

Commit

Permalink
[Fix] Work around parsing AndroidManifest.xml on LGE devices.
Browse files Browse the repository at this point in the history
Bug: #1019
  • Loading branch information
zhanghai committed Sep 15, 2023
1 parent 1ed7316 commit edc71c8
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,25 @@ class LocaleConfigCompat(context: Context) {
// @see com.android.server.pm.pkg.parsing.ParsingPackageUtils
@XmlRes
private fun getLocaleConfigResourceId(context: Context): Int {
// Java cookies starts at 1, while passing 0 (invalid cookie for Java) makes
// AssetManager pick the last asset containing such a file name.
// We should go over all the assets containing AndroidManifest.xml, however there's no
// API to do that, so the best we can do is to start from the first asset and iterate
// until we can't find the next asset containing AndroidManifest.xml.
var cookie = 1
var isAndroidManifestFound = false
while (true) {
val parser = try {
context.assets.openXmlResourceParser(cookie, FILE_NAME_ANDROID_MANIFEST)
} catch (e: FileNotFoundException) {
break
if (!isAndroidManifestFound) {
++cookie
continue
} else {
break
}
}
isAndroidManifestFound = true
parser.use {
do {
if (parser.eventType != XmlPullParser.START_TAG) {
Expand Down

0 comments on commit edc71c8

Please sign in to comment.